BEGIN; BEGIN create or replace view revenue14 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1995-11-01' and l_shipdate < date'1995-11-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, revenue14 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue14 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2379273.03..2384371.63 rows=3826 width=79) (actual time=17891.641..17891.647 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue14.supplier_no) Buffers: shared hit=881398 read=446179 written=561 InitPlan 1 (returns $0) -> Aggregate (cost=1180838.12..1180838.13 rows=1 width=8) (actual time=8614.055..8614.055 rows=1 loops=1) Buffers: shared hit=379285 read=283376 written=261 -> HashAggregate (cost=1180752.03..1180790.29 rows=3826 width=12) (actual time=8571.027..8603.566 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=379285 read=283376 written=261 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=48937.96..1157593.60 rows=2315843 width=12) (actual time=1202.393..6787.619 rows=2243536 loops=1) Recheck Cond: ((l_shipdate >= '1995-11-01'::date) AND (l_shipdate < '1996-01-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=656533 Buffers: shared hit=379285 read=283376 written=261 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..48359.00 rows=2315843 width=0) (actual time=917.763..917.763 rows=2259357 loops=1) Index Cond: ((l_shipdate >= '1995-11-01'::date) AND (l_shipdate < '1996-01-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6128 written=1 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.032..34.112 rows=82975 loops=1) Buffers: shared hit=2255 -> Sort (cost=1198434.62..1198444.18 rows=3826 width=12) (actual time=17849.354..17849.356 rows=1 loops=1) Sort Key: revenue14.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=879143 read=446179 written=561 -> Subquery Scan on revenue14 (cost=1198120.85..1198206.94 rows=3826 width=12) (actual time=17841.016..17849.322 rows=1 loops=1) Buffers: shared hit=879143 read=446179 written=561 -> HashAggregate (cost=1198120.85..1198168.68 rows=3826 width=12) (actual time=17841.014..17849.317 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=879143 read=446179 written=561 -> Bitmap Heap Scan on lineitem (cost=48937.96..1157593.60 rows=2315843 width=12) (actual time=1291.241..6944.631 rows=2243536 loops=1) Recheck Cond: ((l_shipdate >= '1995-11-01'::date) AND (l_shipdate < '1996-01-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=656533 Buffers: shared hit=499858 read=162803 written=300 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..48359.00 rows=2315843 width=0) (actual time=985.005..985.005 rows=2259357 loops=1) Index Cond: ((l_shipdate >= '1995-11-01'::date) AND (l_shipdate < '1996-01-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6128 written=9 Planning time: 3.305 ms Execution time: 17908.317 ms (38 rows) drop view revenue14; DROP VIEW COMMIT; COMMIT