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 '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=985924.67..985924.68 rows=1 width=27) (actual time=26596.256..26596.256 rows=2 loops=1) Sort Key: lineitem.l_shipmode Sort Method: quicksort Memory: 25kB Buffers: shared hit=732314 read=631402 written=176 -> HashAggregate (cost=985924.65..985924.66 rows=1 width=27) (actual time=26596.191..26596.193 rows=2 loops=1) Group Key: lineitem.l_shipmode Buffers: shared hit=732309 read=631402 written=176 -> Hash Join (cost=594310.27..980767.74 rows=294681 width=27) (actual time=12288.254..26300.782 rows=310962 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=732309 read=631402 written=176 -> Index Scan using lineitem_l_orderkey_idx_part2 on lineitem (cost=0.43..377249.11 rows=294681 width=15) (actual time=0.291..13606.642 rows=310962 loops=1) Filter: ((l_shipmode = ANY ('{FOB,AIR}'::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: 6885903 Buffers: shared hit=525776 read=583145 written=161 -> Hash (cost=405686.04..405686.04 rows=15089904 width=20) (actual time=11684.880..11684.880 rows=15015000 loops=1) Buckets: 16777216 Batches: 1 Memory Usage: 893553kB Buffers: shared hit=206530 read=48257 written=15 -> Seq Scan on orders (cost=0.00..405686.04 rows=15089904 width=20) (actual time=0.022..5584.142 rows=15015000 loops=1) Buffers: shared hit=206530 read=48257 written=15 Planning time: 3.214 ms Execution time: 26622.746 ms (21 rows) COMMIT; COMMIT