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 ('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=987690.43..987690.44 rows=1 width=27) (actual time=33514.686..33514.687 rows=2 loops=1) Sort Key: lineitem.l_shipmode Sort Method: quicksort Memory: 25kB Buffers: shared hit=658040 read=706491 dirtied=254 written=278 -> HashAggregate (cost=987690.41..987690.42 rows=1 width=27) (actual time=33514.538..33514.539 rows=2 loops=1) Buffers: shared hit=658035 read=706491 dirtied=254 written=278 -> Hash Join (cost=595494.80..982603.39 rows=290687 width=27) (actual time=14611.054..33029.816 rows=310920 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=658035 read=706491 dirtied=254 written=278 -> Index Scan using lineitem_l_orderkey_idx_part2 on lineitem (cost=0.00..378024.62 rows=290687 width=15) (actual time=0.328..17324.117 rows=310920 loops=1) Filter: ((l_shipmode = ANY ('{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: 6885839 Buffers: shared hit=408114 read=701114 written=278 -> Hash (cost=406494.91..406494.91 rows=15119991 width=20) (actual time=14599.070..14599.070 rows=15015000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 762481kB Buffers: shared hit=249918 read=5377 dirtied=254 -> Seq Scan on orders (cost=0.00..406494.91 rows=15119991 width=20) (actual time=0.033..6720.855 rows=15015000 loops=1) Buffers: shared hit=249918 read=5377 dirtied=254 Total runtime: 33630.235 ms (19 rows) COMMIT; COMMIT