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 >= '1996-02-01' and l_shipdate < date'1996-02-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=2386927.81..2392024.51 rows=3682 width=79) (actual time=32423.685..32423.692 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue12.supplier_no) Buffers: shared hit=674423 read=661970 dirtied=643 written=18130 InitPlan 1 (returns $0) -> Aggregate (cost=1184931.09..1184931.10 rows=1 width=8) (actual time=16626.980..16626.980 rows=1 loops=1) Buffers: shared hit=195983 read=471367 dirtied=643 written=18130 -> HashAggregate (cost=1184848.24..1184885.06 rows=3682 width=12) (actual time=16552.615..16616.219 rows=100000 loops=1) Buffers: shared hit=195983 read=471367 dirtied=643 written=18130 -> Bitmap Heap Scan on lineitem (cost=47307.79..1162384.86 rows=2246338 width=12) (actual time=2023.507..12656.243 rows=2243258 loops=1) Recheck Cond: ((l_shipdate >= '1996-02-01'::date) AND (l_shipdate < '1996-05-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=195983 read=471367 dirtied=643 written=18130 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46746.21 rows=2246338 width=0) (actual time=1593.800..1593.800 rows=2274808 loops=1) Index Cond: ((l_shipdate >= '1996-02-01'::date) AND (l_shipdate < '1996-05-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=1 read=6126 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.091..26.553 rows=61971 loops=1) Buffers: shared hit=1691 read=1 -> Sort (cost=1201996.71..1202005.92 rows=3682 width=12) (actual time=32390.648..32390.650 rows=1 loops=1) Sort Key: revenue12.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=672732 read=661969 dirtied=643 written=18130 -> Subquery Scan on revenue12 (cost=1201695.78..1201778.62 rows=3682 width=12) (actual time=32359.600..32390.607 rows=1 loops=1) Buffers: shared hit=672732 read=661969 dirtied=643 written=18130 -> HashAggregate (cost=1201695.78..1201741.80 rows=3682 width=12) (actual time=32359.598..32390.602 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=672732 read=661969 dirtied=643 written=18130 -> Bitmap Heap Scan on lineitem (cost=47307.79..1162384.86 rows=2246338 width=12) (actual time=2426.191..11599.164 rows=2243258 loops=1) Recheck Cond: ((l_shipdate >= '1996-02-01'::date) AND (l_shipdate < '1996-05-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=476749 read=190602 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46746.21 rows=2246338 width=0) (actual time=2010.924..2010.924 rows=2274808 loops=1) Index Cond: ((l_shipdate >= '1996-02-01'::date) AND (l_shipdate < '1996-05-01 00:00:00'::timestamp without time zone)) Buffers: shared read=6128 Total runtime: 32441.817 ms (33 rows) drop view revenue12; DROP VIEW COMMIT; COMMIT