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 ('TRUCK', 'FOB') 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=986173.86..986173.87 rows=1 width=27) (actual time=46406.609..46406.610 rows=2 loops=1) Sort Key: lineitem.l_shipmode Sort Method: quicksort Memory: 25kB Buffers: shared hit=1031830 read=336134 written=952 -> HashAggregate (cost=986173.84..986173.85 rows=1 width=27) (actual time=46406.485..46406.486 rows=2 loops=1) Buffers: shared hit=1031825 read=336134 written=952 -> Hash Join (cost=594902.33..981059.54 rows=292246 width=27) (actual time=19236.106..45718.250 rows=311225 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1031825 read=336134 written=952 -> Index Scan using lineitem_l_orderkey_idx_part2 on lineitem (cost=0.00..377024.52 rows=292246 width=15) (actual time=0.173..25163.441 rows=311225 loops=1) Filter: ((l_shipmode = ANY ('{TRUCK,FOB}'::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: 6878454 Buffers: shared hit=790460 read=322455 written=418 -> Hash (cost=406090.48..406090.48 rows=15104948 width=20) (actual time=19228.101..19228.101 rows=15000000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 761719kB Buffers: shared hit=241362 read=13679 written=534 -> Seq Scan on orders (cost=0.00..406090.48 rows=15104948 width=20) (actual time=0.017..9798.014 rows=15000000 loops=1) Buffers: shared hit=241362 read=13679 written=534 Total runtime: 46543.210 ms (19 rows) COMMIT; COMMIT