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 >= '1994-07-01' and l_shipdate < date'1994-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, revenue10 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue10 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2361069.39..2366167.18 rows=3755 width=79) (actual time=29437.063..29437.069 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue10.supplier_no) Buffers: shared hit=795347 read=524238 dirtied=217 written=371 InitPlan 1 (returns $0) -> Aggregate (cost=1171955.34..1171955.35 rows=1 width=8) (actual time=15375.487..15375.488 rows=1 loops=1) Buffers: shared hit=292458 read=367069 written=56 -> HashAggregate (cost=1171870.85..1171908.40 rows=3755 width=12) (actual time=15242.356..15323.380 rows=100000 loops=1) Buffers: shared hit=292458 read=367069 written=56 -> Bitmap Heap Scan on lineitem (cost=47872.35..1149289.85 rows=2258100 width=12) (actual time=2628.485..11594.474 rows=2250129 loops=1) Recheck Cond: ((l_shipdate >= '1994-07-01'::date) AND (l_shipdate < '1994-09-29 00:00:00'::timestamp without time zone)) Buffers: shared hit=292458 read=367069 written=56 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47307.83 rows=2258100 width=0) (actual time=2172.430..2172.430 rows=2252389 loops=1) Index Cond: ((l_shipdate >= '1994-07-01'::date) AND (l_shipdate < '1994-09-29 00:00:00'::timestamp without time zone)) Buffers: shared hit=2 read=6144 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.078..13.421 rows=18903 loops=1) Buffers: shared hit=76 read=454 -> Sort (cost=1189114.04..1189123.42 rows=3755 width=12) (actual time=29420.234..29420.237 rows=1 loops=1) Sort Key: revenue10.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=795271 read=523784 dirtied=217 written=371 -> Subquery Scan on revenue10 (cost=1188806.60..1188891.09 rows=3755 width=12) (actual time=29415.035..29420.175 rows=1 loops=1) Buffers: shared hit=795271 read=523784 dirtied=217 written=371 -> HashAggregate (cost=1188806.60..1188853.54 rows=3755 width=12) (actual time=29415.031..29420.169 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=795271 read=523784 dirtied=217 written=371 -> Bitmap Heap Scan on lineitem (cost=47872.35..1149289.85 rows=2258100 width=12) (actual time=3235.571..10210.289 rows=2250129 loops=1) Recheck Cond: ((l_shipdate >= '1994-07-01'::date) AND (l_shipdate < '1994-09-29 00:00:00'::timestamp without time zone)) Buffers: shared hit=502813 read=156715 dirtied=217 written=315 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47307.83 rows=2258100 width=0) (actual time=2768.967..2768.967 rows=2252389 loops=1) Index Cond: ((l_shipdate >= '1994-07-01'::date) AND (l_shipdate < '1994-09-29 00:00:00'::timestamp without time zone)) Buffers: shared hit=954 read=5193 Total runtime: 29471.243 ms (33 rows) drop view revenue10; DROP VIEW COMMIT; COMMIT