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 ('FOB', 'RAIL') and l_commitdate < l_receiptdate and l_shipdate < l_commitdate and l_receiptdate >= date '1995-01-01' and l_receiptdate < date '1995-01-01' + interval '1 year' group by l_shipmode order by l_shipmode; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Sort (cost=985515.65..985515.65 rows=1 width=27) (actual time=49994.582..49994.582 rows=2 loops=1) Sort Key: lineitem.l_shipmode Sort Method: quicksort Memory: 25kB Buffers: shared hit=616484 read=750929 dirtied=87 written=13929 -> HashAggregate (cost=985515.63..985515.64 rows=1 width=27) (actual time=49994.435..49994.435 rows=2 loops=1) Buffers: shared hit=616479 read=750929 dirtied=87 written=13929 -> Hash Join (cost=594309.84..980452.32 rows=289332 width=27) (actual time=19226.628..49300.444 rows=312019 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=616479 read=750929 dirtied=87 written=13929 -> Index Scan using lineitem_l_orderkey_idx_part2 on lineitem (cost=0.00..377100.85 rows=289332 width=15) (actual time=3.482..28618.146 rows=312019 loops=1) Filter: ((l_shipmode = ANY ('{FOB,RAIL}'::bpchar[])) AND (l_receiptdate >= '1995-01-01'::date) AND (l_receiptdate < '1996-01-01 00:00:00'::timestamp without time zone)) Rows Removed by Filter: 6884846 Buffers: shared hit=371366 read=741252 dirtied=87 written=13929 -> Hash (cost=405686.04..405686.04 rows=15089904 width=20) (actual time=19212.535..19212.535 rows=15015000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 762481kB Buffers: shared hit=245110 read=9677 -> Seq Scan on orders (cost=0.00..405686.04 rows=15089904 width=20) (actual time=0.021..8538.174 rows=15015000 loops=1) Buffers: shared hit=245110 read=9677 Total runtime: 50127.799 ms (19 rows) COMMIT; COMMIT