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-05-01' and o_orderdate < cast(date '1993-05-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=2293435.03..2293435.08 rows=20 width=176) (actual time=30723.791..30723.798 rows=20 loops=1) Buffers: shared hit=1128864 read=238274 dirtied=321 written=5 -> Sort (cost=2293435.03..2294860.02 rows=569993 width=176) (actual time=30723.789..30723.796 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=1128864 read=238274 dirtied=321 written=5 -> HashAggregate (cost=2272567.80..2278267.73 rows=569993 width=176) (actual time=30374.939..30585.653 rows=381756 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=1128861 read=238274 dirtied=321 written=5 -> Hash Join (cost=346585.76..2258317.97 rows=569993 width=176) (actual time=7269.503..28439.612 rows=1148730 loops=1) Hash Cond: (customer.c_nationkey = nation.n_nationkey) Buffers: shared hit=1128861 read=238274 dirtied=321 written=5 -> Hash Join (cost=346584.19..2250479.00 rows=569993 width=154) (actual time=7269.470..28043.022 rows=1148730 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=1128860 read=238274 dirtied=321 written=5 -> Hash Join (cost=277556.19..2172901.11 rows=569993 width=12) (actual time=5957.713..25885.701 rows=1148730 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1093582 read=238274 dirtied=321 written=5 -> Seq Scan on lineitem (cost=0.00..1833350.60 rows=15011836 width=12) (actual time=0.012..16431.919 rows=14822772 loops=1) Filter: (l_returnflag = 'R'::bpchar) Rows Removed by Filter: 45221404 Buffers: shared hit=887169 read=188875 -> Hash (cost=270365.73..270365.73 rows=575237 width=8) (actual time=5954.317..5954.317 rows=574192 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 30622kB Buffers: shared hit=206413 read=49399 dirtied=321 written=5 -> Bitmap Heap Scan on orders (cost=5936.18..270365.73 rows=575237 width=8) (actual time=27.771..5755.576 rows=574192 loops=1) Recheck Cond: ((o_orderdate >= '1993-05-01'::date) AND (o_orderdate < '1993-08-01'::date)) Rows Removed by Index Recheck: 14440808 Heap Blocks: lossy=255801 Buffers: shared hit=206413 read=49399 dirtied=321 written=5 -> Bitmap Index Scan on orders_o_orderkey_o_orderdate_brin_idx (cost=0.00..5792.37 rows=575237 width=0) (actual time=27.600..27.600 rows=2558720 loops=1) Index Cond: ((o_orderdate >= '1993-05-01'::date) AND (o_orderdate < '1993-08-01'::date)) Buffers: shared hit=5 read=6 -> Hash (cost=50278.00..50278.00 rows=1500000 width=146) (actual time=1305.564..1305.564 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..540.364 rows=1500000 loops=1) Buffers: shared hit=35278 -> 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: 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.812 ms Execution time: 30738.691 ms (45 rows) COMMIT; COMMIT