BEGIN; BEGIN create or replace view revenue12 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1997-02-01' and l_shipdate < date'1997-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, revenue12 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue12 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2387071.64..2392169.68 rows=3772 width=79) (actual time=25184.658..25184.663 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue12.supplier_no) Buffers: shared hit=389147 read=946193 InitPlan 1 (returns $0) -> Aggregate (cost=1184838.96..1184838.97 rows=1 width=8) (actual time=11540.066..11540.066 rows=1 loops=1) Buffers: shared hit=199440 read=467210 -> HashAggregate (cost=1184754.09..1184791.81 rows=3772 width=12) (actual time=11491.259..11530.393 rows=100000 loops=1) Buffers: shared hit=199440 read=467210 -> Bitmap Heap Scan on lineitem (cost=48259.99..1161861.25 rows=2289284 width=12) (actual time=2266.377..8628.443 rows=2248474 loops=1) Recheck Cond: ((l_shipdate >= '1997-02-01'::date) AND (l_shipdate < '1997-05-02 00:00:00'::timestamp without time zone)) Buffers: shared hit=199440 read=467210 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47687.67 rows=2289284 width=0) (actual time=1862.196..1862.196 rows=2277091 loops=1) Index Cond: ((l_shipdate >= '1997-02-01'::date) AND (l_shipdate < '1997-05-02 00:00:00'::timestamp without time zone)) Buffers: shared read=6144 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.125..27.316 rows=74945 loops=1) Buffers: shared hit=302 read=1737 -> Sort (cost=1202232.67..1202242.10 rows=3772 width=12) (actual time=25150.394..25150.396 rows=1 loops=1) Sort Key: revenue12.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=388845 read=944456 -> Subquery Scan on revenue12 (cost=1201923.72..1202008.59 rows=3772 width=12) (actual time=25133.095..25150.350 rows=1 loops=1) Buffers: shared hit=388845 read=944456 -> HashAggregate (cost=1201923.72..1201970.87 rows=3772 width=12) (actual time=25133.092..25150.344 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=388845 read=944456 -> Bitmap Heap Scan on lineitem (cost=48259.99..1161861.25 rows=2289284 width=12) (actual time=2044.223..10485.810 rows=2248474 loops=1) Recheck Cond: ((l_shipdate >= '1997-02-01'::date) AND (l_shipdate < '1997-05-02 00:00:00'::timestamp without time zone)) Buffers: shared hit=189405 read=477246 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47687.67 rows=2289284 width=0) (actual time=1666.301..1666.301 rows=2277091 loops=1) Index Cond: ((l_shipdate >= '1997-02-01'::date) AND (l_shipdate < '1997-05-02 00:00:00'::timestamp without time zone)) Buffers: shared read=6145 Total runtime: 25205.359 ms (33 rows) drop view revenue12; DROP VIEW COMMIT; COMMIT