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 = 'IRAQ' and n2.n_name = 'ALGERIA') or (n1.n_name = 'ALGERIA' and n2.n_name = 'IRAQ') ) 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=2362987.43..2364888.19 rows=58485 width=64) (actual time=78001.820..78030.787 rows=4 loops=1) Buffers: shared hit=789756 read=644902 dirtied=6 written=14331 -> Sort (cost=2362987.43..2363133.64 rows=58485 width=64) (actual time=77992.034..77999.315 rows=58821 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: 9808kB Buffers: shared hit=789756 read=644902 dirtied=6 written=14331 -> Hash Join (cost=897367.38..2358356.65 rows=58485 width=64) (actual time=38740.233..77714.420 rows=58821 loops=1) Hash Cond: ((lineitem.l_suppkey = supplier.s_suppkey) AND (n1.n_nationkey = supplier.s_nationkey)) Buffers: shared hit=789748 read=644902 dirtied=6 written=14331 -> Hash Join (cost=892688.38..2323525.20 rows=1463759 width=72) (actual time=38663.276..74341.548 rows=1465919 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=787566 read=644902 dirtied=6 written=14331 -> Bitmap Heap Scan on lineitem (cost=387149.13..1734679.71 rows=18311639 width=20) (actual time=12581.502..27595.477 rows=18247310 loops=1) Recheck Cond: ((l_shipdate >= '1995-01-01'::date) AND (l_shipdate <= '1996-12-31'::date)) Buffers: shared hit=503465 read=615605 written=14267 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..382571.22 rows=18311639 width=0) (actual time=11959.177..11959.177 rows=18356292 loops=1) Index Cond: ((l_shipdate >= '1995-01-01'::date) AND (l_shipdate <= '1996-12-31'::date)) Buffers: shared hit=155 read=49660 written=59 -> Hash (cost=490446.39..490446.39 rows=1207429 width=60) (actual time=26081.018..26081.018 rows=1203863 loops=1) Buckets: 131072 Batches: 1 Memory Usage: 108160kB Buffers: shared hit=284101 read=29297 dirtied=6 written=64 -> Hash Join (cost=15638.06..490446.39 rows=1207429 width=60) (actual time=358.399..25324.339 rows=1203863 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=284101 read=29297 dirtied=6 written=64 -> Seq Scan on orders (cost=0.00..406090.48 rows=15104948 width=8) (actual time=0.016..4391.022 rows=15015000 loops=1) Buffers: shared hit=226077 read=28964 dirtied=6 written=61 -> Hash (cost=14139.26..14139.26 rows=119904 width=60) (actual time=358.291..358.291 rows=119972 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 10779kB Buffers: shared hit=58024 read=333 written=3 -> Nested Loop (cost=905.09..14139.26 rows=119904 width=60) (actual time=17.215..314.712 rows=119972 loops=1) Buffers: shared hit=58024 read=333 written=3 -> Nested Loop (cost=0.00..28.00 rows=2 width=60) (actual time=0.082..0.342 rows=2 loops=1) Join Filter: (((n1.n_name = 'IRAQ'::bpchar) AND (n2.n_name = 'ALGERIA'::bpchar)) OR ((n1.n_name = 'ALGERIA'::bpchar) AND (n2.n_name = 'IRAQ'::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.018..0.035 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.005..0.014 rows=25 loops=1) Buffers: shared hit=1 -> Bitmap Heap Scan on customer (cost=905.09..6455.63 rows=60000 width=8) (actual time=18.502..145.671 rows=59986 loops=2) Recheck Cond: (c_nationkey = n2.n_nationkey) Buffers: shared hit=58021 read=333 written=3 -> Bitmap Index Scan on customer_c_nationkey_c_custkey_idx (cost=0.00..890.09 rows=60000 width=0) (actual time=12.178..12.178 rows=59986 loops=2) Index Cond: (c_nationkey = n2.n_nationkey) Buffers: shared hit=1 read=333 written=3 -> Hash (cost=3179.00..3179.00 rows=100000 width=8) (actual time=76.351..76.351 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.007..49.520 rows=100000 loops=1) Buffers: shared hit=2179 Total runtime: 78059.884 ms (53 rows) COMMIT; COMMIT