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-11-01' and o_orderdate < cast(date '1993-11-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=1191295.05..1191295.10 rows=20 width=176) (actual time=42151.018..42151.028 rows=20 loops=1) Buffers: shared hit=522372 read=911661 dirtied=1067 written=20672 -> Sort (cost=1191295.05..1192717.45 rows=568959 width=176) (actual time=42151.014..42151.018 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=522372 read=911661 dirtied=1067 written=20672 -> HashAggregate (cost=1170465.67..1176155.26 rows=568959 width=176) (actual time=41574.810..41970.424 rows=381299 loops=1) Buffers: shared hit=522369 read=911661 dirtied=1067 written=20672 -> Hash Join (cost=400544.33..1156241.69 rows=568959 width=176) (actual time=6352.897..37650.217 rows=1147119 loops=1) Hash Cond: (customer.c_nationkey = nation.n_nationkey) Buffers: shared hit=522369 read=911661 dirtied=1067 written=20672 -> Hash Join (cost=400542.77..1148416.94 rows=568959 width=154) (actual time=6352.859..36909.423 rows=1147119 loops=1) Hash Cond: (orders.o_custkey = customer.c_custkey) Buffers: shared hit=522368 read=911661 dirtied=1067 written=20672 -> Merge Join (cost=331514.77..1068009.76 rows=568959 width=12) (actual time=3075.196..30995.705 rows=1147119 loops=1) Merge Cond: (orders.o_orderkey = lineitem.l_orderkey) Buffers: shared hit=522366 read=876385 dirtied=1067 written=17174 -> Sort (cost=331514.75..332954.49 rows=575898 width=8) (actual time=3074.935..3273.582 rows=573610 loops=1) Sort Key: orders.o_orderkey Sort Method: quicksort Memory: 51464kB Buffers: shared hit=229633 read=1980 written=208 -> Bitmap Heap Scan on orders (cost=12480.93..276414.40 rows=575898 width=8) (actual time=469.508..2740.395 rows=573610 loops=1) Recheck Cond: ((o_orderdate >= '1993-11-01'::date) AND (o_orderdate < '1994-02-01'::date)) Buffers: shared hit=229633 read=1980 written=208 -> Bitmap Index Scan on orders_o_orderdate_o_orderkey_idx (cost=0.00..12336.96 rows=575898 width=0) (actual time=374.346..374.346 rows=578724 loops=1) Index Cond: ((o_orderdate >= '1993-11-01'::date) AND (o_orderdate < '1994-02-01'::date)) Buffers: shared hit=107 read=1551 written=136 -> Index Scan using lineitem_l_orderkey_idx_l_returnflag on lineitem (cost=0.00..690581.44 rows=14937802 width=12) (actual time=0.211..24310.916 rows=14808205 loops=1) Buffers: shared hit=292733 read=874405 dirtied=1067 written=16966 -> Hash (cost=50278.00..50278.00 rows=1500000 width=146) (actual time=3276.099..3276.099 rows=1500000 loops=1) Buckets: 262144 Batches: 1 Memory Usage: 265117kB Buffers: shared hit=2 read=35276 written=3498 -> Seq Scan on customer (cost=0.00..50278.00 rows=1500000 width=146) (actual time=0.013..1610.269 rows=1500000 loops=1) Buffers: shared hit=2 read=35276 written=3498 -> 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: 2kB Buffers: shared hit=1 -> Seq Scan on nation (cost=0.00..1.25 rows=25 width=30) (actual time=0.005..0.009 rows=25 loops=1) Buffers: shared hit=1 Total runtime: 42222.593 ms (40 rows) COMMIT; COMMIT