BEGIN; BEGIN create or replace view revenue1 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1996-07-01' and l_shipdate < date'1996-07-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, revenue1 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue1 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2364140.21..2369237.90 rows=3766 width=79) (actual time=14674.625..14674.629 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue1.supplier_no) Buffers: shared hit=806887 read=513518 InitPlan 1 (returns $0) -> Aggregate (cost=1173452.27..1173452.28 rows=1 width=8) (actual time=4869.501..4869.501 rows=1 loops=1) Buffers: shared hit=598062 read=61309 -> HashAggregate (cost=1173367.53..1173405.19 rows=3766 width=12) (actual time=4839.233..4860.186 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=598062 read=61309 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=48053.88..1150685.27 rows=2268226 width=12) (actual time=1111.526..3503.545 rows=2243700 loops=1) Recheck Cond: ((l_shipdate >= '1996-07-01'::date) AND (l_shipdate < '1996-09-29 00:00:00'::timestamp without time zone)) Heap Blocks: exact=653237 Buffers: shared hit=598062 read=61309 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47486.83 rows=2268226 width=0) (actual time=808.685..808.685 rows=2250224 loops=1) Index Cond: ((l_shipdate >= '1996-07-01'::date) AND (l_shipdate < '1996-09-29 00:00:00'::timestamp without time zone)) Buffers: shared hit=6134 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.058..26.964 rows=60982 loops=1) Buffers: shared hit=168 read=1495 -> Sort (cost=1190687.64..1190697.05 rows=3766 width=12) (actual time=14642.121..14642.123 rows=1 loops=1) Sort Key: revenue1.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=806719 read=512023 -> Subquery Scan on revenue1 (cost=1190379.23..1190463.96 rows=3766 width=12) (actual time=14623.686..14642.076 rows=1 loops=1) Buffers: shared hit=806719 read=512023 -> HashAggregate (cost=1190379.23..1190426.30 rows=3766 width=12) (actual time=14623.685..14642.073 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=806719 read=512023 -> Bitmap Heap Scan on lineitem (cost=48053.88..1150685.27 rows=2268226 width=12) (actual time=1316.571..7912.384 rows=2243700 loops=1) Recheck Cond: ((l_shipdate >= '1996-07-01'::date) AND (l_shipdate < '1996-09-29 00:00:00'::timestamp without time zone)) Heap Blocks: exact=653237 Buffers: shared hit=208657 read=450714 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47486.83 rows=2268226 width=0) (actual time=1006.655..1006.655 rows=2250224 loops=1) Index Cond: ((l_shipdate >= '1996-07-01'::date) AND (l_shipdate < '1996-09-29 00:00:00'::timestamp without time zone)) Buffers: shared read=6134 Planning time: 4.208 ms Execution time: 14682.901 ms (38 rows) drop view revenue1; DROP VIEW COMMIT; COMMIT