BEGIN; BEGIN create or replace view revenue2 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1993-05-01' and l_shipdate < date'1993-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, revenue2 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue2 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2368204.38..2373301.95 rows=3758 width=79) (actual time=17187.137..17187.142 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue2.supplier_no) Buffers: shared hit=667831 read=657848 dirtied=1182 written=262 InitPlan 1 (returns $0) -> Aggregate (cost=1175488.41..1175488.42 rows=1 width=8) (actual time=8281.393..8281.393 rows=1 loops=1) Buffers: shared hit=357554 read=304145 dirtied=565 written=34 -> HashAggregate (cost=1175403.86..1175441.44 rows=3758 width=12) (actual time=8243.121..8271.165 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=357554 read=304145 dirtied=565 written=34 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47983.51..1152731.72 rows=2267214 width=12) (actual time=1909.691..6560.386 rows=2248978 loops=1) Recheck Cond: ((l_shipdate >= '1993-05-01'::date) AND (l_shipdate < '1993-07-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=655558 Buffers: shared hit=357554 read=304145 dirtied=565 written=34 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47416.71 rows=2267214 width=0) (actual time=1628.907..1628.907 rows=2257722 loops=1) Index Cond: ((l_shipdate >= '1993-05-01'::date) AND (l_shipdate < '1993-07-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6141 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.061..32.045 rows=83935 loops=1) Buffers: shared hit=2281 -> Sort (cost=1192715.66..1192725.06 rows=3758 width=12) (actual time=17147.175..17147.177 rows=1 loops=1) Sort Key: revenue2.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=665550 read=657848 dirtied=1182 written=262 -> Subquery Scan on revenue2 (cost=1192407.96..1192492.52 rows=3758 width=12) (actual time=17145.000..17147.147 rows=1 loops=1) Buffers: shared hit=665550 read=657848 dirtied=1182 written=262 -> HashAggregate (cost=1192407.96..1192454.94 rows=3758 width=12) (actual time=17144.999..17147.146 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=665550 read=657848 dirtied=1182 written=262 -> Bitmap Heap Scan on lineitem (cost=47983.51..1152731.72 rows=2267214 width=12) (actual time=1186.022..7086.301 rows=2248978 loops=1) Recheck Cond: ((l_shipdate >= '1993-05-01'::date) AND (l_shipdate < '1993-07-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=655558 Buffers: shared hit=307996 read=353703 dirtied=617 written=228 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47416.71 rows=2267214 width=0) (actual time=899.760..899.760 rows=2257722 loops=1) Index Cond: ((l_shipdate >= '1993-05-01'::date) AND (l_shipdate < '1993-07-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6141 Planning time: 2.239 ms Execution time: 17205.094 ms (38 rows) drop view revenue2; DROP VIEW COMMIT; COMMIT