EXPLAIN (ANALYZE TRUE, VERBOSE TRUE, COSTS TRUE, BUFFERS TRUE, TIMING TRUE) SELECT COUNT(1) FROM proposal.proposal INNER JOIN proposal.note ON proposal.note.proposal_reference = proposal.proposal.reference WHERE proposal.proposal.system_id = '11' AND proposal.proposal.legacy_organisation_id IN ('2', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '42', '43', '44', '45', '46', '47', '48', '50', '52', '53', '54', '55', '181', '187', '188', '189', '190', '191', '192', '193', '194', '195', '196', '197', '199', '200', '202', '203', '204', '218', '221', '222', '223', '225', '226', '227', '228', '229', '230', '231', '232', '233', '235', '237', '239', '240', '241', '242', '243', '244', '245', '246', '247', '248', '249', '250', '251', '252', '253', '254', '255', '258', '259', '260', '261', '262', '263', '264', '265', '266', '267', '41') AND proposal.proposal.has_been_anonymised = false AND proposal.note.legacy_read_by IS NULL AND proposal.note.type_id IN ('1', '4', '9') AND proposal.note.entry_time > '2019-07-09 00:00:00'; 'Aggregate (cost=199100.97..199100.98 rows=1 width=0) (actual time=2265.665..2265.665 rows=1 loops=1)' ' Output: count(1)' ' Buffers: shared hit=303 read=44070, temp read=3401 written=3275' ' I/O Timings: read=338.284' ' -> Hash Join (cost=95655.49..199099.14 rows=733 width=0) (actual time=2166.000..2265.500 rows=961 loops=1)' ' Hash Cond: (note.proposal_reference = proposal.reference)' ' Buffers: shared hit=303 read=44070, temp read=3401 written=3275' ' I/O Timings: read=338.284' ' -> Bitmap Heap Scan on proposal.note (cost=3055.52..105082.81 rows=72805 width=16) (actual time=26.098..183.887 rows=133338 loops=1)' ' Output: note.proposal_reference' ' Recheck Cond: ((note.type_id = ANY ('{1,4,9}'::integer[])) AND (note.entry_time > '2019-07-09 00:00:00+01'::timestamp with time zone) AND (note.legacy_read_by IS NULL))' ' Rows Removed by Index Recheck: 155411' ' Heap Blocks: exact=5730 lossy=3139' ' Buffers: shared hit=2 read=9873' ' I/O Timings: read=63.824' ' -> Bitmap Index Scan on note_type_id_entry_time_idx (cost=0.00..3037.32 rows=72805 width=0) (actual time=25.246..25.246 rows=133338 loops=1)' ' Index Cond: ((note.type_id = ANY ('{1,4,9}'::integer[])) AND (note.entry_time > '2019-07-09 00:00:00+01'::timestamp with time zone))' ' Buffers: shared hit=2 read=1004' ' I/O Timings: read=8.786' ' -> Hash (cost=91092.63..91092.63 rows=86668 width=16) (actual time=1960.836..1960.836 rows=465120 loops=1)' ' Output: proposal.reference' ' Buckets: 16384 (originally 16384) Batches: 64 (originally 16) Memory Usage: 476kB' ' Buffers: shared hit=301 read=34197, temp written=1979' ' I/O Timings: read=274.460' ' -> Bitmap Heap Scan on proposal.proposal (cost=2871.35..91092.63 rows=86668 width=16) (actual time=73.254..1823.379 rows=465120 loops=1)' ' Output: proposal.reference' ' Recheck Cond: ((proposal.system_id = 11) AND (proposal.legacy_organisation_id = ANY ('{2,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,42,43,44,45,46,47,48,50,52,53,54,55,181,187,188,189,190,191,192,193,194,195,196,197,199,200,202,203,204,218,221,222,223,225,226,227,228,229,230,231,232,233,235,237,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,258,259,260,261,262,263,264,265,266,267,41}'::integer[])))' ' Rows Removed by Index Recheck: 1944770' ' Filter: (NOT proposal.has_been_anonymised)' ' Rows Removed by Filter: 993208' ' Heap Blocks: exact=3983 lossy=27989' ' Buffers: shared hit=301 read=34197' ' I/O Timings: read=274.460' ' -> Bitmap Index Scan on proposal_has_been_anonymised_system_id_legacy_organisation__idx (cost=0.00..2849.68 rows=86668 width=0) (actual time=72.624..72.624 rows=465120 loops=1)' ' Index Cond: ((proposal.has_been_anonymised = false) AND (proposal.system_id = 11) AND (proposal.legacy_organisation_id = ANY ('{2,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,42,43,44,45,46,47,48,50,52,53,54,55,181,187,188,189,190,191,192,193,194,195,196,197,199,200,202,203,204,218,221,222,223,225,226,227,228,229,230,231,232,233,235,237,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,258,259,260,261,262,263,264,265,266,267,41}'::integer[])))' ' Buffers: shared hit=301 read=2225' ' I/O Timings: read=23.251' 'Planning time: 0.920 ms' 'Execution time: 2265.986 ms'