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 >= '1995-11-01' and l_shipdate < date'1995-11-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=2358521.14..2363618.25 rows=3710 width=79) (actual time=33164.678..33164.684 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue10.supplier_no) Buffers: shared hit=672637 read=646161 dirtied=243 written=833 InitPlan 1 (returns $0) -> Aggregate (cost=1170778.06..1170778.07 rows=1 width=8) (actual time=15804.623..15804.623 rows=1 loops=1) Buffers: shared hit=257391 read=401366 written=60 -> HashAggregate (cost=1170694.59..1170731.69 rows=3710 width=12) (actual time=15727.605..15793.499 rows=100000 loops=1) Buffers: shared hit=257391 read=401366 written=60 -> Bitmap Heap Scan on lineitem (cost=47331.74..1148367.85 rows=2232674 width=12) (actual time=2079.097..11799.581 rows=2243625 loops=1) Recheck Cond: ((l_shipdate >= '1995-11-01'::date) AND (l_shipdate < '1996-01-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=257391 read=401366 written=60 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46773.57 rows=2232674 width=0) (actual time=1657.698..1657.698 rows=2245876 loops=1) Index Cond: ((l_shipdate >= '1995-11-01'::date) AND (l_shipdate < '1996-01-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=1 read=6127 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.063..20.946 rows=46963 loops=1) Buffers: shared hit=132 read=1151 -> Sort (cost=1187743.07..1187752.34 rows=3710 width=12) (actual time=33138.724..33138.727 rows=1 loops=1) Sort Key: revenue10.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=672505 read=645010 dirtied=243 written=833 -> Subquery Scan on revenue10 (cost=1187439.64..1187523.12 rows=3710 width=12) (actual time=33113.158..33138.689 rows=1 loops=1) Buffers: shared hit=672505 read=645010 dirtied=243 written=833 -> HashAggregate (cost=1187439.64..1187486.02 rows=3710 width=12) (actual time=33113.156..33138.684 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=672505 read=645010 dirtied=243 written=833 -> Bitmap Heap Scan on lineitem (cost=47331.74..1148367.85 rows=2232674 width=12) (actual time=4689.204..13662.064 rows=2243625 loops=1) Recheck Cond: ((l_shipdate >= '1995-11-01'::date) AND (l_shipdate < '1996-01-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=415114 read=243644 dirtied=243 written=773 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46773.57 rows=2232674 width=0) (actual time=4183.103..4183.103 rows=2245876 loops=1) Index Cond: ((l_shipdate >= '1995-11-01'::date) AND (l_shipdate < '1996-01-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=4 read=6125 Total runtime: 33187.304 ms (33 rows) drop view revenue10; DROP VIEW COMMIT; COMMIT