BEGIN; BEGIN create or replace view revenue13 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1996-01-01' and l_shipdate < date'1996-01-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, revenue13 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue13 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2393591.80..2398690.28 rows=3801 width=79) (actual time=62166.135..62166.140 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue13.supplier_no) Buffers: shared hit=654706 read=682226 InitPlan 1 (returns $0) -> Aggregate (cost=1188008.61..1188008.62 rows=1 width=8) (actual time=24969.757..24969.757 rows=1 loops=1) Buffers: shared hit=314361 read=353151 -> HashAggregate (cost=1187923.08..1187961.09 rows=3801 width=12) (actual time=24872.493..24952.179 rows=100000 loops=1) Buffers: shared hit=314361 read=353151 -> Bitmap Heap Scan on lineitem (cost=48712.53..1164791.66 rows=2313142 width=12) (actual time=2701.912..20229.751 rows=2242974 loops=1) Recheck Cond: ((l_shipdate >= '1996-01-01'::date) AND (l_shipdate < '1996-03-31 00:00:00'::timestamp without time zone)) Buffers: shared hit=314361 read=353151 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..48134.25 rows=2313142 width=0) (actual time=2299.121..2299.121 rows=2274813 loops=1) Index Cond: ((l_shipdate >= '1996-01-01'::date) AND (l_shipdate < '1996-03-31 00:00:00'::timestamp without time zone)) Buffers: shared read=6127 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.141..29.838 rows=69999 loops=1) Buffers: shared hit=1906 read=1 -> Sort (cost=1205583.18..1205592.69 rows=3801 width=12) (actual time=62128.932..62128.934 rows=1 loops=1) Sort Key: revenue13.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=652800 read=682225 -> Subquery Scan on revenue13 (cost=1205271.65..1205357.17 rows=3801 width=12) (actual time=62105.574..62128.893 rows=1 loops=1) Buffers: shared hit=652800 read=682225 -> HashAggregate (cost=1205271.65..1205319.16 rows=3801 width=12) (actual time=62105.572..62128.889 rows=1 loops=1) Filter: (sum((public.lineitem.l_extendedprice * (1::double precision - public.lineitem.l_discount))) = $0) Rows Removed by Filter: 99999 Buffers: shared hit=652800 read=682225 -> Bitmap Heap Scan on lineitem (cost=48712.53..1164791.66 rows=2313142 width=12) (actual time=2680.956..32471.410 rows=2242974 loops=1) Recheck Cond: ((l_shipdate >= '1996-01-01'::date) AND (l_shipdate < '1996-03-31 00:00:00'::timestamp without time zone)) Buffers: shared hit=338439 read=329074 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..48134.25 rows=2313142 width=0) (actual time=2296.319..2296.319 rows=2274813 loops=1) Index Cond: ((l_shipdate >= '1996-01-01'::date) AND (l_shipdate < '1996-03-31 00:00:00'::timestamp without time zone)) Buffers: shared read=6128 Total runtime: 62179.884 ms (33 rows) drop view revenue13; DROP VIEW COMMIT; COMMIT