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', 'AIR') 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=992326.33..992326.34 rows=1 width=27) (actual time=31557.682..31557.683 rows=2 loops=1) Sort Key: lineitem.l_shipmode Sort Method: quicksort Memory: 25kB Buffers: shared hit=906258 read=460228 dirtied=169 written=199 -> HashAggregate (cost=992326.31..992326.32 rows=1 width=27) (actual time=31557.562..31557.565 rows=2 loops=1) Buffers: shared hit=906253 read=460228 dirtied=169 written=199 -> Hash Join (cost=598445.50..987173.04 rows=294473 width=27) (actual time=12797.524..30995.637 rows=311731 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=906253 read=460228 dirtied=169 written=199 -> Index Scan using lineitem_l_orderkey_idx_part2 on lineitem (cost=0.00..379525.26 rows=294473 width=15) (actual time=0.165..16915.944 rows=311731 loops=1) Filter: ((l_shipmode = ANY ('{FOB,AIR}'::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: 6877740 Buffers: shared hit=691249 read=418669 dirtied=169 written=155 -> Hash (cost=408509.11..408509.11 rows=15194911 width=20) (actual time=12785.256..12785.256 rows=15000000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 761719kB Buffers: shared hit=215001 read=41559 written=44 -> Seq Scan on orders (cost=0.00..408509.11 rows=15194911 width=20) (actual time=0.016..5947.215 rows=15000000 loops=1) Buffers: shared hit=215001 read=41559 written=44 Total runtime: 31670.040 ms (19 rows) COMMIT; COMMIT