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 = 'FRANCE') or (n1.n_name = 'FRANCE' 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=2365126.28..2367026.30 rows=58462 width=64) (actual time=184130.486..184171.607 rows=4 loops=1) Buffers: shared hit=539247 read=898810 dirtied=1 written=5044 -> Sort (cost=2365126.28..2365272.44 rows=58462 width=64) (actual time=184119.480..184130.984 rows=58098 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: 9707kB Buffers: shared hit=539247 read=898810 dirtied=1 written=5044 -> Hash Join (cost=897326.31..2360497.49 rows=58462 width=64) (actual time=71559.769..183771.302 rows=58098 loops=1) Hash Cond: ((lineitem.l_suppkey = supplier.s_suppkey) AND (n1.n_nationkey = supplier.s_nationkey)) Buffers: shared hit=539239 read=898810 dirtied=1 written=5044 -> Hash Join (cost=892647.31..2325705.52 rows=1461802 width=72) (actual time=71385.130..179033.473 rows=1460000 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=537057 read=898810 dirtied=1 written=5044 -> Bitmap Heap Scan on lineitem (cost=386134.19..1735997.54 rows=18287157 width=20) (actual time=20021.925..103231.333 rows=18227913 loops=1) Recheck Cond: ((l_shipdate >= '1995-01-01'::date) AND (l_shipdate <= '1996-12-31'::date)) Buffers: shared hit=266051 read=855710 written=2686 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..381562.40 rows=18287157 width=0) (actual time=19337.645..19337.645 rows=18407518 loops=1) Index Cond: ((l_shipdate >= '1995-01-01'::date) AND (l_shipdate <= '1996-12-31'::date)) Buffers: shared hit=4177 read=45638 written=2508 -> Hash (cost=491390.26..491390.26 rows=1209829 width=60) (actual time=51362.534..51362.534 rows=1203502 loops=1) Buckets: 131072 Batches: 1 Memory Usage: 108128kB Buffers: shared hit=271006 read=43100 dirtied=1 written=2358 -> Hash Join (cost=15638.06..491390.26 rows=1209829 width=60) (actual time=4733.329..50149.986 rows=1203502 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=271006 read=43100 dirtied=1 written=2358 -> Seq Scan on orders (cost=0.00..406897.75 rows=15134975 width=8) (actual time=0.017..13620.815 rows=15000000 loops=1) Buffers: shared hit=247031 read=8517 dirtied=1 written=39 -> Hash (cost=14139.26..14139.26 rows=119904 width=60) (actual time=4733.200..4733.200 rows=120285 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 10807kB Buffers: shared hit=23975 read=34583 written=2319 -> Nested Loop (cost=905.09..14139.26 rows=119904 width=60) (actual time=41.037..4618.881 rows=120285 loops=1) Buffers: shared hit=23975 read=34583 written=2319 -> Nested Loop (cost=0.00..28.00 rows=2 width=60) (actual time=0.113..0.433 rows=2 loops=1) Join Filter: (((n1.n_name = 'EGYPT'::bpchar) AND (n2.n_name = 'FRANCE'::bpchar)) OR ((n1.n_name = 'FRANCE'::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.016..0.034 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.004..0.011 rows=25 loops=1) Buffers: shared hit=1 -> Bitmap Heap Scan on customer (cost=905.09..6455.63 rows=60000 width=8) (actual time=43.911..2281.535 rows=60142 loops=2) Recheck Cond: (c_nationkey = n2.n_nationkey) Buffers: shared hit=23972 read=34583 written=2319 -> Bitmap Index Scan on customer_c_nationkey_c_custkey_idx (cost=0.00..890.09 rows=60000 width=0) (actual time=33.825..33.825 rows=60142 loops=2) Index Cond: (c_nationkey = n2.n_nationkey) Buffers: shared hit=1 read=335 written=19 -> Hash (cost=3179.00..3179.00 rows=100000 width=8) (actual time=169.414..169.414 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.023..123.645 rows=100000 loops=1) Buffers: shared hit=2179 Total runtime: 184201.979 ms (53 rows) COMMIT; COMMIT