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 = 'CANADA' and n2.n_name = 'MOZAMBIQUE') or (n1.n_name = 'MOZAMBIQUE' and n2.n_name = 'CANADA') ) 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=2355336.49..2357236.57 rows=58464 width=64) (actual time=115594.457..115622.782 rows=4 loops=1) Buffers: shared hit=776128 read=652338 written=4864 -> Sort (cost=2355336.49..2355482.65 rows=58464 width=64) (actual time=115583.784..115591.118 rows=57978 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: 9690kB Buffers: shared hit=776128 read=652338 written=4864 -> Hash Join (cost=895302.40..2350707.53 rows=58464 width=64) (actual time=59605.814..115192.912 rows=57978 loops=1) Hash Cond: ((lineitem.l_suppkey = supplier.s_suppkey) AND (n1.n_nationkey = supplier.s_nationkey)) Buffers: shared hit=776120 read=652338 written=4864 -> Hash Join (cost=890623.40..2315919.61 rows=1461598 width=72) (actual time=59510.626..111491.913 rows=1449976 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=776111 read=650165 written=4864 -> Bitmap Heap Scan on lineitem (cost=387515.97..1729628.95 rows=18284599 width=20) (actual time=22103.458..48478.630 rows=18230142 loops=1) Recheck Cond: ((l_shipdate >= '1995-01-01'::date) AND (l_shipdate <= '1996-12-31'::date)) Buffers: shared hit=516094 read=597984 written=4797 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..382944.82 rows=18284599 width=0) (actual time=20409.937..20409.937 rows=18282046 loops=1) Index Cond: ((l_shipdate >= '1995-01-01'::date) AND (l_shipdate <= '1996-12-31'::date)) Buffers: shared hit=10494 read=39321 written=4741 -> Hash (cost=488089.48..488089.48 rows=1201436 width=60) (actual time=37406.298..37406.298 rows=1193857 loops=1) Buckets: 131072 Batches: 1 Memory Usage: 107261kB Buffers: shared hit=260017 read=52181 written=67 -> Hash Join (cost=15638.06..488089.48 rows=1201436 width=60) (actual time=1470.591..34400.520 rows=1193857 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=260017 read=52181 written=67 -> Seq Scan on orders (cost=0.00..404074.68 rows=15029968 width=8) (actual time=0.018..6140.024 rows=15000000 loops=1) Buffers: shared hit=222269 read=31506 written=41 -> Hash (cost=14139.26..14139.26 rows=119904 width=60) (actual time=1470.400..1470.400 rows=119645 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 10750kB Buffers: shared hit=37748 read=20675 written=26 -> Nested Loop (cost=905.09..14139.26 rows=119904 width=60) (actual time=19.089..1374.322 rows=119645 loops=1) Buffers: shared hit=37748 read=20675 written=26 -> Nested Loop (cost=0.00..28.00 rows=2 width=60) (actual time=0.200..0.557 rows=2 loops=1) Join Filter: (((n1.n_name = 'CANADA'::bpchar) AND (n2.n_name = 'MOZAMBIQUE'::bpchar)) OR ((n1.n_name = 'MOZAMBIQUE'::bpchar) AND (n2.n_name = 'CANADA'::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.100..0.130 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.008..0.010 rows=25 loops=1) Buffers: shared hit=1 -> Bitmap Heap Scan on customer (cost=905.09..6455.63 rows=60000 width=8) (actual time=28.613..665.167 rows=59822 loops=2) Recheck Cond: (c_nationkey = n2.n_nationkey) Buffers: shared hit=37745 read=20675 written=26 -> Bitmap Index Scan on customer_c_nationkey_c_custkey_idx (cost=0.00..890.09 rows=60000 width=0) (actual time=17.989..17.989 rows=59822 loops=2) Index Cond: (c_nationkey = n2.n_nationkey) Buffers: shared hit=1 read=332 written=4 -> Hash (cost=3179.00..3179.00 rows=100000 width=8) (actual time=94.187..94.187 rows=100000 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3907kB Buffers: shared hit=6 read=2173 -> Seq Scan on supplier (cost=0.00..3179.00 rows=100000 width=8) (actual time=0.009..62.030 rows=100000 loops=1) Buffers: shared hit=6 read=2173 Total runtime: 115676.312 ms (53 rows) COMMIT; COMMIT