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 ('REG AIR', 'FOB') 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=986683.15..986683.16 rows=1 width=27) (actual time=70809.625..70809.625 rows=2 loops=1) Sort Key: lineitem.l_shipmode Sort Method: quicksort Memory: 25kB Buffers: shared hit=578749 read=789215 dirtied=834 written=9442 -> HashAggregate (cost=986683.13..986683.14 rows=1 width=27) (actual time=70809.291..70809.294 rows=2 loops=1) Buffers: shared hit=578744 read=789215 dirtied=834 written=9442 -> Hash Join (cost=594902.33..981546.95 rows=293496 width=27) (actual time=24881.192..70040.858 rows=310494 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=578744 read=789215 dirtied=834 written=9442 -> Index Scan using lineitem_l_orderkey_idx_part2 on lineitem (cost=0.00..377472.87 rows=293496 width=15) (actual time=0.223..43444.149 rows=310494 loops=1) Filter: ((l_shipmode = ANY ('{"REG AIR",FOB}'::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: 6879185 Buffers: shared hit=390127 read=722788 dirtied=741 written=4693 -> Hash (cost=406090.48..406090.48 rows=15104948 width=20) (actual time=24872.758..24872.758 rows=15000000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 761719kB Buffers: shared hit=188614 read=66427 dirtied=93 written=4749 -> Seq Scan on orders (cost=0.00..406090.48 rows=15104948 width=20) (actual time=0.019..15091.844 rows=15000000 loops=1) Buffers: shared hit=188614 read=66427 dirtied=93 written=4749 Total runtime: 70972.180 ms (19 rows) COMMIT; COMMIT