BEGIN; BEGIN create or replace view revenue21 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1996-11-01' and l_shipdate < date'1996-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, revenue21 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue21 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2361595.45..2366692.54 rows=3726 width=79) (actual time=17766.101..17766.106 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue21.supplier_no) Buffers: shared hit=782468 read=538951 written=6 InitPlan 1 (returns $0) -> Aggregate (cost=1172276.81..1172276.82 rows=1 width=8) (actual time=9066.165..9066.165 rows=1 loops=1) Buffers: shared hit=344731 read=315297 -> HashAggregate (cost=1172192.97..1172230.23 rows=3726 width=12) (actual time=9019.391..9055.459 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=344731 read=315297 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47516.60..1149765.62 rows=2242735 width=12) (actual time=1198.913..7063.406 rows=2246343 loops=1) Recheck Cond: ((l_shipdate >= '1996-11-01'::date) AND (l_shipdate < '1997-01-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=653890 Buffers: shared hit=344731 read=315297 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46955.92 rows=2242735 width=0) (actual time=927.403..927.403 rows=2250904 loops=1) Index Cond: ((l_shipdate >= '1996-11-01'::date) AND (l_shipdate < '1997-01-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6138 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.027..18.096 rows=49906 loops=1) Buffers: shared hit=1363 -> Sort (cost=1189318.34..1189327.65 rows=3726 width=12) (actual time=17743.012..17743.014 rows=1 loops=1) Sort Key: revenue21.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=781105 read=538951 written=6 -> Subquery Scan on revenue21 (cost=1189013.49..1189097.32 rows=3726 width=12) (actual time=17731.283..17742.983 rows=1 loops=1) Buffers: shared hit=781105 read=538951 written=6 -> HashAggregate (cost=1189013.49..1189060.06 rows=3726 width=12) (actual time=17731.282..17742.981 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=781105 read=538951 written=6 -> Bitmap Heap Scan on lineitem (cost=47516.60..1149765.62 rows=2242735 width=12) (actual time=1250.787..6769.262 rows=2246343 loops=1) Recheck Cond: ((l_shipdate >= '1996-11-01'::date) AND (l_shipdate < '1997-01-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=653890 Buffers: shared hit=436374 read=223654 written=6 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46955.92 rows=2242735 width=0) (actual time=982.773..982.773 rows=2250904 loops=1) Index Cond: ((l_shipdate >= '1996-11-01'::date) AND (l_shipdate < '1997-01-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6138 Planning time: 2.939 ms Execution time: 17775.119 ms (38 rows) drop view revenue21; DROP VIEW COMMIT; COMMIT