BEGIN; BEGIN create or replace view revenue9 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1996-02-01' and l_shipdate < date'1996-02-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, revenue9 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue9 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2372554.10..2377651.65 rows=3757 width=79) (actual time=21081.889..21081.894 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue9.supplier_no) Buffers: shared hit=589081 read=736804 written=13374 InitPlan 1 (returns $0) -> Aggregate (cost=1177655.33..1177655.34 rows=1 width=8) (actual time=10067.861..10067.861 rows=1 loops=1) Buffers: shared hit=300566 read=361531 written=13266 -> HashAggregate (cost=1177570.80..1177608.37 rows=3757 width=12) (actual time=10025.685..10057.496 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=300566 read=361531 written=13266 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47981.30..1154877.40 rows=2269340 width=12) (actual time=1657.397..8154.210 rows=2243551 loops=1) Recheck Cond: ((l_shipdate >= '1996-02-01'::date) AND (l_shipdate < '1996-05-01 00:00:00'::timestamp without time zone)) Heap Blocks: exact=655970 Buffers: shared hit=300566 read=361531 written=13266 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47413.97 rows=2269340 width=0) (actual time=1342.259..1342.259 rows=2256677 loops=1) Index Cond: ((l_shipdate >= '1996-02-01'::date) AND (l_shipdate < '1996-05-01 00:00:00'::timestamp without time zone)) Buffers: shared read=6127 written=5 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.035..24.339 rows=61971 loops=1) Buffers: shared hit=1691 -> Sort (cost=1194898.46..1194907.85 rows=3757 width=12) (actual time=21051.264..21051.266 rows=1 loops=1) Sort Key: revenue9.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=587390 read=736804 written=13374 -> Subquery Scan on revenue9 (cost=1194590.85..1194675.38 rows=3757 width=12) (actual time=21038.081..21051.235 rows=1 loops=1) Buffers: shared hit=587390 read=736804 written=13374 -> HashAggregate (cost=1194590.85..1194637.81 rows=3757 width=12) (actual time=21038.080..21051.234 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=587390 read=736804 written=13374 -> Bitmap Heap Scan on lineitem (cost=47981.30..1154877.40 rows=2269340 width=12) (actual time=1676.322..9030.299 rows=2243551 loops=1) Recheck Cond: ((l_shipdate >= '1996-02-01'::date) AND (l_shipdate < '1996-05-01 00:00:00'::timestamp without time zone)) Heap Blocks: exact=655970 Buffers: shared hit=286824 read=375273 written=108 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47413.97 rows=2269340 width=0) (actual time=1311.118..1311.118 rows=2256677 loops=1) Index Cond: ((l_shipdate >= '1996-02-01'::date) AND (l_shipdate < '1996-05-01 00:00:00'::timestamp without time zone)) Buffers: shared read=6127 written=2 Planning time: 2.867 ms Execution time: 21097.526 ms (38 rows) drop view revenue9; DROP VIEW COMMIT; COMMIT