BEGIN; BEGIN create or replace view revenue6 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1994-05-01' and l_shipdate < date'1994-05-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, revenue6 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue6 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2362341.31..2367438.95 rows=3745 width=79) (actual time=33947.251..33947.254 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue6.supplier_no) Buffers: shared hit=475376 read=846958 dirtied=353 written=354 InitPlan 1 (returns $0) -> Aggregate (cost=1172621.78..1172621.79 rows=1 width=8) (actual time=16994.317..16994.317 rows=1 loops=1) Buffers: shared hit=143955 read=516232 written=5 -> HashAggregate (cost=1172537.51..1172574.96 rows=3745 width=12) (actual time=16916.993..16983.411 rows=100000 loops=1) Buffers: shared hit=143955 read=516232 written=5 -> Bitmap Heap Scan on lineitem (cost=47677.96..1150036.89 rows=2250062 width=12) (actual time=2081.532..12840.952 rows=2247211 loops=1) Recheck Cond: ((l_shipdate >= '1994-05-01'::date) AND (l_shipdate < '1994-07-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=143955 read=516232 written=5 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47115.45 rows=2250062 width=0) (actual time=1668.934..1668.934 rows=2251993 loops=1) Index Cond: ((l_shipdate >= '1994-05-01'::date) AND (l_shipdate < '1994-07-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6138 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.087..29.402 rows=71902 loops=1) Buffers: shared hit=1958 read=1 -> Sort (cost=1189719.52..1189728.88 rows=3745 width=12) (actual time=33910.386..33910.387 rows=1 loops=1) Sort Key: revenue6.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=473418 read=846957 dirtied=353 written=354 -> Subquery Scan on revenue6 (cost=1189412.98..1189497.24 rows=3745 width=12) (actual time=33898.380..33910.358 rows=1 loops=1) Buffers: shared hit=473418 read=846957 dirtied=353 written=354 -> HashAggregate (cost=1189412.98..1189459.79 rows=3745 width=12) (actual time=33898.378..33910.354 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=473418 read=846957 dirtied=353 written=354 -> Bitmap Heap Scan on lineitem (cost=47677.96..1150036.89 rows=2250062 width=12) (actual time=2053.247..12749.784 rows=2247211 loops=1) Recheck Cond: ((l_shipdate >= '1994-05-01'::date) AND (l_shipdate < '1994-07-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=329463 read=330725 dirtied=353 written=349 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47115.45 rows=2250062 width=0) (actual time=1655.928..1655.928 rows=2251993 loops=1) Index Cond: ((l_shipdate >= '1994-05-01'::date) AND (l_shipdate < '1994-07-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=3 read=6136 written=6 Total runtime: 33962.899 ms (33 rows) drop view revenue6; DROP VIEW COMMIT; COMMIT