BEGIN; BEGIN create or replace view revenue22 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1994-08-01' and l_shipdate < date'1994-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, revenue22 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue22 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2378876.39..2383973.79 rows=3746 width=79) (actual time=21771.712..21771.718 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue22.supplier_no) Buffers: shared hit=677449 read=652680 dirtied=237 written=9258 InitPlan 1 (returns $0) -> Aggregate (cost=1180813.41..1180813.42 rows=1 width=8) (actual time=10458.422..10458.422 rows=1 loops=1) Buffers: shared hit=304335 read=360075 written=443 -> HashAggregate (cost=1180729.12..1180766.58 rows=3746 width=12) (actual time=10414.418..10447.661 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=304335 read=360075 written=443 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47926.70..1158026.55 rows=2270257 width=12) (actual time=1297.672..8514.860 rows=2245331 loops=1) Recheck Cond: ((l_shipdate >= '1994-08-01'::date) AND (l_shipdate < '1994-10-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=658270 Buffers: shared hit=304335 read=360075 written=443 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47359.14 rows=2270257 width=0) (actual time=989.706..989.706 rows=2270203 loops=1) Index Cond: ((l_shipdate >= '1994-08-01'::date) AND (l_shipdate < '1994-10-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6140 written=26 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.027..20.743 rows=47970 loops=1) Buffers: shared hit=1310 -> Sort (cost=1198062.68..1198072.05 rows=3746 width=12) (actual time=21746.017..21746.019 rows=1 loops=1) Sort Key: revenue22.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=676139 read=652680 dirtied=237 written=9258 -> Subquery Scan on revenue22 (cost=1197756.05..1197840.34 rows=3746 width=12) (actual time=21742.877..21745.983 rows=1 loops=1) Buffers: shared hit=676139 read=652680 dirtied=237 written=9258 -> HashAggregate (cost=1197756.05..1197802.88 rows=3746 width=12) (actual time=21742.875..21745.980 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=676139 read=652680 dirtied=237 written=9258 -> Bitmap Heap Scan on lineitem (cost=47926.70..1158026.55 rows=2270257 width=12) (actual time=1511.548..8912.118 rows=2245331 loops=1) Recheck Cond: ((l_shipdate >= '1994-08-01'::date) AND (l_shipdate < '1994-10-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=658269 Buffers: shared hit=371804 read=292605 dirtied=237 written=8815 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47359.14 rows=2270257 width=0) (actual time=1181.910..1181.910 rows=2268107 loops=1) Index Cond: ((l_shipdate >= '1994-08-01'::date) AND (l_shipdate < '1994-10-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6140 written=33 Planning time: 3.013 ms Execution time: 21791.904 ms (38 rows) drop view revenue22; DROP VIEW COMMIT; COMMIT