BEGIN; BEGIN EXPLAIN (ANALYZE, BUFFERS) select supp_nation, cust_nation, l_year, sum(volume) as revenue from ( select n1.n_name as supp_nation, n2.n_name as cust_nation, extract(year from l_shipdate) as l_year, l_extendedprice * (1 - l_discount) as volume from supplier, lineitem, orders, customer, nation n1, nation n2 where s_suppkey = l_suppkey and o_orderkey = l_orderkey and c_custkey = o_custkey and s_nationkey = n1.n_nationkey and c_nationkey = n2.n_nationkey and ( (n1.n_name = 'PERU' and n2.n_name = 'ROMANIA') or (n1.n_name = 'ROMANIA' and n2.n_name = 'PERU') ) and l_shipdate between date '1995-01-01' and date '1996-12-31' ) as shipping group by supp_nation, cust_nation, l_year order by supp_nation, cust_nation, l_year; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=2378351.26..2380263.10 rows=58826 width=64) (actual time=130755.593..130785.429 rows=4 loops=1) Buffers: shared hit=1009849 read=436209 written=1125 -> Sort (cost=2378351.26..2378498.32 rows=58826 width=64) (actual time=130745.138..130753.562 rows=58492 loops=1) Sort Key: n1.n_name, n2.n_name, (date_part('year'::text, (lineitem.l_shipdate)::timestamp without time zone)) Sort Method: quicksort Memory: 9762kB Buffers: shared hit=1009849 read=436209 written=1125 -> Hash Join (cost=901409.32..2373691.01 rows=58826 width=64) (actual time=70612.094..130443.953 rows=58492 loops=1) Hash Cond: ((lineitem.l_suppkey = supplier.s_suppkey) AND (n1.n_nationkey = supplier.s_nationkey)) Buffers: shared hit=1009841 read=436209 written=1125 -> Hash Join (cost=896730.32..2338711.54 rows=1470904 width=72) (actual time=70417.340..126546.144 rows=1453417 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1007659 read=436209 written=1125 -> Bitmap Heap Scan on lineitem (cost=387301.31..1745569.66 rows=18401023 width=20) (actual time=21417.056..52631.791 rows=18228513 loops=1) Recheck Cond: ((l_shipdate >= '1995-01-01'::date) AND (l_shipdate <= '1996-12-31'::date)) Buffers: shared hit=709334 read=419104 written=1125 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..382701.06 rows=18401023 width=0) (actual time=20638.672..20638.672 rows=18520613 loops=1) Index Cond: ((l_shipdate >= '1995-01-01'::date) AND (l_shipdate <= '1996-12-31'::date)) Buffers: shared hit=20347 read=29468 written=1125 -> Hash (cost=494216.31..494216.31 rows=1217016 width=60) (actual time=48999.363..48999.363 rows=1193624 loops=1) Buckets: 131072 Batches: 1 Memory Usage: 107240kB Buffers: shared hit=298325 read=17105 -> Hash Join (cost=15638.06..494216.31 rows=1217016 width=60) (actual time=2569.828..47943.633 rows=1193624 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=298325 read=17105 -> Seq Scan on orders (cost=0.00..409314.79 rows=15224879 width=8) (actual time=0.032..12758.846 rows=15000000 loops=1) Buffers: shared hit=249367 read=7699 -> Hash (cost=14139.26..14139.26 rows=119904 width=60) (actual time=2569.651..2569.651 rows=119836 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 10767kB Buffers: shared hit=48958 read=9406 -> Nested Loop (cost=905.09..14139.26 rows=119904 width=60) (actual time=53.481..2460.583 rows=119836 loops=1) Buffers: shared hit=48958 read=9406 -> Nested Loop (cost=0.00..28.00 rows=2 width=60) (actual time=0.472..0.618 rows=2 loops=1) Join Filter: (((n1.n_name = 'PERU'::bpchar) AND (n2.n_name = 'ROMANIA'::bpchar)) OR ((n1.n_name = 'ROMANIA'::bpchar) AND (n2.n_name = 'PERU'::bpchar))) Rows Removed by Join Filter: 623 Buffers: shared hit=3 -> Index Scan using pk_nation on nation n1 (cost=0.00..12.63 rows=25 width=30) (actual time=0.251..0.271 rows=25 loops=1) Buffers: shared hit=2 -> Materialize (cost=0.00..1.38 rows=25 width=30) (actual time=0.001..0.004 rows=25 loops=25) Buffers: shared hit=1 -> Seq Scan on nation n2 (cost=0.00..1.25 rows=25 width=30) (actual time=0.007..0.013 rows=25 loops=1) Buffers: shared hit=1 -> Bitmap Heap Scan on customer (cost=905.09..6455.63 rows=60000 width=8) (actual time=48.055..1205.633 rows=59918 loops=2) Recheck Cond: (c_nationkey = n2.n_nationkey) Buffers: shared hit=48955 read=9406 -> Bitmap Index Scan on customer_c_nationkey_c_custkey_idx (cost=0.00..890.09 rows=60000 width=0) (actual time=38.657..38.657 rows=59918 loops=2) Index Cond: (c_nationkey = n2.n_nationkey) Buffers: shared hit=2 read=333 -> Hash (cost=3179.00..3179.00 rows=100000 width=8) (actual time=194.195..194.195 rows=100000 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3907kB Buffers: shared hit=2179 -> Seq Scan on supplier (cost=0.00..3179.00 rows=100000 width=8) (actual time=0.011..145.354 rows=100000 loops=1) Buffers: shared hit=2179 Total runtime: 130824.980 ms (53 rows) COMMIT; COMMIT