BEGIN; BEGIN create or replace view revenue22 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1995-07-01' and l_shipdate < date'1995-07-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, revenue22 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue22 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2378980.80..2384077.67 rows=3711 width=79) (actual time=20458.067..20458.073 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue22.supplier_no) Buffers: shared hit=624106 read=707404 written=683 InitPlan 1 (returns $0) -> Aggregate (cost=1180941.76..1180941.77 rows=1 width=8) (actual time=10327.614..10327.614 rows=1 loops=1) Buffers: shared hit=319085 read=346110 written=291 -> HashAggregate (cost=1180858.27..1180895.38 rows=3711 width=12) (actual time=10251.775..10317.555 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=319085 read=346110 written=291 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47481.74..1158355.66 rows=2250261 width=12) (actual time=1522.347..7588.603 rows=2247583 loops=1) Recheck Cond: ((l_shipdate >= '1995-07-01'::date) AND (l_shipdate < '1995-09-29 00:00:00'::timestamp without time zone)) Heap Blocks: exact=659056 Buffers: shared hit=319085 read=346110 written=291 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46919.18 rows=2250261 width=0) (actual time=1214.936..1214.936 rows=2270288 loops=1) Index Cond: ((l_shipdate >= '1995-07-01'::date) AND (l_shipdate < '1995-09-29 00:00:00'::timestamp without time zone)) Buffers: shared read=6139 written=9 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.037..16.174 rows=40959 loops=1) Buffers: shared hit=1120 -> Sort (cost=1198038.74..1198048.02 rows=3711 width=12) (actual time=20437.755..20437.758 rows=1 loops=1) Sort Key: revenue22.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=622986 read=707404 written=683 -> Subquery Scan on revenue22 (cost=1197735.22..1197818.72 rows=3711 width=12) (actual time=20431.048..20437.721 rows=1 loops=1) Buffers: shared hit=622986 read=707404 written=683 -> HashAggregate (cost=1197735.22..1197781.61 rows=3711 width=12) (actual time=20431.046..20437.718 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=622986 read=707404 written=683 -> Bitmap Heap Scan on lineitem (cost=47481.74..1158355.66 rows=2250261 width=12) (actual time=1238.500..8165.822 rows=2247583 loops=1) Recheck Cond: ((l_shipdate >= '1995-07-01'::date) AND (l_shipdate < '1995-09-29 00:00:00'::timestamp without time zone)) Heap Blocks: exact=659056 Buffers: shared hit=303901 read=361294 written=392 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46919.18 rows=2250261 width=0) (actual time=951.687..951.687 rows=2270288 loops=1) Index Cond: ((l_shipdate >= '1995-07-01'::date) AND (l_shipdate < '1995-09-29 00:00:00'::timestamp without time zone)) Buffers: shared read=6139 written=7 Planning time: 2.965 ms Execution time: 20469.625 ms (38 rows) drop view revenue22; DROP VIEW COMMIT; COMMIT