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-07-01' and o_orderdate < cast(date '1993-07-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=1157972.50..1157972.55 rows=20 width=175) (actual time=28118.607..28118.615 rows=20 loops=1) Buffers: shared hit=1055591 read=364291 dirtied=110 written=3580 -> Sort (cost=1157972.50..1159408.46 rows=574385 width=175) (actual time=28118.603..28118.606 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=1055591 read=364291 dirtied=110 written=3580 -> HashAggregate (cost=1136944.47..1142688.32 rows=574385 width=175) (actual time=27560.034..27948.968 rows=381627 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=1055588 read=364291 dirtied=110 written=3580 -> Hash Join (cost=353192.40..1122584.84 rows=574385 width=175) (actual time=4636.299..23231.475 rows=1147179 loops=1) Hash Cond: (customer.c_nationkey = nation.n_nationkey) Buffers: shared hit=1055588 read=364291 dirtied=110 written=3580 -> Hash Join (cost=353190.83..1114685.49 rows=574385 width=153) (actual time=4636.256..22818.817 rows=1147179 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=1055587 read=364291 dirtied=110 written=3580 -> Hash Join (cost=284162.83..1037041.71 rows=574385 width=12) (actual time=2925.483..20211.750 rows=1147179 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1022986 read=361614 dirtied=110 written=3576 -> Index Scan using lineitem_l_orderkey_idx_l_returnflag on lineitem (cost=0.43..691069.52 rows=14950919 width=12) (actual time=0.062..13228.142 rows=14807964 loops=1) Buffers: shared hit=880274 read=272627 written=3104 -> Hash (cost=276894.20..276894.20 rows=581456 width=8) (actual time=2919.485..2919.485 rows=573808 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 30607kB Buffers: shared hit=142712 read=88987 dirtied=110 written=472 -> Bitmap Heap Scan on orders (cost=12624.36..276894.20 rows=581456 width=8) (actual time=324.008..2707.083 rows=573808 loops=1) Recheck Cond: ((o_orderdate >= '1993-07-01'::date) AND (o_orderdate < '1993-10-01'::date)) Heap Blocks: exact=230048 Buffers: shared hit=142712 read=88987 dirtied=110 written=472 -> Bitmap Index Scan on orders_o_orderdate_o_orderkey_idx (cost=0.00..12479.00 rows=581456 width=0) (actual time=232.872..232.872 rows=578778 loops=1) Index Cond: ((o_orderdate >= '1993-07-01'::date) AND (o_orderdate < '1993-10-01'::date)) Buffers: shared read=1651 written=2 -> Hash (cost=50278.00..50278.00 rows=1500000 width=145) (actual time=1698.396..1698.396 rows=1500000 loops=1) Buckets: 2097152 Batches: 1 Memory Usage: 281501kB Buffers: shared hit=32601 read=2677 written=4 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=145) (actual time=0.020..723.411 rows=1500000 loops=1) Buffers: shared hit=32601 read=2677 written=4 -> Hash (cost=1.25..1.25 rows=25 width=30) (actual time=0.025..0.025 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.008..0.010 rows=25 loops=1) Buffers: shared hit=1 Planning time: 5.541 ms Execution time: 28144.581 ms (42 rows) COMMIT; COMMIT