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 = 'MOROCCO') or (n1.n_name = 'MOROCCO' 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 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Sort (cost=1974775.00..1974782.64 rows=3056 width=64) (actual time=20494.927..20494.928 rows=4 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: 25kB Buffers: shared hit=5046327 read=454103 written=7 -> HashAggregate (cost=1974552.25..1974598.09 rows=3056 width=64) (actual time=20494.812..20494.817 rows=4 loops=1) Group Key: n1.n_name, n2.n_name, date_part('year'::text, (lineitem.l_shipdate)::timestamp without time zone) Buffers: shared hit=5046319 read=454103 written=7 -> Hash Join (cost=62340.37..1973643.61 rows=60576 width=64) (actual time=986.326..20407.685 rows=57911 loops=1) Hash Cond: (lineitem.l_suppkey = supplier.s_suppkey) Join Filter: (((n1.n_name = 'CANADA'::bpchar) AND (n2.n_name = 'MOROCCO'::bpchar)) OR ((n1.n_name = 'MOROCCO'::bpchar) AND (n2.n_name = 'CANADA'::bpchar))) Rows Removed by Join Filter: 58554 Buffers: shared hit=5046319 read=454103 written=7 -> Nested Loop (cost=58604.97..1961817.86 rows=1455602 width=42) (actual time=936.923..19764.475 rows=1447739 loops=1) Buffers: shared hit=5044136 read=454103 written=7 -> Hash Join (cost=58604.40..531536.45 rows=1203596 width=30) (actual time=936.793..9464.207 rows=1193080 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=220898 read=68409 -> Seq Scan on orders (cost=0.00..404477.52 rows=15044952 width=8) (actual time=0.011..3479.252 rows=15015000 loops=1) Buffers: shared hit=220895 read=33133 -> Hash (cost=57104.40..57104.40 rows=120000 width=30) (actual time=935.957..935.957 rows=119683 loops=1) Buckets: 131072 Batches: 1 Memory Usage: 8271kB Buffers: shared hit=3 read=35276 -> Hash Join (cost=1.40..57104.40 rows=120000 width=30) (actual time=0.052..889.018 rows=119683 loops=1) Hash Cond: (customer.c_nationkey = n2.n_nationkey) Buffers: shared hit=3 read=35276 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=8) (actual time=0.005..654.637 rows=1500000 loops=1) Buffers: shared hit=2 read=35276 -> Hash (cost=1.38..1.38 rows=2 width=30) (actual time=0.032..0.032 rows=2 loops=1) Buckets: 1024 Batches: 1 Memory Usage: 9kB Buffers: shared hit=1 -> Seq Scan on nation n2 (cost=0.00..1.38 rows=2 width=30) (actual time=0.013..0.019 rows=2 loops=1) Filter: ((n_name = 'MOROCCO'::bpchar) OR (n_name = 'CANADA'::bpchar)) Rows Removed by Filter: 23 Buffers: shared hit=1 -> Index Scan using lineitem_l_orderkey_l_linenumber_l_shipdate_idx on lineitem (cost=0.56..1.15 rows=4 width=20) (actual time=0.007..0.008 rows=1 loops=1193080) Index Cond: ((l_orderkey = orders.o_orderkey) AND (l_shipdate >= '1995-01-01'::date) AND (l_shipdate <= '1996-12-31'::date)) Buffers: shared hit=4823238 read=385694 written=7 -> Hash (cost=3635.40..3635.40 rows=8000 width=30) (actual time=48.871..48.871 rows=8044 loops=1) Buckets: 8192 Batches: 1 Memory Usage: 552kB Buffers: shared hit=2180 -> Hash Join (cost=1.40..3635.40 rows=8000 width=30) (actual time=0.057..46.430 rows=8044 loops=1) Hash Cond: (supplier.s_nationkey = n1.n_nationkey) Buffers: shared hit=2180 -> Seq Scan on supplier (cost=0.00..3179.00 rows=100000 width=8) (actual time=0.017..30.151 rows=100000 loops=1) Buffers: shared hit=2179 -> Hash (cost=1.38..1.38 rows=2 width=30) (actual time=0.020..0.020 rows=2 loops=1) Buckets: 1024 Batches: 1 Memory Usage: 9kB Buffers: shared hit=1 -> Seq Scan on nation n1 (cost=0.00..1.38 rows=2 width=30) (actual time=0.009..0.014 rows=2 loops=1) Filter: ((n_name = 'CANADA'::bpchar) OR (n_name = 'MOROCCO'::bpchar)) Rows Removed by Filter: 23 Buffers: shared hit=1 Planning time: 6.214 ms Execution time: 20495.435 ms (54 rows) COMMIT; COMMIT