BEGIN; BEGIN EXPLAIN (ANALYZE, BUFFERS) select o_year, sum(case when nation = 'SAUDI ARABIA' then volume else 0 end) / sum(volume) as mkt_share from ( select extract(year from o_orderdate) as o_year, l_extendedprice * (1 - l_discount) as volume, n2.n_name as nation from part, supplier, lineitem, orders, customer, nation n1, nation n2, region where p_partkey = l_partkey and s_suppkey = l_suppkey and l_orderkey = o_orderkey and o_custkey = c_custkey and c_nationkey = n1.n_nationkey and n1.n_regionkey = r_regionkey and r_name = 'MIDDLE EAST' and s_nationkey = n2.n_nationkey and o_orderdate between date '1995-01-01' and date '1996-12-31' and p_type = 'SMALL BRUSHED TIN' ) as all_nations group by o_year order by o_year; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Sort (cost=1724842.75..1724844.57 rows=729 width=38) (actual time=10243.232..10243.233 rows=2 loops=1) Sort Key: (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 25kB Buffers: shared hit=2037688 read=276173 dirtied=868 written=267 -> HashAggregate (cost=1724795.33..1724808.08 rows=729 width=38) (actual time=10243.173..10243.174 rows=2 loops=1) Group Key: date_part('year'::text, (orders.o_orderdate)::timestamp without time zone) Buffers: shared hit=2037685 read=276173 dirtied=868 written=267 -> Hash Join (cost=39444.83..1724310.99 rows=24217 width=38) (actual time=711.751..10204.373 rows=24523 loops=1) Hash Cond: (supplier.s_nationkey = n2.n_nationkey) Buffers: shared hit=2037685 read=276173 dirtied=868 written=267 -> Nested Loop (cost=39443.27..1723855.36 rows=24217 width=16) (actual time=711.694..10170.851 rows=24523 loops=1) Buffers: shared hit=2037681 read=276173 dirtied=868 written=267 -> Hash Join (cost=39442.98..1716041.43 rows=24217 width=16) (actual time=711.674..9989.937 rows=24523 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=1963979 read=276173 dirtied=868 written=267 -> Nested Loop (cost=412.29..1676314.50 rows=121087 width=20) (actual time=7.090..9211.370 rows=122241 loops=1) Buffers: shared hit=1818775 read=275222 dirtied=868 written=267 -> Nested Loop (cost=411.86..1480413.50 rows=400088 width=16) (actual time=6.842..3551.732 rows=404603 loops=1) Buffers: shared hit=298199 read=175253 dirtied=868 written=160 -> Bitmap Heap Scan on part (cost=411.29..28047.06 rows=13273 width=4) (actual time=6.781..132.001 rows=13459 loops=1) Recheck Cond: ((p_type)::text = 'SMALL BRUSHED TIN'::text) Heap Blocks: exact=11466 Buffers: shared hit=3782 read=7753 written=4 -> Bitmap Index Scan on part_p_type_p_partkey_idx (cost=0.00..407.98 rows=13273 width=0) (actual time=4.557..4.557 rows=13459 loops=1) Index Cond: ((p_type)::text = 'SMALL BRUSHED TIN'::text) Buffers: shared read=69 -> Index Scan using lineitem_l_partkey_l_quantity_l_shipmode_idx on lineitem (cost=0.56..109.11 rows=31 width=20) (actual time=0.025..0.244 rows=30 loops=13459) Index Cond: (l_partkey = part.p_partkey) Buffers: shared hit=294417 read=167500 dirtied=868 written=156 -> Index Scan using pk_orders on orders (cost=0.43..0.48 rows=1 width=12) (actual time=0.013..0.013 rows=0 loops=404603) Index Cond: (o_orderkey = lineitem.l_orderkey) Filter: ((o_orderdate >= '1995-01-01'::date) AND (o_orderdate <= '1996-12-31'::date)) Rows Removed by Filter: 1 Buffers: shared hit=1520576 read=99969 written=107 -> Hash (cost=35280.69..35280.69 rows=300000 width=4) (actual time=701.274..701.274 rows=299838 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 14638kB Buffers: shared hit=145204 read=951 -> Nested Loop (cost=906.18..35280.69 rows=300000 width=4) (actual time=20.488..616.106 rows=299838 loops=1) Buffers: shared hit=145204 read=951 -> Hash Join (cost=1.07..2.47 rows=5 width=4) (actual time=0.044..0.074 rows=5 loops=1) Hash Cond: (n1.n_regionkey = region.r_regionkey) Buffers: shared hit=2 -> Seq Scan on nation n1 (cost=0.00..1.25 rows=25 width=8) (actual time=0.005..0.011 rows=25 loops=1) Buffers: shared hit=1 -> Hash (cost=1.06..1.06 rows=1 width=4) (actual time=0.015..0.015 rows=1 loops=1) Buckets: 1024 Batches: 1 Memory Usage: 9kB Buffers: shared hit=1 -> Seq Scan on region (cost=0.00..1.06 rows=1 width=4) (actual time=0.008..0.009 rows=1 loops=1) Filter: (r_name = 'MIDDLE EAST'::bpchar) Rows Removed by Filter: 4 Buffers: shared hit=1 -> Bitmap Heap Scan on customer (cost=905.11..6455.64 rows=60000 width=8) (actual time=18.230..113.187 rows=59968 loops=5) Recheck Cond: (c_nationkey = n1.n_nationkey) Heap Blocks: exact=145317 Buffers: shared hit=145202 read=951 -> Bitmap Index Scan on customer_c_nationkey_c_custkey_idx (cost=0.00..890.11 rows=60000 width=0) (actual time=11.935..11.935 rows=59968 loops=5) Index Cond: (c_nationkey = n1.n_nationkey) Buffers: shared hit=5 read=831 -> Index Scan using pk_supplier on supplier (cost=0.29..0.31 rows=1 width=8) (actual time=0.006..0.006 rows=1 loops=24523) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=73702 -> Hash (cost=1.25..1.25 rows=25 width=30) (actual time=0.020..0.020 rows=25 loops=1) Buckets: 1024 Batches: 1 Memory Usage: 10kB Buffers: shared hit=1 -> Seq Scan on nation n2 (cost=0.00..1.25 rows=25 width=30) (actual time=0.003..0.006 rows=25 loops=1) Buffers: shared hit=1 Planning time: 8.142 ms Execution time: 10243.997 ms (68 rows) COMMIT; COMMIT