BEGIN; BEGIN create or replace view revenue16 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1994-09-01' and l_shipdate < date'1994-09-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, revenue16 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue16 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2376364.87..2381462.41 rows=3756 width=79) (actual time=21454.839..21454.843 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue16.supplier_no) Buffers: shared hit=734869 read=594135 dirtied=728 written=5119 InitPlan 1 (returns $0) -> Aggregate (cost=1179550.71..1179550.72 rows=1 width=8) (actual time=9981.190..9981.190 rows=1 loops=1) Buffers: shared hit=370651 read=293196 written=555 -> HashAggregate (cost=1179466.20..1179503.76 rows=3756 width=12) (actual time=9890.323..9970.729 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=370651 read=293196 written=555 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47996.75..1156746.02 rows=2272018 width=12) (actual time=1254.774..7436.401 rows=2242395 loops=1) Recheck Cond: ((l_shipdate >= '1994-09-01'::date) AND (l_shipdate < '1994-11-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=657715 Buffers: shared hit=370651 read=293196 written=555 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47428.75 rows=2272018 width=0) (actual time=953.812..953.812 rows=2263072 loops=1) Index Cond: ((l_shipdate >= '1994-09-01'::date) AND (l_shipdate < '1994-11-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6132 written=15 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.031..19.655 rows=47970 loops=1) Buffers: shared hit=1310 -> Sort (cost=1196813.86..1196823.25 rows=3756 width=12) (actual time=21430.459..21430.461 rows=1 loops=1) Sort Key: revenue16.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=733559 read=594135 dirtied=728 written=5119 -> Subquery Scan on revenue16 (cost=1196506.33..1196590.84 rows=3756 width=12) (actual time=21427.279..21430.414 rows=1 loops=1) Buffers: shared hit=733559 read=594135 dirtied=728 written=5119 -> HashAggregate (cost=1196506.33..1196553.28 rows=3756 width=12) (actual time=21427.277..21430.410 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=733559 read=594135 dirtied=728 written=5119 -> Bitmap Heap Scan on lineitem (cost=47996.75..1156746.02 rows=2272018 width=12) (actual time=1333.989..8308.034 rows=2242395 loops=1) Recheck Cond: ((l_shipdate >= '1994-09-01'::date) AND (l_shipdate < '1994-11-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=657715 Buffers: shared hit=362908 read=300939 dirtied=728 written=4564 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47428.75 rows=2272018 width=0) (actual time=996.391..996.391 rows=2262665 loops=1) Index Cond: ((l_shipdate >= '1994-09-01'::date) AND (l_shipdate < '1994-11-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=580 read=5552 written=456 Planning time: 3.188 ms Execution time: 21473.596 ms (38 rows) drop view revenue16; DROP VIEW COMMIT; COMMIT