BEGIN; BEGIN create or replace view revenue1 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1996-12-01' and l_shipdate < date'1996-12-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, revenue1 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue1 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2374392.38..2379490.00 rows=3744 width=79) (actual time=42712.742..42712.745 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue1.supplier_no) Buffers: shared hit=456490 read=870465 dirtied=373 written=21169 InitPlan 1 (returns $0) -> Aggregate (cost=1178584.31..1178584.32 rows=1 width=8) (actual time=24462.091..24462.091 rows=1 loops=1) Buffers: shared hit=202557 read=460768 dirtied=373 written=15001 -> HashAggregate (cost=1178500.07..1178537.51 rows=3744 width=12) (actual time=24393.905..24449.766 rows=100000 loops=1) Buffers: shared hit=202557 read=460768 dirtied=373 written=15001 -> Bitmap Heap Scan on lineitem (cost=47910.27..1155831.35 rows=2266872 width=12) (actual time=2423.402..20282.203 rows=2245866 loops=1) Recheck Cond: ((l_shipdate >= '1996-12-01'::date) AND (l_shipdate < '1997-03-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=202557 read=460768 dirtied=373 written=15001 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47343.55 rows=2266872 width=0) (actual time=1960.726..1960.726 rows=2263838 loops=1) Index Cond: ((l_shipdate >= '1996-12-01'::date) AND (l_shipdate < '1997-03-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=1112 read=5024 written=486 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.099..5.133 rows=10906 loops=1) Buffers: shared hit=303 read=1 -> Sort (cost=1195808.06..1195817.42 rows=3744 width=12) (actual time=42706.383..42706.383 rows=1 loops=1) Sort Key: revenue1.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=456187 read=870464 dirtied=373 written=21169 -> Subquery Scan on revenue1 (cost=1195501.61..1195585.85 rows=3744 width=12) (actual time=42679.843..42706.351 rows=1 loops=1) Buffers: shared hit=456187 read=870464 dirtied=373 written=21169 -> HashAggregate (cost=1195501.61..1195548.41 rows=3744 width=12) (actual time=42679.841..42706.347 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=456187 read=870464 dirtied=373 written=21169 -> Bitmap Heap Scan on lineitem (cost=47910.27..1155831.35 rows=2266872 width=12) (actual time=2336.602..14614.361 rows=2245866 loops=1) Recheck Cond: ((l_shipdate >= '1996-12-01'::date) AND (l_shipdate < '1997-03-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=253630 read=409696 written=6168 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47343.55 rows=2266872 width=0) (actual time=1740.948..1740.948 rows=2261649 loops=1) Index Cond: ((l_shipdate >= '1996-12-01'::date) AND (l_shipdate < '1997-03-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=2113 read=4024 Total runtime: 42728.458 ms (33 rows) drop view revenue1; DROP VIEW COMMIT; COMMIT