BEGIN; BEGIN create or replace view revenue20 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1994-10-01' and l_shipdate < date'1994-10-01' + interval '90 days' group by l_suppkey; CREATE VIEW EXPLAIN (ANALYZE, BUFFERS) select s_suppkey, s_name, s_address, s_phone, total_revenue from supplier, revenue20 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue20 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2358014.78..2363111.76 rows=3719 width=79) (actual time=17797.612..17797.617 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue20.supplier_no) Buffers: shared hit=1055312 read=263570 written=1193 InitPlan 1 (returns $0) -> Aggregate (cost=1170511.51..1170511.52 rows=1 width=8) (actual time=9670.380..9670.381 rows=1 loops=1) Buffers: shared hit=467455 read=191789 written=42 -> HashAggregate (cost=1170427.83..1170465.02 rows=3719 width=12) (actual time=9588.980..9659.700 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=467455 read=191789 written=42 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47408.81..1148066.62 rows=2236121 width=12) (actual time=1642.937..6534.311 rows=2241622 loops=1) Recheck Cond: ((l_shipdate >= '1994-10-01'::date) AND (l_shipdate < '1994-12-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=653115 Buffers: shared hit=467455 read=191789 written=42 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46849.78 rows=2236121 width=0) (actual time=1293.397..1293.397 rows=2246046 loops=1) Index Cond: ((l_shipdate >= '1994-10-01'::date) AND (l_shipdate < '1994-12-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6129 written=2 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.034..5.150 rows=13954 loops=1) Buffers: shared hit=394 -> Sort (cost=1187502.96..1187512.26 rows=3719 width=12) (actual time=17791.072..17791.074 rows=1 loops=1) Sort Key: revenue20.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=1054918 read=263570 written=1193 -> Subquery Scan on revenue20 (cost=1187198.74..1187282.42 rows=3719 width=12) (actual time=17770.694..17791.042 rows=1 loops=1) Buffers: shared hit=1054918 read=263570 written=1193 -> HashAggregate (cost=1187198.74..1187245.23 rows=3719 width=12) (actual time=17770.693..17791.040 rows=1 loops=1) Group Key: lineitem.l_suppkey Filter: (sum((lineitem.l_extendedprice * (1::double precision - lineitem.l_discount))) = $0) Rows Removed by Filter: 99999 Buffers: shared hit=1054918 read=263570 written=1193 -> Bitmap Heap Scan on lineitem (cost=47408.81..1148066.62 rows=2236121 width=12) (actual time=1519.361..6123.286 rows=2241622 loops=1) Recheck Cond: ((l_shipdate >= '1994-10-01'::date) AND (l_shipdate < '1994-12-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=653115 Buffers: shared hit=587463 read=71781 written=1151 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46849.78 rows=2236121 width=0) (actual time=1134.784..1134.784 rows=2245180 loops=1) Index Cond: ((l_shipdate >= '1994-10-01'::date) AND (l_shipdate < '1994-12-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=288 read=5841 written=177 Planning time: 2.613 ms Execution time: 17805.682 ms (38 rows) drop view revenue20; DROP VIEW COMMIT; COMMIT