BEGIN; BEGIN EXPLAIN (ANALYZE, BUFFERS) select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue from customer, orders, lineitem, supplier, nation, region where c_custkey = o_custkey and l_orderkey = o_orderkey and l_suppkey = s_suppkey and c_nationkey = s_nationkey and s_nationkey = n_nationkey and n_regionkey = r_regionkey and r_name = 'AMERICA' and o_orderdate >= date '1997-01-01' and o_orderdate < date '1997-01-01' + interval '1 year' group by n_name order by revenue desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Sort (cost=1856838.76..1856838.82 rows=25 width=34) (actual time=15673.831..15673.832 rows=5 loops=1) Sort Key: (sum((lineitem.l_extendedprice * (1::double precision - lineitem.l_discount)))) Sort Method: quicksort Memory: 25kB Buffers: shared hit=2224789 read=489976 written=4194 -> HashAggregate (cost=1856837.93..1856838.18 rows=25 width=34) (actual time=15673.764..15673.766 rows=5 loops=1) Group Key: nation.n_name Buffers: shared hit=2224786 read=489976 written=4194 -> Hash Join (cost=92092.72..1856107.75 rows=73018 width=34) (actual time=2479.862..15592.123 rows=72706 loops=1) Hash Cond: ((lineitem.l_suppkey = supplier.s_suppkey) AND (customer.c_nationkey = supplier.s_nationkey)) Buffers: shared hit=2224786 read=489976 written=4194 -> Nested Loop (cost=87413.72..1837007.60 rows=1825463 width=46) (actual time=2409.692..14869.269 rows=1819432 loops=1) Buffers: shared hit=2222604 read=489976 written=4194 -> Hash Join (cost=87413.15..388262.46 rows=456167 width=38) (actual time=2409.664..6741.913 rows=454887 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=224962 read=180700 written=2556 -> Bitmap Heap Scan on orders (cost=48370.98..336105.49 rows=2280834 width=8) (actual time=1204.455..4381.803 rows=2275543 loops=1) Recheck Cond: ((o_orderdate >= '1997-01-01'::date) AND (o_orderdate < '1998-01-01 00:00:00'::timestamp without time zone)) Heap Blocks: exact=253504 Buffers: shared hit=115123 read=144601 written=1311 -> Bitmap Index Scan on orders_o_orderdate_o_orderkey_idx (cost=0.00..47800.77 rows=2280834 width=0) (actual time=1091.486..1091.486 rows=2277844 loops=1) Index Cond: ((o_orderdate >= '1997-01-01'::date) AND (o_orderdate < '1998-01-01 00:00:00'::timestamp without time zone)) Buffers: shared read=6220 written=291 -> Hash (cost=35292.17..35292.17 rows=300000 width=38) (actual time=1201.577..1201.577 rows=299436 loops=1) Buckets: 524288 Batches: 1 Memory Usage: 25151kB Buffers: shared hit=109839 read=36099 written=1245 -> Nested Loop (cost=905.25..35292.17 rows=300000 width=38) (actual time=22.199..1075.563 rows=299436 loops=1) Buffers: shared hit=109839 read=36099 written=1245 -> Nested Loop (cost=0.14..13.95 rows=5 width=30) (actual time=0.049..0.110 rows=5 loops=1) Join Filter: (nation.n_regionkey = region.r_regionkey) Rows Removed by Join Filter: 20 Buffers: shared hit=3 -> Index Scan using pk_nation on nation (cost=0.14..12.51 rows=25 width=34) (actual time=0.012..0.036 rows=25 loops=1) Buffers: shared hit=2 -> Materialize (cost=0.00..1.07 rows=1 width=4) (actual time=0.001..0.002 rows=1 loops=25) Buffers: shared hit=1 -> Seq Scan on region (cost=0.00..1.06 rows=1 width=4) (actual time=0.012..0.013 rows=1 loops=1) Filter: (r_name = 'AMERICA'::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=19.096..202.246 rows=59887 loops=5) Recheck Cond: (c_nationkey = nation.n_nationkey) Heap Blocks: exact=145102 Buffers: shared hit=109836 read=36099 written=1245 -> Bitmap Index Scan on customer_c_nationkey_c_custkey_idx (cost=0.00..890.11 rows=60000 width=0) (actual time=12.481..12.481 rows=59887 loops=5) Index Cond: (c_nationkey = nation.n_nationkey) Buffers: shared hit=7 read=826 written=36 -> Index Scan using lineitem_l_orderkey_idx on lineitem (cost=0.56..3.03 rows=15 width=16) (actual time=0.015..0.016 rows=4 loops=454887) Index Cond: (l_orderkey = orders.o_orderkey) Buffers: shared hit=1997642 read=309276 written=1638 -> Hash (cost=3179.00..3179.00 rows=100000 width=8) (actual time=69.105..69.105 rows=100000 loops=1) Buckets: 131072 Batches: 1 Memory Usage: 4931kB Buffers: shared hit=2179 -> Seq Scan on supplier (cost=0.00..3179.00 rows=100000 width=8) (actual time=0.012..41.147 rows=100000 loops=1) Buffers: shared hit=2179 Planning time: 6.850 ms Execution time: 15675.568 ms (56 rows) COMMIT; COMMIT