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 ('SHIP', '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=990896.26..990896.26 rows=1 width=27) (actual time=43787.195..43787.196 rows=2 loops=1) Sort Key: lineitem.l_shipmode Sort Method: quicksort Memory: 25kB Buffers: shared hit=605063 read=764723 dirtied=253 written=271 -> HashAggregate (cost=990896.24..990896.25 rows=1 width=27) (actual time=43787.075..43787.076 rows=2 loops=1) Buffers: shared hit=605058 read=764723 dirtied=253 written=271 -> Hash Join (cost=597855.36..985813.71 rows=290430 width=27) (actual time=16405.866..43182.265 rows=311536 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=605058 read=764723 dirtied=253 written=271 -> Index Scan using lineitem_l_orderkey_idx_part2 on lineitem (cost=0.00..378882.42 rows=290430 width=15) (actual time=0.209..25373.863 rows=311536 loops=1) Filter: ((l_shipmode = ANY ('{SHIP,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: 6884990 Buffers: shared hit=349003 read=764468 written=271 -> Hash (cost=408106.27..408106.27 rows=15179927 width=20) (actual time=16389.795..16389.795 rows=15015000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 762481kB Buffers: shared hit=256052 read=255 dirtied=253 -> Seq Scan on orders (cost=0.00..408106.27 rows=15179927 width=20) (actual time=0.023..8036.049 rows=15015000 loops=1) Buffers: shared hit=256052 read=255 dirtied=253 Total runtime: 43962.686 ms (19 rows) COMMIT; COMMIT