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 '1994-03-01' and o_orderdate < cast(date '1994-03-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=1159028.31..1159028.36 rows=20 width=175) (actual time=31176.327..31176.334 rows=20 loops=1) Buffers: shared hit=813638 read=610528 dirtied=175 written=653 -> Sort (cost=1159028.31..1160463.32 rows=574005 width=175) (actual time=31176.325..31176.328 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=813638 read=610528 dirtied=175 written=653 -> HashAggregate (cost=1138014.19..1143754.24 rows=574005 width=175) (actual time=30512.834..30996.474 rows=381472 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=813635 read=610528 dirtied=175 written=653 -> Hash Join (cost=353726.63..1123664.07 rows=574005 width=175) (actual time=4973.197..27155.623 rows=1148919 loops=1) Hash Cond: (customer.c_nationkey = nation.n_nationkey) Buffers: shared hit=813635 read=610528 dirtied=175 written=653 -> Hash Join (cost=353725.07..1115769.94 rows=574005 width=153) (actual time=4973.139..26728.514 rows=1148919 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=813634 read=610528 dirtied=175 written=653 -> Hash Join (cost=284697.07..1038131.86 rows=574005 width=12) (actual time=2860.599..23149.044 rows=1148919 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=796385 read=592499 dirtied=175 written=632 -> Index Scan using lineitem_l_orderkey_idx_l_returnflag on lineitem (cost=0.43..691607.05 rows=14956835 width=12) (actual time=0.078..14212.709 rows=14822651 loops=1) Buffers: shared hit=640504 read=516077 written=504 -> Hash (cost=277421.73..277421.73 rows=581992 width=8) (actual time=2854.334..2854.334 rows=573731 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 30604kB Buffers: shared hit=155881 read=76422 dirtied=175 written=128 -> Bitmap Heap Scan on orders (cost=12637.85..277421.73 rows=581992 width=8) (actual time=328.199..2636.860 rows=573731 loops=1) Recheck Cond: ((o_orderdate >= '1994-03-01'::date) AND (o_orderdate < '1994-06-01'::date)) Heap Blocks: exact=230645 Buffers: shared hit=155881 read=76422 dirtied=175 written=128 -> Bitmap Index Scan on orders_o_orderdate_o_orderkey_idx (cost=0.00..12492.35 rows=581992 width=0) (actual time=239.082..239.082 rows=579410 loops=1) Index Cond: ((o_orderdate >= '1994-03-01'::date) AND (o_orderdate < '1994-06-01'::date)) Buffers: shared read=1658 written=5 -> Hash (cost=50278.00..50278.00 rows=1500000 width=145) (actual time=2096.862..2096.862 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 281501kB Buffers: shared hit=17249 read=18029 written=21 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=145) (actual time=0.012..1010.424 rows=1500000 loops=1) Buffers: shared hit=17249 read=18029 written=21 -> Hash (cost=1.25..1.25 rows=25 width=30) (actual time=0.035..0.035 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.013..0.021 rows=25 loops=1) Buffers: shared hit=1 Planning time: 7.976 ms Execution time: 31213.126 ms (42 rows) COMMIT; COMMIT