BEGIN; BEGIN create or replace view revenue8 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1997-09-01' and l_shipdate < date'1997-09-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, revenue8 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue8 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2362850.05..2367947.81 rows=3753 width=79) (actual time=23824.301..23824.304 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue8.supplier_no) Buffers: shared hit=929305 read=391841 dirtied=291 written=378 InitPlan 1 (returns $0) -> Aggregate (cost=1172856.85..1172856.86 rows=1 width=8) (actual time=10462.164..10462.164 rows=1 loops=1) Buffers: shared hit=491434 read=168723 written=64 -> HashAggregate (cost=1172772.41..1172809.94 rows=3753 width=12) (actual time=10359.356..10444.196 rows=100000 loops=1) Buffers: shared hit=491434 read=168723 written=64 -> Bitmap Heap Scan on lineitem (cost=47785.98..1150221.04 rows=2255137 width=12) (actual time=1734.107..7122.128 rows=2245406 loops=1) Recheck Cond: ((l_shipdate >= '1997-09-01'::date) AND (l_shipdate < '1997-11-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=491434 read=168723 written=64 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47222.20 rows=2255137 width=0) (actual time=1376.461..1376.461 rows=2249932 loops=1) Index Cond: ((l_shipdate >= '1997-09-01'::date) AND (l_shipdate < '1997-11-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=1 read=6132 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.057..9.964 rows=29990 loops=1) Buffers: shared hit=831 -> Sort (cost=1189993.19..1190002.57 rows=3753 width=12) (actual time=23811.279..23811.280 rows=1 loops=1) Sort Key: revenue8.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=928474 read=391841 dirtied=291 written=378 -> Subquery Scan on revenue8 (cost=1189685.94..1189770.38 rows=3753 width=12) (actual time=23792.579..23811.249 rows=1 loops=1) Buffers: shared hit=928474 read=391841 dirtied=291 written=378 -> HashAggregate (cost=1189685.94..1189732.85 rows=3753 width=12) (actual time=23792.576..23811.244 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=928474 read=391841 dirtied=291 written=378 -> Bitmap Heap Scan on lineitem (cost=47785.98..1150221.04 rows=2255137 width=12) (actual time=2321.979..9928.245 rows=2245406 loops=1) Recheck Cond: ((l_shipdate >= '1997-09-01'::date) AND (l_shipdate < '1997-11-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=437040 read=223118 dirtied=291 written=314 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47222.20 rows=2255137 width=0) (actual time=1813.042..1813.042 rows=2249932 loops=1) Index Cond: ((l_shipdate >= '1997-09-01'::date) AND (l_shipdate < '1997-11-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=5 read=6129 Total runtime: 23841.221 ms (33 rows) drop view revenue8; DROP VIEW COMMIT; COMMIT