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', '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=986705.33..986705.34 rows=1 width=27) (actual time=35440.381..35440.381 rows=2 loops=1) Sort Key: lineitem.l_shipmode Sort Method: quicksort Memory: 25kB Buffers: shared hit=480796 read=887168 dirtied=243 written=8585 -> HashAggregate (cost=986705.31..986705.32 rows=1 width=27) (actual time=35440.283..35440.286 rows=2 loops=1) Buffers: shared hit=480791 read=887168 dirtied=243 written=8585 -> Hash Join (cost=594902.33..981598.43 rows=291822 width=27) (actual time=16288.434..34940.167 rows=311533 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=480791 read=887168 dirtied=243 written=8585 -> Index Scan using lineitem_l_orderkey_idx_part2 on lineitem (cost=0.00..377576.66 rows=291822 width=15) (actual time=0.136..17420.899 rows=311533 loops=1) Filter: ((l_shipmode = ANY ('{"REG AIR",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: 6878146 Buffers: shared hit=359014 read=753901 dirtied=58 written=1318 -> Hash (cost=406090.48..406090.48 rows=15104948 width=20) (actual time=16280.772..16280.772 rows=15000000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 761719kB Buffers: shared hit=121774 read=133267 dirtied=185 written=7267 -> Seq Scan on orders (cost=0.00..406090.48 rows=15104948 width=20) (actual time=0.012..7924.606 rows=15000000 loops=1) Buffers: shared hit=121774 read=133267 dirtied=185 written=7267 Total runtime: 35573.323 ms (19 rows) COMMIT; COMMIT