BEGIN; BEGIN create or replace view revenue18 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1995-09-01' and l_shipdate < date'1995-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, revenue18 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue18 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2386195.47..2391292.22 rows=3686 width=79) (actual time=105698.686..105698.689 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue18.supplier_no) Buffers: shared hit=393232 read=945323 written=12291 InitPlan 1 (returns $0) -> Aggregate (cost=1184577.71..1184577.72 rows=1 width=8) (actual time=54159.812..54159.813 rows=1 loops=1) Buffers: shared hit=303218 read=364729 written=16 -> HashAggregate (cost=1184494.77..1184531.63 rows=3686 width=12) (actual time=54084.494..54145.767 rows=100000 loops=1) Buffers: shared hit=303218 read=364729 written=16 -> Bitmap Heap Scan on lineitem (cost=47240.47..1162065.85 rows=2242892 width=12) (actual time=2935.358..49186.878 rows=2245011 loops=1) Recheck Cond: ((l_shipdate >= '1995-09-01'::date) AND (l_shipdate < '1995-11-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=303218 read=364729 written=16 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46679.75 rows=2242892 width=0) (actual time=2475.108..2475.108 rows=2279099 loops=1) Index Cond: ((l_shipdate >= '1995-09-01'::date) AND (l_shipdate < '1995-11-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6139 written=9 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.110..137.787 rows=97885 loops=1) Buffers: shared hit=2660 -> Sort (cost=1201617.75..1201626.97 rows=3686 width=12) (actual time=105543.199..105543.199 rows=1 loops=1) Sort Key: revenue18.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=390572 read=945323 written=12291 -> Subquery Scan on revenue18 (cost=1201316.46..1201399.40 rows=3686 width=12) (actual time=105510.922..105543.162 rows=1 loops=1) Buffers: shared hit=390572 read=945323 written=12291 -> HashAggregate (cost=1201316.46..1201362.54 rows=3686 width=12) (actual time=105510.920..105543.158 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=390572 read=945323 written=12291 -> Bitmap Heap Scan on lineitem (cost=47240.47..1162065.85 rows=2242892 width=12) (actual time=2975.714..46427.513 rows=2245011 loops=1) Recheck Cond: ((l_shipdate >= '1995-09-01'::date) AND (l_shipdate < '1995-11-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=87354 read=580594 written=12275 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46679.75 rows=2242892 width=0) (actual time=2523.298..2523.298 rows=2278745 loops=1) Index Cond: ((l_shipdate >= '1995-09-01'::date) AND (l_shipdate < '1995-11-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=619 read=5521 written=528 Total runtime: 105713.983 ms (33 rows) drop view revenue18; DROP VIEW COMMIT; COMMIT