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-03-01' and l_shipdate < date'1993-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, revenue10 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue10 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2361223.58..2366321.46 rows=3761 width=79) (actual time=39348.865..39348.871 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue10.supplier_no) Buffers: shared hit=839070 read=482928 dirtied=238 written=444 InitPlan 1 (returns $0) -> Aggregate (cost=1172026.40..1172026.41 rows=1 width=8) (actual time=17592.268..17592.268 rows=1 loops=1) Buffers: shared hit=393607 read=266506 -> HashAggregate (cost=1171941.77..1171979.38 rows=3761 width=12) (actual time=17533.200..17581.871 rows=100000 loops=1) Buffers: shared hit=393607 read=266506 -> Bitmap Heap Scan on lineitem (cost=47904.32..1149345.19 rows=2259658 width=12) (actual time=2236.155..13707.387 rows=2249760 loops=1) Recheck Cond: ((l_shipdate >= '1993-03-01'::date) AND (l_shipdate < '1993-05-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=393607 read=266506 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47339.41 rows=2259658 width=0) (actual time=1776.163..1776.163 rows=2251935 loops=1) Index Cond: ((l_shipdate >= '1993-03-01'::date) AND (l_shipdate < '1993-05-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6144 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.084..33.937 rows=64983 loops=1) Buffers: shared hit=178 read=1593 -> Sort (cost=1189197.18..1189206.58 rows=3761 width=12) (actual time=39307.972..39307.974 rows=1 loops=1) Sort Key: revenue10.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=838892 read=481335 dirtied=238 written=444 -> Subquery Scan on revenue10 (cost=1188889.21..1188973.83 rows=3761 width=12) (actual time=39283.457..39307.939 rows=1 loops=1) Buffers: shared hit=838892 read=481335 dirtied=238 written=444 -> HashAggregate (cost=1188889.21..1188936.22 rows=3761 width=12) (actual time=39283.455..39307.935 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=838892 read=481335 dirtied=238 written=444 -> Bitmap Heap Scan on lineitem (cost=47904.32..1149345.19 rows=2259658 width=12) (actual time=4977.557..17453.080 rows=2249760 loops=1) Recheck Cond: ((l_shipdate >= '1993-03-01'::date) AND (l_shipdate < '1993-05-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=445285 read=214829 dirtied=238 written=444 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47339.41 rows=2259658 width=0) (actual time=4626.678..4626.678 rows=2251935 loops=1) Index Cond: ((l_shipdate >= '1993-03-01'::date) AND (l_shipdate < '1993-05-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=3 read=6142 Total runtime: 39366.199 ms (33 rows) drop view revenue10; DROP VIEW COMMIT; COMMIT