BEGIN; BEGIN create or replace view revenue15 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1993-08-01' and l_shipdate < date'1993-08-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, revenue15 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue15 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2374069.72..2379167.31 rows=3759 width=79) (actual time=20233.557..20233.563 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue15.supplier_no) Buffers: shared hit=778903 read=549444 written=10912 InitPlan 1 (returns $0) -> Aggregate (cost=1178391.09..1178391.10 rows=1 width=8) (actual time=8776.328..8776.328 rows=1 loops=1) Buffers: shared hit=392948 read=269867 written=529 -> HashAggregate (cost=1178306.51..1178344.10 rows=3759 width=12) (actual time=8733.795..8766.033 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=392948 read=269867 written=529 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=48069.49..1155566.10 rows=2274041 width=12) (actual time=1235.419..6917.716 rows=2246514 loops=1) Recheck Cond: ((l_shipdate >= '1993-08-01'::date) AND (l_shipdate < '1993-10-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=656674 Buffers: shared hit=392948 read=269867 written=529 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47500.98 rows=2274041 width=0) (actual time=928.890..928.890 rows=2264198 loops=1) Index Cond: ((l_shipdate >= '1993-08-01'::date) AND (l_shipdate < '1993-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=1 read=6140 written=10 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.032..39.673 rows=99925 loops=1) Buffers: shared hit=2717 -> Sort (cost=1195678.33..1195687.73 rows=3759 width=12) (actual time=20183.898..20183.901 rows=1 loops=1) Sort Key: revenue15.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=776186 read=549444 written=10912 -> Subquery Scan on revenue15 (cost=1195370.54..1195455.12 rows=3759 width=12) (actual time=20171.438..20183.861 rows=1 loops=1) Buffers: shared hit=776186 read=549444 written=10912 -> HashAggregate (cost=1195370.54..1195417.53 rows=3759 width=12) (actual time=20171.436..20183.856 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=776186 read=549444 written=10912 -> Bitmap Heap Scan on lineitem (cost=48069.66..1155574.53 rows=2274058 width=12) (actual time=1713.149..8626.721 rows=2246514 loops=1) Recheck Cond: ((l_shipdate >= '1993-08-01'::date) AND (l_shipdate < '1993-10-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=656674 Buffers: shared hit=383238 read=279577 written=10383 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47501.15 rows=2274058 width=0) (actual time=1334.016..1334.016 rows=2263412 loops=1) Index Cond: ((l_shipdate >= '1993-08-01'::date) AND (l_shipdate < '1993-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=838 read=5303 written=648 Planning time: 3.135 ms Execution time: 20245.074 ms (38 rows) drop view revenue15; DROP VIEW COMMIT; COMMIT