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=2283089.69..2283089.74 rows=20 width=176) (actual time=31396.779..31396.784 rows=20 loops=1) Buffers: shared hit=707183 read=653381 dirtied=750 written=774 -> Sort (cost=2283089.69..2284519.04 rows=571739 width=176) (actual time=31396.776..31396.780 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=707183 read=653381 dirtied=750 written=774 -> HashAggregate (cost=2262158.53..2267875.92 rows=571739 width=176) (actual time=31019.762..31259.190 rows=381883 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=707180 read=653381 dirtied=750 written=774 -> Hash Join (cost=345384.82..2247865.06 rows=571739 width=176) (actual time=6876.488..28978.885 rows=1148292 loops=1) Hash Cond: (customer.c_nationkey = nation.n_nationkey) Buffers: shared hit=707180 read=653381 dirtied=750 written=774 -> Hash Join (cost=345383.26..2240002.08 rows=571739 width=154) (actual time=6876.459..28569.053 rows=1148292 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=707179 read=653381 dirtied=750 written=774 -> Hash Join (cost=276355.26..2162398.00 rows=571739 width=12) (actual time=5541.844..26504.379 rows=1148292 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=671901 read=653381 dirtied=750 written=774 -> Seq Scan on lineitem (cost=0.00..1824308.60 rows=14937799 width=12) (actual time=0.047..17621.379 rows=14823489 loops=1) Filter: (l_returnflag = 'R'::bpchar) Rows Removed by Filter: 45222732 Buffers: shared hit=436138 read=634599 dirtied=750 written=734 -> Hash (cost=269142.92..269142.92 rows=576987 width=8) (actual time=5538.287..5538.287 rows=574316 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 30627kB Buffers: shared hit=235763 read=18782 written=40 -> Bitmap Heap Scan on orders (cost=5954.12..269142.92 rows=576987 width=8) (actual time=27.449..5327.335 rows=574316 loops=1) Recheck Cond: ((o_orderdate >= '1993-07-01'::date) AND (o_orderdate < '1993-10-01'::date)) Rows Removed by Index Recheck: 14440684 Heap Blocks: lossy=254534 Buffers: shared hit=235763 read=18782 written=40 -> Bitmap Index Scan on orders_o_orderkey_o_orderdate_brin_idx (cost=0.00..5809.87 rows=576987 width=0) (actual time=27.265..27.265 rows=2545920 loops=1) Index Cond: ((o_orderdate >= '1993-07-01'::date) AND (o_orderdate < '1993-10-01'::date)) Buffers: shared hit=11 -> Hash (cost=50278.00..50278.00 rows=1500000 width=146) (actual time=1328.471..1328.471 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=146) (actual time=0.008..546.494 rows=1500000 loops=1) Buffers: shared hit=35278 -> Hash (cost=1.25..1.25 rows=25 width=30) (actual time=0.018..0.018 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.004..0.007 rows=25 loops=1) Buffers: shared hit=1 Planning time: 3.911 ms Execution time: 31411.190 ms (45 rows) COMMIT; COMMIT