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 >= '1997-10-01' and l_shipdate < date'1997-10-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=2385324.47..2390421.37 rows=3696 width=79) (actual time=47083.106..47083.109 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue7.supplier_no) Buffers: shared hit=702043 read=633052 written=24758 InitPlan 1 (returns $0) -> Aggregate (cost=1184111.21..1184111.22 rows=1 width=8) (actual time=25271.474..25271.474 rows=1 loops=1) Buffers: shared hit=309826 read=356757 written=24724 -> HashAggregate (cost=1184028.05..1184065.01 rows=3696 width=12) (actual time=25192.296..25257.854 rows=100000 loops=1) Buffers: shared hit=309826 read=356757 written=24724 -> Bitmap Heap Scan on lineitem (cost=47432.30..1161517.35 rows=2251070 width=12) (actual time=2344.589..20726.459 rows=2244404 loops=1) Recheck Cond: ((l_shipdate >= '1997-10-01'::date) AND (l_shipdate < '1997-12-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=309826 read=356757 written=24724 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46869.53 rows=2251070 width=0) (actual time=1970.869..1970.869 rows=2273989 loops=1) Index Cond: ((l_shipdate >= '1997-10-01'::date) AND (l_shipdate < '1997-12-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=806 read=5323 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.112..51.874 rows=70888 loops=1) Buffers: shared hit=1927 read=1 -> Sort (cost=1201213.25..1201222.49 rows=3696 width=12) (actual time=47021.800..47021.801 rows=1 loops=1) Sort Key: revenue7.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=700116 read=633051 written=24758 -> Subquery Scan on revenue7 (cost=1200911.07..1200994.23 rows=3696 width=12) (actual time=47013.759..47021.759 rows=1 loops=1) Buffers: shared hit=700116 read=633051 written=24758 -> HashAggregate (cost=1200911.07..1200957.27 rows=3696 width=12) (actual time=47013.757..47021.755 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=700116 read=633051 written=24758 -> Bitmap Heap Scan on lineitem (cost=47432.30..1161517.35 rows=2251070 width=12) (actual time=2657.990..17353.986 rows=2244404 loops=1) Recheck Cond: ((l_shipdate >= '1997-10-01'::date) AND (l_shipdate < '1997-12-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=390290 read=276294 written=34 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46869.53 rows=2251070 width=0) (actual time=2126.613..2126.613 rows=2273130 loops=1) Index Cond: ((l_shipdate >= '1997-10-01'::date) AND (l_shipdate < '1997-12-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6130 Total runtime: 47107.297 ms (33 rows) drop view revenue7; DROP VIEW COMMIT; COMMIT