BEGIN; BEGIN create or replace view revenue8 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1996-04-01' and l_shipdate < date'1996-04-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, revenue8 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue8 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2363957.25..2369055.01 rows=3771 width=79) (actual time=19910.959..19910.964 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue8.supplier_no) Buffers: shared hit=715240 read=604929 dirtied=488 written=68 InitPlan 1 (returns $0) -> Aggregate (cost=1173367.52..1173367.53 rows=1 width=8) (actual time=8803.129..8803.129 rows=1 loops=1) Buffers: shared hit=383854 read=275670 dirtied=488 written=7 -> HashAggregate (cost=1173282.67..1173320.38 rows=3771 width=12) (actual time=8762.640..8792.951 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=383854 read=275670 dirtied=488 written=7 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=48015.02..1150618.81 rows=2266386 width=12) (actual time=1204.586..6977.973 rows=2246466 loops=1) Recheck Cond: ((l_shipdate >= '1996-04-01'::date) AND (l_shipdate < '1996-06-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=653389 Buffers: shared hit=383854 read=275670 dirtied=488 written=7 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47448.43 rows=2266386 width=0) (actual time=907.585..907.585 rows=2250787 loops=1) Index Cond: ((l_shipdate >= '1996-04-01'::date) AND (l_shipdate < '1996-06-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6135 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.048..16.448 rows=40980 loops=1) Buffers: shared hit=1121 -> Sort (cost=1190589.43..1190598.85 rows=3771 width=12) (actual time=19890.530..19890.532 rows=1 loops=1) Sort Key: revenue8.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=714119 read=604929 dirtied=488 written=68 -> Subquery Scan on revenue8 (cost=1190280.57..1190365.41 rows=3771 width=12) (actual time=19885.282..19890.492 rows=1 loops=1) Buffers: shared hit=714119 read=604929 dirtied=488 written=68 -> HashAggregate (cost=1190280.57..1190327.70 rows=3771 width=12) (actual time=19885.280..19890.487 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=714119 read=604929 dirtied=488 written=68 -> Bitmap Heap Scan on lineitem (cost=48015.02..1150618.81 rows=2266386 width=12) (actual time=1906.944..9056.876 rows=2246466 loops=1) Recheck Cond: ((l_shipdate >= '1996-04-01'::date) AND (l_shipdate < '1996-06-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=653389 Buffers: shared hit=330265 read=329259 written=61 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47448.43 rows=2266386 width=0) (actual time=1503.769..1503.769 rows=2250787 loops=1) Index Cond: ((l_shipdate >= '1996-04-01'::date) AND (l_shipdate < '1996-06-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6135 Planning time: 2.599 ms Execution time: 19928.366 ms (38 rows) drop view revenue8; DROP VIEW COMMIT; COMMIT