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-05-01' and o_orderdate < cast(date '1993-05-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=1185928.87..1185928.92 rows=20 width=175) (actual time=36571.000..36571.008 rows=20 loops=1) Buffers: shared hit=879923 read=534189 -> Sort (cost=1185928.87..1187347.99 rows=567647 width=175) (actual time=36570.995..36571.000 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=879923 read=534189 -> HashAggregate (cost=1165147.52..1170823.99 rows=567647 width=175) (actual time=35949.926..36366.690 rows=381689 loops=1) Buffers: shared hit=879920 read=534189 -> Hash Join (cost=398771.61..1150956.35 rows=567647 width=175) (actual time=6150.478..31690.137 rows=1148634 loops=1) Hash Cond: (customer.c_nationkey = nation.n_nationkey) Buffers: shared hit=879920 read=534189 -> Hash Join (cost=398770.05..1143149.64 rows=567647 width=153) (actual time=6150.419..30956.385 rows=1148634 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=879919 read=534189 -> Merge Join (cost=329742.05..1062768.70 rows=567647 width=12) (actual time=3674.240..26184.648 rows=1148634 loops=1) Merge Cond: (orders.o_orderkey = lineitem.l_orderkey) Buffers: shared hit=845659 read=533171 -> Sort (cost=329742.05..331177.70 rows=574262 width=8) (actual time=3674.041..3860.061 rows=574123 loops=1) Sort Key: orders.o_orderkey Sort Method: quicksort Memory: 51489kB Buffers: shared hit=194516 read=35647 -> Bitmap Heap Scan on orders (cost=12168.08..274810.01 rows=574262 width=8) (actual time=495.423..3378.297 rows=574123 loops=1) Recheck Cond: ((o_orderdate >= '1993-05-01'::date) AND (o_orderdate < '1993-08-01'::date)) Buffers: shared hit=194516 read=35647 -> Bitmap Index Scan on orders_o_orderdate_o_orderkey_idx (cost=0.00..12024.52 rows=574262 width=0) (actual time=338.531..338.531 rows=575263 loops=1) Index Cond: ((o_orderdate >= '1993-05-01'::date) AND (o_orderdate < '1993-08-01'::date)) Buffers: shared read=1571 -> Index Scan using lineitem_l_orderkey_idx_l_returnflag on lineitem (cost=0.00..687301.92 rows=14871659 width=12) (actual time=0.140..19117.058 rows=14823174 loops=1) Buffers: shared hit=651143 read=497524 -> Hash (cost=50278.00..50278.00 rows=1500000 width=145) (actual time=2473.626..2473.626 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 265117kB Buffers: shared hit=34260 read=1018 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=145) (actual time=0.019..1119.559 rows=1500000 loops=1) Buffers: shared hit=34260 read=1018 -> Hash (cost=1.25..1.25 rows=25 width=30) (actual time=0.034..0.034 rows=25 loops=1) Buckets: 1024 Batches: 1 Memory Usage: 2kB Buffers: shared hit=1 -> Seq Scan on nation (cost=0.00..1.25 rows=25 width=30) (actual time=0.011..0.016 rows=25 loops=1) Buffers: shared hit=1 Total runtime: 36625.817 ms (40 rows) COMMIT; COMMIT