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 >= '1996-08-01' and l_shipdate < date'1996-08-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=2356193.62..2361290.83 rows=3716 width=79) (actual time=13234.565..13234.572 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue0.supplier_no) Buffers: shared hit=736002 read=582259 InitPlan 1 (returns $0) -> Aggregate (cost=1169623.06..1169623.07 rows=1 width=8) (actual time=3575.287..3575.287 rows=1 loops=1) Buffers: shared hit=657094 read=1190 -> HashAggregate (cost=1169539.45..1169576.61 rows=3716 width=12) (actual time=3544.846..3565.622 rows=100000 loops=1) Buffers: shared hit=657094 read=1190 -> Bitmap Heap Scan on lineitem (cost=47307.27..1147236.58 rows=2230287 width=12) (actual time=789.103..2334.859 rows=2247173 loops=1) Recheck Cond: ((l_shipdate >= '1996-08-01'::date) AND (l_shipdate < '1996-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=657094 read=1190 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46749.70 rows=2230287 width=0) (actual time=570.862..570.862 rows=2247173 loops=1) Index Cond: ((l_shipdate >= '1996-08-01'::date) AND (l_shipdate < '1996-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=6138 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.030..26.157 rows=61965 loops=1) Buffers: shared hit=1322 read=370 -> Sort (cost=1186570.56..1186579.85 rows=3716 width=12) (actual time=13202.555..13202.557 rows=1 loops=1) Sort Key: revenue0.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=734680 read=581889 -> Subquery Scan on revenue0 (cost=1186266.60..1186350.21 rows=3716 width=12) (actual time=13160.882..13202.514 rows=1 loops=1) Buffers: shared hit=734680 read=581889 -> HashAggregate (cost=1186266.60..1186313.05 rows=3716 width=12) (actual time=13160.873..13202.497 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=734680 read=581889 -> Bitmap Heap Scan on lineitem (cost=47307.27..1147236.58 rows=2230287 width=12) (actual time=902.992..7835.123 rows=2247173 loops=1) Recheck Cond: ((l_shipdate >= '1996-08-01'::date) AND (l_shipdate < '1996-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=77586 read=580699 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46749.70 rows=2230287 width=0) (actual time=683.576..683.576 rows=2247173 loops=1) Index Cond: ((l_shipdate >= '1996-08-01'::date) AND (l_shipdate < '1996-10-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6139 Total runtime: 13243.590 ms (33 rows) drop view revenue0; DROP VIEW COMMIT; COMMIT