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 ('MAIL', '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=990777.44..990777.44 rows=1 width=27) (actual time=23935.637..23935.638 rows=2 loops=1) Sort Key: lineitem.l_shipmode Sort Method: quicksort Memory: 25kB Buffers: shared hit=1020784 read=345448 written=6006 -> HashAggregate (cost=990777.42..990777.43 rows=1 width=27) (actual time=23935.575..23935.576 rows=2 loops=1) Group Key: lineitem.l_shipmode Buffers: shared hit=1020779 read=345448 written=6006 -> Hash Join (cost=597855.79..985638.63 rows=293645 width=27) (actual time=10777.538..23610.579 rows=311141 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1020779 read=345448 written=6006 -> Index Scan using lineitem_l_orderkey_idx_part2 on lineitem (cost=0.43..378606.87 rows=293645 width=15) (actual time=0.093..12349.309 rows=311141 loops=1) Filter: ((l_shipmode = ANY ('{MAIL,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: 6878255 Buffers: shared hit=870873 read=239044 written=308 -> Hash (cost=408106.27..408106.27 rows=15179927 width=20) (actual time=10545.066..10545.066 rows=15000000 loops=1) Buckets: 16777216 Batches: 1 Memory Usage: 892791kB Buffers: shared hit=149903 read=106404 written=5698 -> Seq Scan on orders (cost=0.00..408106.27 rows=15179927 width=20) (actual time=0.022..5545.152 rows=15000000 loops=1) Buffers: shared hit=149903 read=106404 written=5698 Planning time: 2.959 ms Execution time: 23958.470 ms (21 rows) COMMIT; COMMIT