BEGIN; BEGIN create or replace view revenue3 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1995-12-01' and l_shipdate < date'1995-12-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, revenue3 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue3 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2377102.10..2382199.59 rows=3753 width=79) (actual time=16332.811..16332.813 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue3.supplier_no) Buffers: shared hit=676824 read=649984 written=67 InitPlan 1 (returns $0) -> Aggregate (cost=1179914.25..1179914.26 rows=1 width=8) (actual time=8680.380..8680.380 rows=1 loops=1) Buffers: shared hit=260205 read=402949 written=31 -> HashAggregate (cost=1179829.81..1179867.34 rows=3753 width=12) (actual time=8642.891..8670.533 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=260205 read=402949 written=31 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=48018.88..1157095.84 rows=2273397 width=12) (actual time=1061.327..6723.628 rows=2239957 loops=1) Recheck Cond: ((l_shipdate >= '1995-12-01'::date) AND (l_shipdate < '1996-02-29 00:00:00'::timestamp without time zone)) Heap Blocks: exact=657029 Buffers: shared hit=260205 read=402949 written=31 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47450.54 rows=2273397 width=0) (actual time=792.047..792.047 rows=2260348 loops=1) Index Cond: ((l_shipdate >= '1995-12-01'::date) AND (l_shipdate < '1996-02-29 00:00:00'::timestamp without time zone)) Buffers: shared read=6125 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.049..7.379 rows=17822 loops=1) Buffers: shared hit=500 -> Sort (cost=1197187.54..1197196.92 rows=3753 width=12) (actual time=16323.736..16323.737 rows=1 loops=1) Sort Key: revenue3.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=676324 read=649984 written=67 -> Subquery Scan on revenue3 (cost=1196880.29..1196964.73 rows=3753 width=12) (actual time=16315.537..16323.709 rows=1 loops=1) Buffers: shared hit=676324 read=649984 written=67 -> HashAggregate (cost=1196880.29..1196927.20 rows=3753 width=12) (actual time=16315.536..16323.706 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=676324 read=649984 written=67 -> Bitmap Heap Scan on lineitem (cost=48018.88..1157095.84 rows=2273397 width=12) (actual time=1019.781..6118.342 rows=2239957 loops=1) Recheck Cond: ((l_shipdate >= '1995-12-01'::date) AND (l_shipdate < '1996-02-29 00:00:00'::timestamp without time zone)) Heap Blocks: exact=657029 Buffers: shared hit=416119 read=247035 written=36 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47450.54 rows=2273397 width=0) (actual time=779.125..779.125 rows=2260348 loops=1) Index Cond: ((l_shipdate >= '1995-12-01'::date) AND (l_shipdate < '1996-02-29 00:00:00'::timestamp without time zone)) Buffers: shared read=6125 written=5 Planning time: 2.648 ms Execution time: 16342.844 ms (38 rows) drop view revenue3; DROP VIEW COMMIT; COMMIT