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', 'REG AIR') 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=986977.44..986977.44 rows=1 width=27) (actual time=26848.295..26848.296 rows=2 loops=1) Sort Key: lineitem.l_shipmode Sort Method: quicksort Memory: 25kB Buffers: shared hit=850192 read=514338 written=517 -> HashAggregate (cost=986977.42..986977.43 rows=1 width=27) (actual time=26848.208..26848.210 rows=2 loops=1) Group Key: lineitem.l_shipmode Buffers: shared hit=850187 read=514338 written=517 -> Hash Join (cost=595495.23..981876.61 rows=291475 width=27) (actual time=10736.319..26461.373 rows=312515 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=850187 read=514338 written=517 -> Index Scan using lineitem_l_orderkey_idx_part2 on lineitem (cost=0.43..377273.21 rows=291475 width=15) (actual time=0.325..15154.461 rows=312515 loops=1) Filter: ((l_shipmode = ANY ('{MAIL,"REG AIR"}'::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: 6884244 Buffers: shared hit=653015 read=456212 written=444 -> Hash (cost=406494.91..406494.91 rows=15119991 width=20) (actual time=10633.195..10633.195 rows=15015000 loops=1) Buckets: 16777216 Batches: 1 Memory Usage: 893553kB Buffers: shared hit=197169 read=58126 written=73 -> Seq Scan on orders (cost=0.00..406494.91 rows=15119991 width=20) (actual time=0.028..5708.182 rows=15015000 loops=1) Buffers: shared hit=197169 read=58126 written=73 Planning time: 4.482 ms Execution time: 26862.759 ms (21 rows) COMMIT; COMMIT