BEGIN; BEGIN EXPLAIN (ANALYZE, BUFFERS) select c_custkey, c_name, sum(l_extendedprice * (1 - l_discount)) as revenue, c_acctbal, n_name, c_address, c_phone, c_comment from customer, orders, lineitem, nation where c_custkey = o_custkey and l_orderkey = o_orderkey and o_orderdate >= date '1993-07-01' and o_orderdate < cast(date '1993-07-01' + interval '3 month' as date) and l_returnflag = 'R' and c_nationkey = n_nationkey group by c_custkey, c_name, c_acctbal, c_phone, n_name, c_address, c_comment order by revenue desc LIMIT 20; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=1158680.47..1158680.52 rows=20 width=176) (actual time=27801.489..27801.495 rows=20 loops=1) Buffers: shared hit=764346 read=664022 dirtied=1873 written=5266 -> Sort (cost=1158680.47..1160111.06 rows=572236 width=176) (actual time=27801.485..27801.486 rows=20 loops=1) Sort Key: (sum((lineitem.l_extendedprice * (1::double precision - lineitem.l_discount)))) Sort Method: top-N heapsort Memory: 30kB Buffers: shared hit=764346 read=664022 dirtied=1873 written=5266 -> HashAggregate (cost=1137731.11..1143453.47 rows=572236 width=176) (actual time=27274.009..27649.441 rows=381633 loops=1) Group Key: customer.c_custkey, customer.c_name, customer.c_acctbal, customer.c_phone, nation.n_name, customer.c_address, customer.c_comment Buffers: shared hit=764343 read=664022 dirtied=1873 written=5266 -> Hash Join (cost=353651.55..1123425.21 rows=572236 width=176) (actual time=4673.376..24217.485 rows=1147161 loops=1) Hash Cond: (customer.c_nationkey = nation.n_nationkey) Buffers: shared hit=764343 read=664022 dirtied=1873 written=5266 -> Hash Join (cost=353649.99..1115555.41 rows=572236 width=154) (actual time=4673.331..23793.331 rows=1147161 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=764342 read=664022 dirtied=1873 written=5266 -> Hash Join (cost=284621.99..1037943.87 rows=572236 width=12) (actual time=2626.403..20452.019 rows=1147161 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=764340 read=628746 dirtied=1873 written=1773 -> Index Scan using lineitem_l_orderkey_idx_l_returnflag on lineitem (cost=0.43..691533.92 rows=14950942 width=12) (actual time=0.067..13909.329 rows=14807792 loops=1) Buffers: shared hit=596047 read=564871 dirtied=1873 written=1120 -> Hash (cost=277366.22..277366.22 rows=580427 width=8) (actual time=2620.347..2620.347 rows=573787 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 30606kB Buffers: shared hit=168293 read=63875 written=653 -> Bitmap Heap Scan on orders (cost=12605.81..277366.22 rows=580427 width=8) (actual time=311.933..2419.072 rows=573787 loops=1) Recheck Cond: ((o_orderdate >= '1993-07-01'::date) AND (o_orderdate < '1993-10-01'::date)) Heap Blocks: exact=230508 Buffers: shared hit=168293 read=63875 written=653 -> Bitmap Index Scan on orders_o_orderdate_o_orderkey_idx (cost=0.00..12460.70 rows=580427 width=0) (actual time=227.642..227.642 rows=580443 loops=1) Index Cond: ((o_orderdate >= '1993-07-01'::date) AND (o_orderdate < '1993-10-01'::date)) Buffers: shared hit=99 read=1561 written=151 -> Hash (cost=50278.00..50278.00 rows=1500000 width=146) (actual time=2022.321..2022.321 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 281501kB Buffers: shared hit=2 read=35276 written=3493 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=146) (actual time=0.025..987.077 rows=1500000 loops=1) Buffers: shared hit=2 read=35276 written=3493 -> Hash (cost=1.25..1.25 rows=25 width=30) (actual time=0.023..0.023 rows=25 loops=1) Buckets: 1024 Batches: 1 Memory Usage: 10kB Buffers: shared hit=1 -> Seq Scan on nation (cost=0.00..1.25 rows=25 width=30) (actual time=0.009..0.011 rows=25 loops=1) Buffers: shared hit=1 Planning time: 5.578 ms Execution time: 27836.245 ms (42 rows) COMMIT; COMMIT