BEGIN; BEGIN create or replace view revenue10 (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, revenue10 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue10 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2360668.69..2365766.48 rows=3755 width=79) (actual time=23674.200..23674.204 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue10.supplier_no) Buffers: shared hit=696662 read=623780 dirtied=391 written=1749 InitPlan 1 (returns $0) -> Aggregate (cost=1171770.02..1171770.03 rows=1 width=8) (actual time=11705.466..11705.467 rows=1 loops=1) Buffers: shared hit=281245 read=378239 written=193 -> HashAggregate (cost=1171685.54..1171723.09 rows=3755 width=12) (actual time=11614.701..11694.360 rows=100000 loops=1) Buffers: shared hit=281245 read=378239 written=193 -> Bitmap Heap Scan on lineitem (cost=47787.26..1149144.63 rows=2254091 width=12) (actual time=2137.333..8477.865 rows=2250213 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=281245 read=378239 written=193 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47223.74 rows=2254091 width=0) (actual time=1736.680..1736.680 rows=2252390 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=6146 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.034..25.357 rows=53897 loops=1) Buffers: shared hit=180 read=1293 -> Sort (cost=1188898.65..1188908.04 rows=3755 width=12) (actual time=23643.132..23643.134 rows=1 loops=1) Sort Key: revenue10.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=696482 read=622487 dirtied=391 written=1749 -> Subquery Scan on revenue10 (cost=1188591.22..1188675.71 rows=3755 width=12) (actual time=23588.157..23643.093 rows=1 loops=1) Buffers: shared hit=696482 read=622487 dirtied=391 written=1749 -> HashAggregate (cost=1188591.22..1188638.16 rows=3755 width=12) (actual time=23588.155..23643.088 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=696482 read=622487 dirtied=391 written=1749 -> Bitmap Heap Scan on lineitem (cost=47787.26..1149144.63 rows=2254091 width=12) (actual time=2306.562..8799.665 rows=2250213 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=415237 read=244248 dirtied=391 written=1556 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47223.74 rows=2254091 width=0) (actual time=1809.104..1809.104 rows=2252390 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=16 read=6131 Total runtime: 23693.004 ms (33 rows) drop view revenue10; DROP VIEW COMMIT; COMMIT