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 >= '1997-06-01' and l_shipdate < date'1997-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, revenue13 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue13 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2390720.16..2395817.34 rows=3715 width=79) (actual time=57798.610..57798.614 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue13.supplier_no) Buffers: shared hit=275259 read=1063477 written=65 InitPlan 1 (returns $0) -> Aggregate (cost=1186761.71..1186761.72 rows=1 width=8) (actual time=16671.868..16671.868 rows=1 loops=1) Buffers: shared hit=82336 read=586442 -> HashAggregate (cost=1186678.12..1186715.27 rows=3715 width=12) (actual time=16591.884..16660.832 rows=100000 loops=1) Buffers: shared hit=82336 read=586442 -> Bitmap Heap Scan on lineitem (cost=47643.97..1164042.86 rows=2263526 width=12) (actual time=1974.288..12798.087 rows=2246314 loops=1) Recheck Cond: ((l_shipdate >= '1997-06-01'::date) AND (l_shipdate < '1997-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=82336 read=586442 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47078.09 rows=2263526 width=0) (actual time=1622.911..1622.911 rows=2279970 loops=1) Index Cond: ((l_shipdate >= '1997-06-01'::date) AND (l_shipdate < '1997-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=1 read=6133 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.142..19.756 rows=42993 loops=1) Buffers: shared hit=1179 -> Sort (cost=1203958.44..1203967.72 rows=3715 width=12) (actual time=57774.221..57774.222 rows=1 loops=1) Sort Key: revenue13.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=274080 read=1063477 written=65 -> Subquery Scan on revenue13 (cost=1203654.57..1203738.15 rows=3715 width=12) (actual time=57759.626..57774.185 rows=1 loops=1) Buffers: shared hit=274080 read=1063477 written=65 -> HashAggregate (cost=1203654.57..1203701.00 rows=3715 width=12) (actual time=57759.625..57774.182 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=274080 read=1063477 written=65 -> Bitmap Heap Scan on lineitem (cost=47643.97..1164042.86 rows=2263526 width=12) (actual time=2857.630..36167.436 rows=2246314 loops=1) Recheck Cond: ((l_shipdate >= '1997-06-01'::date) AND (l_shipdate < '1997-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=191744 read=477035 written=65 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47078.09 rows=2263526 width=0) (actual time=2512.832..2512.832 rows=2279970 loops=1) Index Cond: ((l_shipdate >= '1997-06-01'::date) AND (l_shipdate < '1997-08-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6135 Total runtime: 57810.385 ms (33 rows) drop view revenue13; DROP VIEW COMMIT; COMMIT