BEGIN; BEGIN EXPLAIN (ANALYZE, BUFFERS) select l_shipmode, sum(case when o_orderpriority = '1-URGENT' or o_orderpriority = '2-HIGH' then 1 else 0 end) as high_line_count, sum(case when o_orderpriority <> '1-URGENT' and o_orderpriority <> '2-HIGH' then 1 else 0 end) as low_line_count from orders, lineitem where o_orderkey = l_orderkey and l_shipmode in ('SHIP', 'MAIL') and l_commitdate < l_receiptdate and l_shipdate < l_commitdate and l_receiptdate >= date '1997-01-01' and l_receiptdate < date '1997-01-01' + interval '1 year' group by l_shipmode order by l_shipmode; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Sort (cost=985928.29..985928.30 rows=1 width=27) (actual time=26241.736..26241.737 rows=2 loops=1) Sort Key: lineitem.l_shipmode Sort Method: quicksort Memory: 25kB Buffers: shared hit=1008565 read=359229 dirtied=74 written=1007 -> HashAggregate (cost=985928.27..985928.28 rows=1 width=27) (actual time=26241.655..26241.656 rows=2 loops=1) Group Key: lineitem.l_shipmode Buffers: shared hit=1008560 read=359229 dirtied=74 written=1007 -> Hash Join (cost=594902.76..980857.61 rows=289752 width=27) (actual time=14166.278..25936.750 rows=311578 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1008560 read=359229 dirtied=74 written=1007 -> Index Scan using lineitem_l_orderkey_idx_part2 on lineitem (cost=0.43..376900.53 rows=289752 width=15) (actual time=0.176..11356.761 rows=311578 loops=1) Filter: ((l_shipmode = ANY ('{SHIP,MAIL}'::bpchar[])) AND (l_receiptdate >= '1997-01-01'::date) AND (l_receiptdate < '1998-01-01 00:00:00'::timestamp without time zone)) Rows Removed by Filter: 6885191 Buffers: shared hit=856590 read=256155 dirtied=74 written=985 -> Hash (cost=406090.48..406090.48 rows=15104948 width=20) (actual time=12612.102..12612.102 rows=15015000 loops=1) Buckets: 16777216 Batches: 1 Memory Usage: 893553kB Buffers: shared hit=151967 read=103074 written=22 -> Seq Scan on orders (cost=0.00..406090.48 rows=15104948 width=20) (actual time=0.038..6117.239 rows=15015000 loops=1) Buffers: shared hit=151967 read=103074 written=22 Planning time: 5.084 ms Execution time: 26262.564 ms (21 rows) COMMIT; COMMIT