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-10-01' and o_orderdate < cast(date '1993-10-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=1157331.85..1157331.90 rows=20 width=175) (actual time=24641.585..24641.602 rows=20 loops=1) Buffers: shared hit=831975 read=595930 dirtied=329 written=933 -> Sort (cost=1157331.85..1158745.00 rows=565261 width=175) (actual time=24641.583..24641.595 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=831975 read=595930 dirtied=329 written=933 -> HashAggregate (cost=1136637.84..1142290.45 rows=565261 width=175) (actual time=24113.151..24489.552 rows=381460 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=831972 read=595930 dirtied=329 written=933 -> Hash Join (cost=353310.93..1122506.32 rows=565261 width=175) (actual time=4766.862..22165.412 rows=1148455 loops=1) Hash Cond: (customer.c_nationkey = nation.n_nationkey) Buffers: shared hit=831972 read=595930 dirtied=329 written=933 -> Hash Join (cost=353309.36..1114732.42 rows=565261 width=153) (actual time=4766.829..21777.586 rows=1148455 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=831971 read=595930 dirtied=329 written=933 -> Hash Join (cost=284281.36..1037225.50 rows=565261 width=12) (actual time=3312.079..19469.300 rows=1148455 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=797195 read=595428 dirtied=329 written=932 -> Index Scan using lineitem_l_orderkey_idx_l_returnflag on lineitem (cost=0.43..691242.70 rows=14946472 width=12) (actual time=0.076..12147.983 rows=14822651 loops=1) Buffers: shared hit=623921 read=536519 dirtied=114 written=877 -> Hash (cost=277111.89..277111.89 rows=573523 width=8) (actual time=2675.791..2675.791 rows=573892 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 30610kB Buffers: shared hit=173274 read=58909 dirtied=215 written=55 -> Bitmap Heap Scan on orders (cost=12455.05..277111.89 rows=573523 width=8) (actual time=812.134..2467.129 rows=573892 loops=1) Recheck Cond: ((o_orderdate >= '1993-10-01'::date) AND (o_orderdate < '1994-01-01'::date)) Heap Blocks: exact=230527 Buffers: shared hit=173274 read=58909 dirtied=215 written=55 -> Bitmap Index Scan on orders_o_orderdate_o_orderkey_idx (cost=0.00..12311.66 rows=573523 width=0) (actual time=725.812..725.812 rows=579534 loops=1) Index Cond: ((o_orderdate >= '1993-10-01'::date) AND (o_orderdate < '1994-01-01'::date)) Buffers: shared read=1656 written=4 -> Hash (cost=50278.00..50278.00 rows=1500000 width=145) (actual time=1443.221..1443.221 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 281501kB Buffers: shared hit=34776 read=502 written=1 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=145) (actual time=0.016..607.896 rows=1500000 loops=1) Buffers: shared hit=34776 read=502 written=1 -> 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 (cost=0.00..1.25 rows=25 width=30) (actual time=0.005..0.008 rows=25 loops=1) Buffers: shared hit=1 Planning time: 4.305 ms Execution time: 24673.493 ms (42 rows) COMMIT; COMMIT