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 = 'ROMANIA' and n2.n_name = 'INDIA') or (n1.n_name = 'INDIA' and n2.n_name = 'ROMANIA') ) 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=2356729.13..2358624.40 rows=58316 width=64) (actual time=73760.979..73787.942 rows=4 loops=1) Buffers: shared hit=877240 read=553622 written=4991 -> Sort (cost=2356729.13..2356874.92 rows=58316 width=64) (actual time=73751.183..73757.573 rows=60102 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: 9988kB Buffers: shared hit=877240 read=553622 written=4991 -> Hash Join (cost=895362.88..2352112.95 rows=58316 width=64) (actual time=41212.533..73495.475 rows=60102 loops=1) Hash Cond: ((lineitem.l_suppkey = supplier.s_suppkey) AND (n1.n_nationkey = supplier.s_nationkey)) Buffers: shared hit=877232 read=553622 written=4991 -> Hash Join (cost=890683.88..2317368.97 rows=1459512 width=72) (actual time=41140.449..70857.798 rows=1463095 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=875050 read=553622 written=4991 -> Bitmap Heap Scan on lineitem (cost=386604.51..1730225.08 rows=18258505 width=20) (actual time=13779.345..26193.918 rows=18229496 loops=1) Recheck Cond: ((l_shipdate >= '1995-01-01'::date) AND (l_shipdate <= '1996-12-31'::date)) Buffers: shared hit=627710 read=488258 written=4129 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..382039.88 rows=18258505 width=0) (actual time=12874.023..12874.023 rows=18315931 loops=1) Index Cond: ((l_shipdate >= '1995-01-01'::date) AND (l_shipdate <= '1996-12-31'::date)) Buffers: shared hit=7273 read=42542 written=2908 -> Hash (cost=489031.49..489031.49 rows=1203831 width=60) (actual time=27359.882..27359.882 rows=1199634 loops=1) Buckets: 131072 Batches: 1 Memory Usage: 107780kB Buffers: shared hit=247340 read=65364 written=862 -> Hash Join (cost=15638.06..489031.49 rows=1203831 width=60) (actual time=875.365..25872.004 rows=1199634 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=247340 read=65364 written=862 -> Seq Scan on orders (cost=0.00..404880.36 rows=15059936 width=8) (actual time=0.018..4551.341 rows=15000000 loops=1) Buffers: shared hit=223471 read=30810 written=42 -> Hash (cost=14139.26..14139.26 rows=119904 width=60) (actual time=875.151..875.151 rows=120263 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 10805kB Buffers: shared hit=23869 read=34554 written=820 -> Nested Loop (cost=905.09..14139.26 rows=119904 width=60) (actual time=31.767..792.574 rows=120263 loops=1) Buffers: shared hit=23869 read=34554 written=820 -> Nested Loop (cost=0.00..28.00 rows=2 width=60) (actual time=0.166..0.351 rows=2 loops=1) Join Filter: (((n1.n_name = 'ROMANIA'::bpchar) AND (n2.n_name = 'INDIA'::bpchar)) OR ((n1.n_name = 'INDIA'::bpchar) AND (n2.n_name = 'ROMANIA'::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.027..0.040 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.009 rows=25 loops=1) Buffers: shared hit=1 -> Bitmap Heap Scan on customer (cost=905.09..6455.63 rows=60000 width=8) (actual time=26.304..379.045 rows=60132 loops=2) Recheck Cond: (c_nationkey = n2.n_nationkey) Buffers: shared hit=23866 read=34554 written=820 -> Bitmap Index Scan on customer_c_nationkey_c_custkey_idx (cost=0.00..890.09 rows=60000 width=0) (actual time=17.639..17.639 rows=60132 loops=2) Index Cond: (c_nationkey = n2.n_nationkey) Buffers: shared hit=1 read=336 written=4 -> Hash (cost=3179.00..3179.00 rows=100000 width=8) (actual time=71.214..71.214 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..44.424 rows=100000 loops=1) Buffers: shared hit=2179 Total runtime: 73830.283 ms (53 rows) COMMIT; COMMIT