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', 'SHIP') and l_commitdate < l_receiptdate and l_shipdate < l_commitdate and l_receiptdate >= date '1994-01-01' and l_receiptdate < date '1994-01-01' + interval '1 year' group by l_shipmode order by l_shipmode; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Sort (cost=990770.40..990770.41 rows=1 width=27) (actual time=23097.039..23097.039 rows=2 loops=1) Sort Key: lineitem.l_shipmode Sort Method: quicksort Memory: 25kB Buffers: shared hit=1267869 read=101590 dirtied=146 written=64 -> HashAggregate (cost=990770.38..990770.39 rows=1 width=27) (actual time=23096.950..23096.951 rows=2 loops=1) Buffers: shared hit=1267864 read=101590 dirtied=146 written=64 -> Hash Join (cost=597265.22..985654.20 rows=292353 width=27) (actual time=12141.753..22770.037 rows=311682 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1267864 read=101590 dirtied=146 written=64 -> Index Scan using lineitem_l_orderkey_idx_part2 on lineitem (cost=0.00..379252.95 rows=292353 width=15) (actual time=0.140..9547.345 rows=311682 loops=1) Filter: ((l_shipmode = ANY ('{AIR,SHIP}'::bpchar[])) AND (l_receiptdate >= '1994-01-01'::date) AND (l_receiptdate < '1995-01-01 00:00:00'::timestamp without time zone)) Rows Removed by Filter: 6877737 Buffers: shared hit=1027027 read=86370 dirtied=112 -> Hash (cost=407703.43..407703.43 rows=15164943 width=20) (actual time=12130.847..12130.847 rows=15000000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 761719kB Buffers: shared hit=240834 read=15220 dirtied=34 written=64 -> Seq Scan on orders (cost=0.00..407703.43 rows=15164943 width=20) (actual time=0.014..5628.511 rows=15000000 loops=1) Buffers: shared hit=240834 read=15220 dirtied=34 written=64 Total runtime: 23222.090 ms (19 rows) COMMIT; COMMIT