BEGIN; BEGIN create or replace view revenue0 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1993-02-01' and l_shipdate < date'1993-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, revenue0 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue0 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2359184.17..2364282.11 rows=3765 width=79) (actual time=13512.169..13512.172 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue0.supplier_no) Buffers: shared hit=729258 read=589906 InitPlan 1 (returns $0) -> Aggregate (cost=1171004.72..1171004.73 rows=1 width=8) (actual time=3774.291..3774.291 rows=1 loops=1) Buffers: shared hit=657691 read=1154 -> HashAggregate (cost=1170920.01..1170957.66 rows=3765 width=12) (actual time=3743.845..3764.781 rows=100000 loops=1) Buffers: shared hit=657691 read=1154 -> Bitmap Heap Scan on lineitem (cost=47941.34..1148318.54 rows=2260147 width=12) (actual time=774.628..2523.672 rows=2250260 loops=1) Recheck Cond: ((l_shipdate >= '1993-02-01'::date) AND (l_shipdate < '1993-05-02 00:00:00'::timestamp without time zone)) Buffers: shared hit=657691 read=1154 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47376.30 rows=2260147 width=0) (actual time=558.952..558.952 rows=2250260 loops=1) Index Cond: ((l_shipdate >= '1993-02-01'::date) AND (l_shipdate < '1993-05-02 00:00:00'::timestamp without time zone)) Buffers: shared hit=6146 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.044..18.804 rows=53897 loops=1) Buffers: shared hit=1148 read=325 -> Sort (cost=1188179.44..1188188.85 rows=3765 width=12) (actual time=13488.315..13488.316 rows=1 loops=1) Sort Key: revenue0.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=728110 read=589581 -> Subquery Scan on revenue0 (cost=1187871.11..1187955.83 rows=3765 width=12) (actual time=13471.685..13488.250 rows=1 loops=1) Buffers: shared hit=728110 read=589581 -> HashAggregate (cost=1187871.11..1187918.18 rows=3765 width=12) (actual time=13471.683..13488.247 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=728110 read=589581 -> Bitmap Heap Scan on lineitem (cost=47941.34..1148318.54 rows=2260147 width=12) (actual time=890.896..8043.772 rows=2250260 loops=1) Recheck Cond: ((l_shipdate >= '1993-02-01'::date) AND (l_shipdate < '1993-05-02 00:00:00'::timestamp without time zone)) Buffers: shared hit=70419 read=588427 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47376.30 rows=2260147 width=0) (actual time=675.450..675.450 rows=2250260 loops=1) Index Cond: ((l_shipdate >= '1993-02-01'::date) AND (l_shipdate < '1993-05-02 00:00:00'::timestamp without time zone)) Buffers: shared read=6147 Total runtime: 13516.663 ms (33 rows) drop view revenue0; DROP VIEW COMMIT; COMMIT