BEGIN; BEGIN create or replace view revenue4 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1997-03-01' and l_shipdate < date'1997-03-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, revenue4 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue4 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2363217.89..2368315.47 rows=3758 width=79) (actual time=20336.752..20336.754 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue4.supplier_no) Buffers: shared hit=590384 read=730878 dirtied=396 written=13875 InitPlan 1 (returns $0) -> Aggregate (cost=1173026.06..1173026.07 rows=1 width=8) (actual time=9261.427..9261.427 rows=1 loops=1) Buffers: shared hit=306082 read=354410 written=1043 -> HashAggregate (cost=1172941.50..1172979.08 rows=3758 width=12) (actual time=9214.098..9252.212 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=306082 read=354410 written=1043 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47859.08..1150351.73 rows=2258977 width=12) (actual time=1397.046..6687.761 rows=2249656 loops=1) Recheck Cond: ((l_shipdate >= '1997-03-01'::date) AND (l_shipdate < '1997-05-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=654347 Buffers: shared hit=306082 read=354410 written=1043 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47294.34 rows=2258977 width=0) (actual time=1064.438..1064.438 rows=2254224 loops=1) Index Cond: ((l_shipdate >= '1997-03-01'::date) AND (l_shipdate < '1997-05-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=3 read=6142 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.029..3.876 rows=9914 loops=1) Buffers: shared hit=278 -> Sort (cost=1190191.53..1190200.93 rows=3758 width=12) (actual time=20331.984..20331.985 rows=1 loops=1) Sort Key: revenue4.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=590106 read=730878 dirtied=396 written=13875 -> Subquery Scan on revenue4 (cost=1189883.83..1189968.39 rows=3758 width=12) (actual time=20319.366..20331.951 rows=1 loops=1) Buffers: shared hit=590106 read=730878 dirtied=396 written=13875 -> HashAggregate (cost=1189883.83..1189930.81 rows=3758 width=12) (actual time=20319.364..20331.949 rows=1 loops=1) Group Key: lineitem.l_suppkey Filter: (sum((lineitem.l_extendedprice * (1::double precision - lineitem.l_discount))) = $0) Rows Removed by Filter: 99999 Buffers: shared hit=590106 read=730878 dirtied=396 written=13875 -> Bitmap Heap Scan on lineitem (cost=47859.08..1150351.73 rows=2258977 width=12) (actual time=1571.797..8306.244 rows=2249656 loops=1) Recheck Cond: ((l_shipdate >= '1997-03-01'::date) AND (l_shipdate < '1997-05-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=654347 Buffers: shared hit=284024 read=376468 dirtied=396 written=12832 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47294.34 rows=2258977 width=0) (actual time=1218.629..1218.629 rows=2254224 loops=1) Index Cond: ((l_shipdate >= '1997-03-01'::date) AND (l_shipdate < '1997-05-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=627 read=5518 written=888 Planning time: 2.292 ms Execution time: 20348.153 ms (38 rows) drop view revenue4; DROP VIEW COMMIT; COMMIT