BEGIN; BEGIN create or replace view revenue11 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1995-06-01' and l_shipdate < date'1995-06-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, revenue11 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue11 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2359803.50..2364901.30 rows=3773 width=79) (actual time=20385.148..20385.153 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue11.supplier_no) Buffers: shared hit=863774 read=455390 written=11013 InitPlan 1 (returns $0) -> Aggregate (cost=1171290.19..1171290.20 rows=1 width=8) (actual time=7584.993..7584.993 rows=1 loops=1) Buffers: shared hit=475293 read=183328 written=6327 -> HashAggregate (cost=1171205.30..1171243.03 rows=3773 width=12) (actual time=7541.849..7574.785 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=475293 read=183328 written=6327 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=48068.08..1148540.41 rows=2266489 width=12) (actual time=1162.242..5688.552 rows=2244170 loops=1) Recheck Cond: ((l_shipdate >= '1995-06-01'::date) AND (l_shipdate < '1995-08-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=652486 Buffers: shared hit=475293 read=183328 written=6327 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47501.46 rows=2266489 width=0) (actual time=903.208..903.208 rows=2248025 loops=1) Index Cond: ((l_shipdate >= '1995-06-01'::date) AND (l_shipdate < '1995-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=375 read=5760 written=246 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.023..26.144 rows=70652 loops=1) Buffers: shared hit=1922 -> Sort (cost=1188513.01..1188522.44 rows=3773 width=12) (actual time=20351.892..20351.894 rows=1 loops=1) Sort Key: revenue11.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=861852 read=455390 written=11013 -> Subquery Scan on revenue11 (cost=1188203.97..1188288.86 rows=3773 width=12) (actual time=20300.798..20351.859 rows=1 loops=1) Buffers: shared hit=861852 read=455390 written=11013 -> HashAggregate (cost=1188203.97..1188251.13 rows=3773 width=12) (actual time=20300.797..20351.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=861852 read=455390 written=11013 -> Bitmap Heap Scan on lineitem (cost=48068.08..1148540.41 rows=2266489 width=12) (actual time=2163.231..10088.591 rows=2244170 loops=1) Recheck Cond: ((l_shipdate >= '1995-06-01'::date) AND (l_shipdate < '1995-08-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=652486 Buffers: shared hit=386559 read=272062 written=4686 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47501.46 rows=2266489 width=0) (actual time=1714.161..1714.161 rows=2246437 loops=1) Index Cond: ((l_shipdate >= '1995-06-01'::date) AND (l_shipdate < '1995-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=2 read=6133 Planning time: 1.963 ms Execution time: 20394.217 ms (38 rows) drop view revenue11; DROP VIEW COMMIT; COMMIT