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 >= '1995-02-01' and l_shipdate < date'1995-02-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=2382733.25..2387831.36 rows=3777 width=79) (actual time=24317.496..24317.502 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue7.supplier_no) Buffers: shared hit=349019 read=984762 written=170 InitPlan 1 (returns $0) -> Aggregate (cost=1182675.32..1182675.33 rows=1 width=8) (actual time=11073.179..11073.179 rows=1 loops=1) Buffers: shared hit=224952 read=440796 -> HashAggregate (cost=1182590.33..1182628.10 rows=3777 width=12) (actual time=11009.319..11063.631 rows=100000 loops=1) Buffers: shared hit=224952 read=440796 -> Bitmap Heap Scan on lineitem (cost=48276.36..1159712.74 rows=2287759 width=12) (actual time=1900.410..8155.438 rows=2247295 loops=1) Recheck Cond: ((l_shipdate >= '1995-02-01'::date) AND (l_shipdate < '1995-05-02 00:00:00'::timestamp without time zone)) Buffers: shared hit=224952 read=440796 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47704.42 rows=2287759 width=0) (actual time=1521.230..1521.230 rows=2272240 loops=1) Index Cond: ((l_shipdate >= '1995-02-01'::date) AND (l_shipdate < '1995-05-02 00:00:00'::timestamp without time zone)) Buffers: shared read=6146 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.112..33.784 rows=83967 loops=1) Buffers: shared hit=2283 read=1 -> Sort (cost=1200057.92..1200067.36 rows=3777 width=12) (actual time=24275.867..24275.869 rows=1 loops=1) Sort Key: revenue7.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=346736 read=984761 written=170 -> Subquery Scan on revenue7 (cost=1199748.53..1199833.51 rows=3777 width=12) (actual time=24244.866..24275.819 rows=1 loops=1) Buffers: shared hit=346736 read=984761 written=170 -> HashAggregate (cost=1199748.53..1199795.74 rows=3777 width=12) (actual time=24244.863..24275.810 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=346736 read=984761 written=170 -> Bitmap Heap Scan on lineitem (cost=48276.36..1159712.74 rows=2287759 width=12) (actual time=2221.755..10206.607 rows=2247295 loops=1) Recheck Cond: ((l_shipdate >= '1995-02-01'::date) AND (l_shipdate < '1995-05-02 00:00:00'::timestamp without time zone)) Buffers: shared hit=121784 read=543965 written=170 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47704.42 rows=2287759 width=0) (actual time=1765.957..1765.957 rows=2272240 loops=1) Index Cond: ((l_shipdate >= '1995-02-01'::date) AND (l_shipdate < '1995-05-02 00:00:00'::timestamp without time zone)) Buffers: shared read=6147 Total runtime: 24333.474 ms (33 rows) drop view revenue7; DROP VIEW COMMIT; COMMIT