BEGIN; BEGIN create or replace view revenue12 (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, revenue12 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue12 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2379641.33..2384736.93 rows=3626 width=79) (actual time=15682.655..15682.659 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue12.supplier_no) Buffers: shared hit=828750 read=505864 dirtied=626 written=20038 InitPlan 1 (returns $0) -> Aggregate (cost=1181438.50..1181438.51 rows=1 width=8) (actual time=7108.384..7108.384 rows=1 loops=1) Buffers: shared hit=365606 read=301141 written=1591 -> HashAggregate (cost=1181356.92..1181393.18 rows=3626 width=12) (actual time=7072.161..7098.804 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=365606 read=301141 written=1591 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=46502.42..1159290.72 rows=2206620 width=12) (actual time=1010.306..5495.992 rows=2245066 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=660608 Buffers: shared hit=365606 read=301141 written=1591 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..45950.76 rows=2206620 width=0) (actual time=781.820..781.820 rows=2276859 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 hit=4 read=6135 written=59 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.049..16.411 rows=40959 loops=1) Buffers: shared hit=116 read=1004 -> Sort (cost=1198202.53..1198211.59 rows=3626 width=12) (actual time=15662.257..15662.259 rows=1 loops=1) Sort Key: revenue12.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=828634 read=504860 dirtied=626 written=20038 -> Subquery Scan on revenue12 (cost=1197906.57..1197988.16 rows=3626 width=12) (actual time=15657.660..15662.213 rows=1 loops=1) Buffers: shared hit=828634 read=504860 dirtied=626 written=20038 -> HashAggregate (cost=1197906.57..1197951.90 rows=3626 width=12) (actual time=15657.657..15662.209 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=828634 read=504860 dirtied=626 written=20038 -> Bitmap Heap Scan on lineitem (cost=46502.42..1159290.72 rows=2206620 width=12) (actual time=1123.984..6288.626 rows=2245066 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=660608 Buffers: shared hit=463028 read=203719 dirtied=626 written=18447 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..45950.76 rows=2206620 width=0) (actual time=877.389..877.389 rows=2275745 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 hit=1035 read=5104 Planning time: 2.698 ms Execution time: 15692.319 ms (38 rows) drop view revenue12; DROP VIEW COMMIT; COMMIT