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 = 'VIETNAM' and n2.n_name = 'UNITED KINGDOM') or (n1.n_name = 'UNITED KINGDOM' and n2.n_name = 'VIETNAM') ) 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=2377456.93..2379367.77 rows=58795 width=64) (actual time=144818.534..144848.399 rows=4 loops=1) Buffers: shared hit=1081302 read=364364 written=1717 -> Sort (cost=2377456.93..2377603.92 rows=58795 width=64) (actual time=144808.130..144817.808 rows=57800 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: 9665kB Buffers: shared hit=1081302 read=364364 written=1717 -> Hash Join (cost=901308.06..2372799.37 rows=58795 width=64) (actual time=75825.390..144413.032 rows=57800 loops=1) Hash Cond: ((lineitem.l_suppkey = supplier.s_suppkey) AND (n1.n_nationkey = supplier.s_nationkey)) Buffers: shared hit=1081294 read=364364 written=1717 -> Hash Join (cost=896629.06..2337836.16 rows=1470114 width=72) (actual time=75639.605..140395.475 rows=1459347 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1079112 read=364364 written=1717 -> Bitmap Heap Scan on lineitem (cost=387200.06..1744739.22 rows=18391144 width=20) (actual time=20689.815..60580.195 rows=18228513 loops=1) Recheck Cond: ((l_shipdate >= '1995-01-01'::date) AND (l_shipdate <= '1996-12-31'::date)) Buffers: shared hit=798153 read=329705 written=1416 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..382602.27 rows=18391144 width=0) (actual time=19947.838..19947.838 rows=18512780 loops=1) Index Cond: ((l_shipdate >= '1995-01-01'::date) AND (l_shipdate <= '1996-12-31'::date)) Buffers: shared hit=10922 read=38893 written=1393 -> Hash (cost=494216.31..494216.31 rows=1217016 width=60) (actual time=54948.914..54948.914 rows=1202636 loops=1) Buckets: 131072 Batches: 1 Memory Usage: 108050kB Buffers: shared hit=280959 read=34659 written=301 -> Hash Join (cost=15638.06..494216.31 rows=1217016 width=60) (actual time=2301.754..52951.972 rows=1202636 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=280959 read=34659 written=301 -> Seq Scan on orders (cost=0.00..409314.79 rows=15224879 width=8) (actual time=0.017..14835.918 rows=15000000 loops=1) Buffers: shared hit=222740 read=34326 written=291 -> Hash (cost=14139.26..14139.26 rows=119904 width=60) (actual time=2301.628..2301.628 rows=120378 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 10816kB Buffers: shared hit=58219 read=333 written=10 -> Nested Loop (cost=905.09..14139.26 rows=119904 width=60) (actual time=46.387..2191.253 rows=120378 loops=1) Buffers: shared hit=58219 read=333 written=10 -> Nested Loop (cost=0.00..28.00 rows=2 width=60) (actual time=0.269..0.371 rows=2 loops=1) Join Filter: (((n1.n_name = 'VIETNAM'::bpchar) AND (n2.n_name = 'UNITED KINGDOM'::bpchar)) OR ((n1.n_name = 'UNITED KINGDOM'::bpchar) AND (n2.n_name = 'VIETNAM'::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.023..0.037 rows=25 loops=1) Buffers: shared hit=2 -> Materialize (cost=0.00..1.38 rows=25 width=30) (actual time=0.001..0.003 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=42.083..1071.108 rows=60189 loops=2) Recheck Cond: (c_nationkey = n2.n_nationkey) Buffers: shared hit=58216 read=333 written=10 -> Bitmap Index Scan on customer_c_nationkey_c_custkey_idx (cost=0.00..890.09 rows=60000 width=0) (actual time=33.209..33.209 rows=60189 loops=2) Index Cond: (c_nationkey = n2.n_nationkey) Buffers: shared hit=5 read=331 written=10 -> Hash (cost=3179.00..3179.00 rows=100000 width=8) (actual time=183.533..183.533 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.020..134.268 rows=100000 loops=1) Buffers: shared hit=2179 Total runtime: 144888.168 ms (53 rows) COMMIT; COMMIT