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 = 'MIDDLE EAST' and o_orderdate >= date '1996-01-01' and o_orderdate < date '1996-01-01' + interval '1 year' group by n_name order by revenue desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Sort (cost=2439964.10..2439964.16 rows=25 width=34) (actual time=153662.987..153662.987 rows=5 loops=1) Sort Key: (sum((lineitem.l_extendedprice * (1::double precision - lineitem.l_discount)))) Sort Method: quicksort Memory: 25kB Buffers: shared hit=780611 read=703465 written=6 -> HashAggregate (cost=2439963.27..2439963.52 rows=25 width=34) (actual time=153662.899..153662.901 rows=5 loops=1) Buffers: shared hit=780608 read=703465 written=6 -> Hash Join (cost=402391.17..2439227.10 rows=73617 width=34) (actual time=29293.896..153332.310 rows=72751 loops=1) Hash Cond: ((lineitem.l_suppkey = supplier.s_suppkey) AND (customer.c_nationkey = supplier.s_nationkey)) Buffers: shared hit=780608 read=703465 written=6 -> Hash Join (cost=397712.17..2396997.31 rows=1840731 width=46) (actual time=29111.784..147939.611 rows=1826305 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=778426 read=703465 written=6 -> Seq Scan on lineitem (cost=0.00..1678557.89 rows=60463989 width=16) (actual time=0.027..65601.552 rows=60044664 loops=1) Buffers: shared hit=418265 read=655653 written=6 -> Hash (cost=391958.37..391958.37 rows=460304 width=38) (actual time=29111.110..29111.110 rows=456553 loops=1) Buckets: 65536 Batches: 1 Memory Usage: 32102kB Buffers: shared hit=360161 read=47812 -> Hash Join (cost=88906.79..391958.37 rows=460304 width=38) (actual time=8863.802..28672.586 rows=456553 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=360161 read=47812 -> Bitmap Heap Scan on orders (cost=49864.58..339682.41 rows=2301522 width=8) (actual time=2451.744..14135.068 rows=2283996 loops=1) Recheck Cond: ((o_orderdate >= '1996-01-01'::date) AND (o_orderdate < '1997-01-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=247654 read=14162 -> Bitmap Index Scan on orders_o_orderdate_o_orderkey_idx (cost=0.00..49289.20 rows=2301522 width=0) (actual time=2307.783..2307.783 rows=2299883 loops=1) Index Cond: ((o_orderdate >= '1996-01-01'::date) AND (o_orderdate < '1997-01-01 00:00:00'::timestamp without time zone)) Buffers: shared read=6538 -> Hash (cost=35292.22..35292.22 rows=300000 width=38) (actual time=6411.667..6411.667 rows=299838 loops=1) Buckets: 32768 Batches: 1 Memory Usage: 21083kB Buffers: shared hit=112507 read=33650 -> Nested Loop (cost=905.09..35292.22 rows=300000 width=38) (actual time=63.399..6162.193 rows=299838 loops=1) Buffers: shared hit=112507 read=33650 -> Nested Loop (cost=0.00..14.07 rows=5 width=30) (actual time=0.084..0.212 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.00..12.63 rows=25 width=34) (actual time=0.017..0.069 rows=25 loops=1) Buffers: shared hit=2 -> Materialize (cost=0.00..1.07 rows=1 width=4) (actual time=0.002..0.003 rows=1 loops=25) Buffers: shared hit=1 -> Seq Scan on region (cost=0.00..1.06 rows=1 width=4) (actual time=0.036..0.036 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.09..6455.63 rows=60000 width=8) (actual time=48.473..1206.498 rows=59968 loops=5) Recheck Cond: (c_nationkey = nation.n_nationkey) Buffers: shared hit=112504 read=33650 -> Bitmap Index Scan on customer_c_nationkey_c_custkey_idx (cost=0.00..890.09 rows=60000 width=0) (actual time=39.162..39.162 rows=59968 loops=5) Index Cond: (c_nationkey = nation.n_nationkey) Buffers: shared hit=5 read=832 -> Hash (cost=3179.00..3179.00 rows=100000 width=8) (actual time=180.665..180.665 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.013..128.063 rows=100000 loops=1) Buffers: shared hit=2179 Total runtime: 153685.987 ms (55 rows) COMMIT; COMMIT