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 ('REG AIR', 'MAIL') 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=985482.48..985482.49 rows=1 width=27) (actual time=26771.852..26771.852 rows=2 loops=1) Sort Key: lineitem.l_shipmode Sort Method: quicksort Memory: 25kB Buffers: shared hit=952278 read=411438 dirtied=995 written=14775 -> HashAggregate (cost=985482.46..985482.47 rows=1 width=27) (actual time=26771.790..26771.791 rows=2 loops=1) Group Key: lineitem.l_shipmode Buffers: shared hit=952273 read=411438 dirtied=995 written=14775 -> Hash Join (cost=594310.27..980383.32 rows=291380 width=27) (actual time=10899.696..26410.857 rows=311058 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=952273 read=411438 dirtied=995 written=14775 -> Index Scan using lineitem_l_orderkey_idx_part2 on lineitem (cost=0.43..376967.85 rows=291380 width=15) (actual time=0.125..14943.668 rows=311058 loops=1) Filter: ((l_shipmode = ANY ('{"REG AIR",MAIL}'::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: 6885807 Buffers: shared hit=730034 read=378887 dirtied=995 written=14771 -> Hash (cost=405686.04..405686.04 rows=15089904 width=20) (actual time=10437.040..10437.040 rows=15015000 loops=1) Buckets: 16777216 Batches: 1 Memory Usage: 893553kB Buffers: shared hit=222236 read=32551 written=4 -> Seq Scan on orders (cost=0.00..405686.04 rows=15089904 width=20) (actual time=0.018..5275.861 rows=15015000 loops=1) Buffers: shared hit=222236 read=32551 written=4 Planning time: 3.300 ms Execution time: 26797.536 ms (21 rows) COMMIT; COMMIT