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 = 'EGYPT' and n2.n_name = 'UNITED KINGDOM') or (n1.n_name = 'UNITED KINGDOM' and n2.n_name = 'EGYPT') ) 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=2371685.95..2373597.77 rows=58825 width=64) (actual time=125594.446..125620.984 rows=4 loops=1) Buffers: shared hit=1194929 read=244771 written=2486 -> Sort (cost=2371685.95..2371833.02 rows=58825 width=64) (actual time=125584.972..125589.892 rows=57892 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: 9678kB Buffers: shared hit=1194929 read=244771 written=2486 -> Hash Join (cost=900017.76..2367025.80 rows=58825 width=64) (actual time=66505.843..125194.675 rows=57892 loops=1) Hash Cond: ((lineitem.l_suppkey = supplier.s_suppkey) AND (n1.n_nationkey = supplier.s_nationkey)) Buffers: shared hit=1194921 read=244771 written=2486 -> Hash Join (cost=895338.76..2332042.22 rows=1471110 width=72) (actual time=66343.186..121493.646 rows=1459080 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1192739 read=244771 written=2486 -> Bitmap Heap Scan on lineitem (cost=388339.66..1741318.55 rows=18403593 width=20) (actual time=16321.871..48630.886 rows=18227889 loops=1) Recheck Cond: ((l_shipdate >= '1995-01-01'::date) AND (l_shipdate <= '1996-12-31'::date)) Buffers: shared hit=973694 read=149430 written=2480 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..383738.76 rows=18403593 width=0) (actual time=15597.432..15597.432 rows=18429277 loops=1) Index Cond: ((l_shipdate >= '1995-01-01'::date) AND (l_shipdate <= '1996-12-31'::date)) Buffers: shared hit=2436 read=47379 written=2480 -> Hash (cost=491861.27..491861.27 rows=1211027 width=60) (actual time=50020.220..50020.220 rows=1202092 loops=1) Buckets: 131072 Batches: 1 Memory Usage: 108001kB Buffers: shared hit=219045 read=95341 written=6 -> Hash Join (cost=15638.06..491861.27 rows=1211027 width=60) (actual time=2173.801..48700.416 rows=1202092 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=219045 read=95341 written=6 -> Seq Scan on orders (cost=0.00..407300.59 rows=15149959 width=8) (actual time=0.018..11811.087 rows=15000000 loops=1) Buffers: shared hit=182379 read=73422 written=6 -> Hash (cost=14139.26..14139.26 rows=119904 width=60) (actual time=2173.636..2173.636 rows=120350 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 10813kB Buffers: shared hit=36666 read=21919 -> Nested Loop (cost=905.09..14139.26 rows=119904 width=60) (actual time=27.921..2050.763 rows=120350 loops=1) Buffers: shared hit=36666 read=21919 -> Nested Loop (cost=0.00..28.00 rows=2 width=60) (actual time=0.124..0.444 rows=2 loops=1) Join Filter: (((n1.n_name = 'EGYPT'::bpchar) AND (n2.n_name = 'UNITED KINGDOM'::bpchar)) OR ((n1.n_name = 'UNITED KINGDOM'::bpchar) AND (n2.n_name = 'EGYPT'::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.015..0.041 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.009..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=36.075..999.965 rows=60175 loops=2) Recheck Cond: (c_nationkey = n2.n_nationkey) Buffers: shared hit=36663 read=21919 -> Bitmap Index Scan on customer_c_nationkey_c_custkey_idx (cost=0.00..890.09 rows=60000 width=0) (actual time=24.985..24.985 rows=60175 loops=2) Index Cond: (c_nationkey = n2.n_nationkey) Buffers: shared hit=2 read=334 -> Hash (cost=3179.00..3179.00 rows=100000 width=8) (actual time=162.306..162.306 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..114.848 rows=100000 loops=1) Buffers: shared hit=2179 Total runtime: 125644.105 ms (53 rows) COMMIT; COMMIT