BEGIN; BEGIN create or replace view revenue7 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1993-06-01' and l_shipdate < date'1993-06-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, revenue7 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue7 ) order by s_suppkey; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=4044568.10..4049665.67 rows=3758 width=79) (actual time=40823.953..40823.957 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue7.supplier_no) Buffers: shared hit=991559 read=1167970 InitPlan 1 (returns $0) -> Aggregate (cost=2013624.02..2013624.03 rows=1 width=8) (actual time=20005.939..20005.939 rows=1 loops=1) Buffers: shared hit=305681 read=773579 -> HashAggregate (cost=2013539.47..2013577.05 rows=3758 width=12) (actual time=19964.073..19994.990 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=305681 read=773579 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1990743.98 rows=2279548 width=12) (actual time=0.015..18087.344 rows=2246070 loops=1) Filter: ((l_shipdate >= '1993-06-01'::date) AND (l_shipdate < '1993-08-30 00:00:00'::timestamp without time zone)) Rows Removed by Filter: 57739468 Buffers: shared hit=305681 read=773579 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.033..11.824 rows=36837 loops=1) Buffers: shared hit=1009 -> Sort (cost=2030943.78..2030953.17 rows=3758 width=12) (actual time=40808.592..40808.593 rows=1 loops=1) Sort Key: revenue7.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=990550 read=1167970 -> Subquery Scan on revenue7 (cost=2030636.07..2030720.63 rows=3758 width=12) (actual time=40782.789..40808.570 rows=1 loops=1) Buffers: shared hit=990550 read=1167970 -> HashAggregate (cost=2030636.07..2030683.05 rows=3758 width=12) (actual time=40782.788..40808.568 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=990550 read=1167970 -> Seq Scan on lineitem (cost=0.00..1990743.98 rows=2279548 width=12) (actual time=0.019..18560.495 rows=2246070 loops=1) Filter: ((l_shipdate >= '1993-06-01'::date) AND (l_shipdate < '1993-08-30 00:00:00'::timestamp without time zone)) Rows Removed by Filter: 57739468 Buffers: shared hit=684869 read=394391 Planning time: 2.466 ms Execution time: 40826.411 ms (32 rows) drop view revenue7; DROP VIEW COMMIT; COMMIT