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-02-01' and o_orderdate < cast(date '1994-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=1151125.19..1151125.24 rows=20 width=175) (actual time=19552.480..19552.489 rows=20 loops=1) Buffers: shared hit=1353211 read=63365 written=3509 -> Sort (cost=1151125.19..1152468.32 rows=537252 width=175) (actual time=19552.477..19552.481 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=1353211 read=63365 written=3509 -> HashAggregate (cost=1131456.58..1136829.10 rows=537252 width=175) (actual time=19094.942..19407.600 rows=371940 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=1353208 read=63365 written=3509 -> Hash Join (cost=351404.45..1118025.28 rows=537252 width=175) (actual time=3319.080..17359.630 rows=1109444 loops=1) Hash Cond: (customer.c_nationkey = nation.n_nationkey) Buffers: shared hit=1353208 read=63365 written=3509 -> Hash Join (cost=351402.89..1110636.51 rows=537252 width=153) (actual time=3319.047..17002.101 rows=1109444 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=1353207 read=63365 written=3509 -> Hash Join (cost=282374.89..1033549.73 rows=537252 width=12) (actual time=1703.336..14631.161 rows=1109444 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1317929 read=63365 written=3509 -> Index Scan using lineitem_l_orderkey_idx_l_returnflag on lineitem (cost=0.43..689865.05 rows=14916721 width=12) (actual time=0.098..9595.115 rows=14807964 loops=1) Buffers: shared hit=1093853 read=57959 written=3504 -> Hash (cost=275560.54..275560.54 rows=545113 width=8) (actual time=1697.192..1697.192 rows=554270 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 29844kB Buffers: shared hit=224076 read=5406 written=5 -> Bitmap Heap Scan on orders (cost=11835.84..275560.54 rows=545113 width=8) (actual time=259.282..1527.062 rows=554270 loops=1) Recheck Cond: ((o_orderdate >= '1994-02-01'::date) AND (o_orderdate < '1994-05-01'::date)) Heap Blocks: exact=227887 Buffers: shared hit=224076 read=5406 written=5 -> Bitmap Index Scan on orders_o_orderdate_o_orderkey_idx (cost=0.00..11699.57 rows=545113 width=0) (actual time=183.844..183.844 rows=559266 loops=1) Index Cond: ((o_orderdate >= '1994-02-01'::date) AND (o_orderdate < '1994-05-01'::date)) Buffers: shared hit=1 read=1594 -> Hash (cost=50278.00..50278.00 rows=1500000 width=145) (actual time=1604.680..1604.680 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 281501kB Buffers: shared hit=35278 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=145) (actual time=0.014..699.169 rows=1500000 loops=1) Buffers: shared hit=35278 -> Hash (cost=1.25..1.25 rows=25 width=30) (actual time=0.019..0.019 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.006..0.011 rows=25 loops=1) Buffers: shared hit=1 Planning time: 4.140 ms Execution time: 19575.683 ms (42 rows) COMMIT; COMMIT