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-01-01' and l_shipdate < date'1993-01-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=2361931.01..2367029.59 rows=3808 width=79) (actual time=15154.299..15154.304 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue0.supplier_no) Buffers: shared hit=734135 read=585887 InitPlan 1 (returns $0) -> Aggregate (cost=1172273.73..1172273.74 rows=1 width=8) (actual time=4097.201..4097.201 rows=1 loops=1) Buffers: shared hit=658093 read=1181 -> HashAggregate (cost=1172188.05..1172226.13 rows=3808 width=12) (actual time=4066.087..4087.482 rows=100000 loops=1) Buffers: shared hit=658093 read=1181 -> Bitmap Heap Scan on lineitem (cost=48522.82..1149311.96 rows=2287609 width=12) (actual time=941.664..2828.811 rows=2249543 loops=1) Recheck Cond: ((l_shipdate >= '1993-01-01'::date) AND (l_shipdate < '1993-04-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=658093 read=1181 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47950.92 rows=2287609 width=0) (actual time=670.341..670.341 rows=2249543 loops=1) Index Cond: ((l_shipdate >= '1993-01-01'::date) AND (l_shipdate < '1993-04-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=6144 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.035..24.022 rows=53897 loops=1) Buffers: shared hit=1151 read=322 -> Sort (cost=1189657.27..1189666.79 rows=3808 width=12) (actual time=15125.130..15125.132 rows=1 loops=1) Sort Key: revenue0.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=732984 read=585565 -> Subquery Scan on revenue0 (cost=1189345.11..1189430.79 rows=3808 width=12) (actual time=15084.106..15125.087 rows=1 loops=1) Buffers: shared hit=732984 read=585565 -> HashAggregate (cost=1189345.11..1189392.71 rows=3808 width=12) (actual time=15084.104..15125.084 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=732984 read=585565 -> Bitmap Heap Scan on lineitem (cost=48522.82..1149311.96 rows=2287609 width=12) (actual time=906.696..8030.191 rows=2249543 loops=1) Recheck Cond: ((l_shipdate >= '1993-01-01'::date) AND (l_shipdate < '1993-04-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=74891 read=584384 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47950.92 rows=2287609 width=0) (actual time=689.970..689.970 rows=2249543 loops=1) Index Cond: ((l_shipdate >= '1993-01-01'::date) AND (l_shipdate < '1993-04-01 00:00:00'::timestamp without time zone)) Buffers: shared read=6145 Total runtime: 15163.927 ms (33 rows) drop view revenue0; DROP VIEW COMMIT; COMMIT