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 >= '1997-06-01' and l_shipdate < date'1997-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=2357326.06..2362423.61 rows=3739 width=79) (actual time=29074.466..29074.469 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue11.supplier_no) Buffers: shared hit=557422 read=761730 written=33351 InitPlan 1 (returns $0) -> Aggregate (cost=1170146.11..1170146.12 rows=1 width=8) (actual time=10278.970..10278.970 rows=1 loops=1) Buffers: shared hit=541772 read=117214 written=6938 -> HashAggregate (cost=1170061.98..1170099.37 rows=3739 width=12) (actual time=10214.874..10268.025 rows=100000 loops=1) Buffers: shared hit=541772 read=117214 written=6938 -> Bitmap Heap Scan on lineitem (cost=47547.16..1147646.05 rows=2241593 width=12) (actual time=1701.508..6925.789 rows=2243815 loops=1) Recheck Cond: ((l_shipdate >= '1997-06-01'::date) AND (l_shipdate < '1997-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=541772 read=117214 written=6938 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46986.76 rows=2241593 width=0) (actual time=1371.876..1371.876 rows=2248378 loops=1) Index Cond: ((l_shipdate >= '1997-06-01'::date) AND (l_shipdate < '1997-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=842 read=5292 written=239 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.021..16.206 rows=42993 loops=1) Buffers: shared hit=1179 -> Sort (cost=1187179.94..1187189.29 rows=3739 width=12) (actual time=29053.758..29053.758 rows=1 loops=1) Sort Key: revenue11.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=556243 read=761730 written=33351 -> Subquery Scan on revenue11 (cost=1186873.93..1186958.06 rows=3739 width=12) (actual time=29041.517..29053.728 rows=1 loops=1) Buffers: shared hit=556243 read=761730 written=33351 -> HashAggregate (cost=1186873.93..1186920.67 rows=3739 width=12) (actual time=29041.515..29053.724 rows=1 loops=1) Filter: (sum((public.lineitem.l_extendedprice * (1::double precision - public.lineitem.l_discount))) = $0) Rows Removed by Filter: 99999 Buffers: shared hit=556243 read=761730 written=33351 -> Bitmap Heap Scan on lineitem (cost=47547.16..1147646.05 rows=2241593 width=12) (actual time=2235.456..15180.566 rows=2243815 loops=1) Recheck Cond: ((l_shipdate >= '1997-06-01'::date) AND (l_shipdate < '1997-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=14471 read=644516 written=26413 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46986.76 rows=2241593 width=0) (actual time=1876.592..1876.592 rows=2246034 loops=1) Index Cond: ((l_shipdate >= '1997-06-01'::date) AND (l_shipdate < '1997-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=3 read=6132 Total runtime: 29085.064 ms (33 rows) drop view revenue11; DROP VIEW COMMIT; COMMIT