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 '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=988052.20..988052.21 rows=1 width=27) (actual time=20568.711..20568.712 rows=2 loops=1) Sort Key: lineitem.l_shipmode Sort Method: quicksort Memory: 25kB Buffers: shared hit=947570 read=427307 dirtied=239 written=214 -> HashAggregate (cost=988052.18..988052.19 rows=1 width=27) (actual time=20568.634..20568.635 rows=2 loops=1) Group Key: lineitem.l_shipmode Buffers: shared hit=947565 read=427307 dirtied=239 written=214 -> Hash Join (cost=596085.37..982910.95 rows=293785 width=27) (actual time=10285.700..20299.706 rows=312226 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=947565 read=427307 dirtied=239 written=214 -> Index Scan using lineitem_l_orderkey_idx_part2 on lineitem (cost=0.43..377645.23 rows=293785 width=15) (actual time=0.152..9659.847 rows=312226 loops=1) Filter: ((l_shipmode = ANY ('{AIR,FOB}'::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: 6877164 Buffers: shared hit=692989 read=426332 dirtied=227 written=210 -> Hash (cost=406897.75..406897.75 rows=15134975 width=20) (actual time=9827.229..9827.229 rows=15000000 loops=1) Buckets: 16777216 Batches: 1 Memory Usage: 892791kB Buffers: shared hit=254573 read=975 dirtied=12 written=4 -> Seq Scan on orders (cost=0.00..406897.75 rows=15134975 width=20) (actual time=0.020..4453.670 rows=15000000 loops=1) Buffers: shared hit=254573 read=975 dirtied=12 written=4 Planning time: 2.416 ms Execution time: 20579.955 ms (21 rows) COMMIT; COMMIT