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 '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=984854.78..984854.79 rows=1 width=27) (actual time=34542.190..34542.191 rows=2 loops=1) Sort Key: lineitem.l_shipmode Sort Method: quicksort Memory: 25kB Buffers: shared hit=764905 read=602255 dirtied=1808 written=2504 -> HashAggregate (cost=984854.76..984854.77 rows=1 width=27) (actual time=34541.986..34541.987 rows=2 loops=1) Buffers: shared hit=764900 read=602255 dirtied=1808 written=2504 -> Hash Join (cost=593719.70..979773.66 rows=290349 width=27) (actual time=15618.965..34018.381 rows=310715 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=764900 read=602255 dirtied=1808 written=2504 -> Index Scan using lineitem_l_orderkey_idx_part2 on lineitem (cost=0.00..376980.55 rows=290349 width=15) (actual time=0.300..17047.886 rows=310715 loops=1) Filter: ((l_shipmode = ANY ('{"REG AIR",AIR}'::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: 6879150 Buffers: shared hit=529957 read=582661 dirtied=1516 written=824 -> Hash (cost=405283.20..405283.20 rows=15074920 width=20) (actual time=15608.876..15608.876 rows=15000000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 761719kB Buffers: shared hit=234940 read=19594 dirtied=292 written=1680 -> Seq Scan on orders (cost=0.00..405283.20 rows=15074920 width=20) (actual time=0.027..7175.148 rows=15000000 loops=1) Buffers: shared hit=234940 read=19594 dirtied=292 written=1680 Total runtime: 34698.152 ms (19 rows) COMMIT; COMMIT