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-02-01' and o_orderdate < cast(date '1993-02-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=1177589.45..1177589.50 rows=20 width=175) (actual time=40650.093..40650.100 rows=20 loops=1) Buffers: shared hit=650727 read=757915 written=39776 -> Sort (cost=1177589.45..1178933.85 rows=537761 width=175) (actual time=40650.089..40650.090 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=650727 read=757915 written=39776 -> HashAggregate (cost=1157902.21..1163279.82 rows=537761 width=175) (actual time=40072.421..40463.326 rows=372744 loops=1) Buffers: shared hit=650724 read=757915 written=39776 -> Hash Join (cost=394309.78..1144458.19 rows=537761 width=175) (actual time=5293.279..31530.723 rows=1113032 loops=1) Hash Cond: (customer.c_nationkey = nation.n_nationkey) Buffers: shared hit=650724 read=757915 written=39776 -> Hash Join (cost=394308.22..1137062.41 rows=537761 width=153) (actual time=5293.241..30920.672 rows=1113032 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=650723 read=757915 written=39776 -> Merge Join (cost=325280.22..1057279.19 rows=537761 width=12) (actual time=2683.907..25580.663 rows=1113032 loops=1) Merge Cond: (orders.o_orderkey = lineitem.l_orderkey) Buffers: shared hit=622760 read=750600 written=39776 -> Sort (cost=325280.19..326639.92 rows=543894 width=8) (actual time=2683.736..2857.719 rows=555222 loops=1) Sort Key: orders.o_orderkey Sort Method: quicksort Memory: 50603kB Buffers: shared hit=226720 read=1521 -> Bitmap Heap Scan on orders (cost=11532.81..273466.22 rows=543894 width=8) (actual time=294.496..2018.185 rows=555222 loops=1) Recheck Cond: ((o_orderdate >= '1993-02-01'::date) AND (o_orderdate < '1993-05-01'::date)) Buffers: shared hit=226720 read=1521 -> Bitmap Index Scan on orders_o_orderdate_o_orderkey_idx (cost=0.00..11396.84 rows=543894 width=0) (actual time=219.366..219.366 rows=556265 loops=1) Index Cond: ((o_orderdate >= '1993-02-01'::date) AND (o_orderdate < '1993-05-01'::date)) Buffers: shared read=1521 -> Index Scan using lineitem_l_orderkey_idx_l_returnflag on lineitem (cost=0.00..686752.28 rows=14860480 width=12) (actual time=0.104..19849.093 rows=14808171 loops=1) Buffers: shared hit=396040 read=749079 written=39776 -> Hash (cost=50278.00..50278.00 rows=1500000 width=145) (actual time=2607.670..2607.670 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 265117kB Buffers: shared hit=27963 read=7315 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=145) (actual time=0.012..935.645 rows=1500000 loops=1) Buffers: shared hit=27963 read=7315 -> Hash (cost=1.25..1.25 rows=25 width=30) (actual time=0.021..0.021 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.007..0.010 rows=25 loops=1) Buffers: shared hit=1 Total runtime: 40759.650 ms (40 rows) COMMIT; COMMIT