BEGIN; BEGIN create or replace view revenue21 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1997-05-01' and l_shipdate < date'1997-05-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, revenue21 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue21 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2365639.36..2370737.43 rows=3791 width=79) (actual time=21905.331..21905.336 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue21.supplier_no) Buffers: shared hit=652795 read=668889 written=10 InitPlan 1 (returns $0) -> Aggregate (cost=1174144.84..1174144.85 rows=1 width=8) (actual time=10421.765..10421.765 rows=1 loops=1) Buffers: shared hit=308611 read=351750 written=4 -> HashAggregate (cost=1174059.54..1174097.45 rows=3791 width=12) (actual time=10375.996..10410.901 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=308611 read=351750 written=4 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=48371.42..1151227.49 rows=2283205 width=12) (actual time=1909.708..8378.168 rows=2248039 loops=1) Recheck Cond: ((l_shipdate >= '1997-05-01'::date) AND (l_shipdate < '1997-07-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=654221 Buffers: shared hit=308611 read=351750 written=4 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47800.62 rows=2283205 width=0) (actual time=1480.104..1480.104 rows=2252515 loops=1) Index Cond: ((l_shipdate >= '1997-05-01'::date) AND (l_shipdate < '1997-07-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6140 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.048..14.567 rows=34927 loops=1) Buffers: shared hit=962 -> Sort (cost=1191494.22..1191503.70 rows=3791 width=12) (actual time=21887.244..21887.247 rows=1 loops=1) Sort Key: revenue21.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=651833 read=668889 written=10 -> Subquery Scan on revenue21 (cost=1191183.58..1191268.88 rows=3791 width=12) (actual time=21872.582..21887.212 rows=1 loops=1) Buffers: shared hit=651833 read=668889 written=10 -> HashAggregate (cost=1191183.58..1191230.97 rows=3791 width=12) (actual time=21872.580..21887.208 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=651833 read=668889 written=10 -> Bitmap Heap Scan on lineitem (cost=48371.42..1151227.49 rows=2283205 width=12) (actual time=1617.968..9097.520 rows=2248039 loops=1) Recheck Cond: ((l_shipdate >= '1997-05-01'::date) AND (l_shipdate < '1997-07-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=654221 Buffers: shared hit=343222 read=317139 written=6 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47800.62 rows=2283205 width=0) (actual time=1242.687..1242.687 rows=2252515 loops=1) Index Cond: ((l_shipdate >= '1997-05-01'::date) AND (l_shipdate < '1997-07-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6140 Planning time: 4.433 ms Execution time: 21912.827 ms (38 rows) drop view revenue21; DROP VIEW COMMIT; COMMIT