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-01-01' and o_orderdate < cast(date '1994-01-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=1149795.36..1149795.41 rows=20 width=175) (actual time=23436.574..23436.580 rows=20 loops=1) Buffers: shared hit=1360376 read=56839 written=123 -> Sort (cost=1149795.36..1151188.06 rows=557077 width=175) (actual time=23436.570..23436.575 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=1360376 read=56839 written=123 -> HashAggregate (cost=1129400.97..1134971.74 rows=557077 width=175) (actual time=22932.378..23286.820 rows=374874 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=1360373 read=56839 written=123 -> Hash Join (cost=350490.74..1115474.05 rows=557077 width=175) (actual time=3673.469..20386.286 rows=1120579 loops=1) Hash Cond: (customer.c_nationkey = nation.n_nationkey) Buffers: shared hit=1360373 read=56839 written=123 -> Hash Join (cost=350489.18..1107812.68 rows=557077 width=153) (actual time=3673.432..20000.431 rows=1120579 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=1360372 read=56839 written=123 -> Hash Join (cost=281461.18..1030428.52 rows=557077 width=12) (actual time=2026.158..17437.503 rows=1120579 loops=1) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) Buffers: shared hit=1325094 read=56839 written=123 -> Index Scan using lineitem_l_orderkey_idx_l_returnflag on lineitem (cost=0.43..687611.55 rows=14876121 width=12) (actual time=0.030..11067.387 rows=14808453 loops=1) Buffers: shared hit=1103367 read=49651 written=21 -> Hash (cost=274418.26..274418.26 rows=563399 width=8) (actual time=2019.217..2019.217 rows=560126 loops=1) Buckets: 1048576 Batches: 1 Memory Usage: 30072kB Buffers: shared hit=221727 read=7188 written=102 -> Bitmap Heap Scan on orders (cost=11939.27..274418.26 rows=563399 width=8) (actual time=312.250..1806.526 rows=560126 loops=1) Recheck Cond: ((o_orderdate >= '1994-01-01'::date) AND (o_orderdate < '1994-04-01'::date)) Heap Blocks: exact=227382 Buffers: shared hit=221727 read=7188 written=102 -> Bitmap Index Scan on orders_o_orderdate_o_orderkey_idx (cost=0.00..11798.42 rows=563399 width=0) (actual time=222.023..222.023 rows=562377 loops=1) Index Cond: ((o_orderdate >= '1994-01-01'::date) AND (o_orderdate < '1994-04-01'::date)) Buffers: shared hit=591 read=942 written=82 -> Hash (cost=50278.00..50278.00 rows=1500000 width=145) (actual time=1634.153..1634.153 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.016..680.171 rows=1500000 loops=1) Buffers: shared hit=35278 -> Hash (cost=1.25..1.25 rows=25 width=30) (actual time=0.024..0.024 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.011 rows=25 loops=1) Buffers: shared hit=1 Planning time: 4.317 ms Execution time: 23466.078 ms (42 rows) COMMIT; COMMIT