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 >= '1997-09-01' and l_shipdate < date'1997-09-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=2359297.59..2364394.68 rows=3726 width=79) (actual time=15717.735..15717.740 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue10.supplier_no) Buffers: shared hit=1030007 read=289853 dirtied=201 written=8 InitPlan 1 (returns $0) -> Aggregate (cost=1171136.24..1171136.25 rows=1 width=8) (actual time=8139.572..8139.572 rows=1 loops=1) Buffers: shared hit=462275 read=197240 -> HashAggregate (cost=1171052.40..1171089.66 rows=3726 width=12) (actual time=8096.512..8128.965 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=462275 read=197240 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47493.75..1148647.34 rows=2240506 width=12) (actual time=1634.182..6301.561 rows=2245476 loops=1) Recheck Cond: ((l_shipdate >= '1997-09-01'::date) AND (l_shipdate < '1997-11-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=653382 Buffers: shared hit=462275 read=197240 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46933.62 rows=2240506 width=0) (actual time=1266.520..1266.520 rows=2247772 loops=1) Index Cond: ((l_shipdate >= '1997-09-01'::date) AND (l_shipdate < '1997-11-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6133 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.029..11.665 rows=29990 loops=1) Buffers: shared hit=830 -> Sort (cost=1188161.05..1188170.36 rows=3726 width=12) (actual time=15703.008..15703.010 rows=1 loops=1) Sort Key: revenue10.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=1029177 read=289853 dirtied=201 written=8 -> Subquery Scan on revenue10 (cost=1187856.20..1187940.03 rows=3726 width=12) (actual time=15693.407..15702.981 rows=1 loops=1) Buffers: shared hit=1029177 read=289853 dirtied=201 written=8 -> HashAggregate (cost=1187856.20..1187902.77 rows=3726 width=12) (actual time=15693.405..15702.977 rows=1 loops=1) Group Key: lineitem.l_suppkey Filter: (sum((lineitem.l_extendedprice * (1::double precision - lineitem.l_discount))) = $0) Rows Removed by Filter: 99999 Buffers: shared hit=1029177 read=289853 dirtied=201 written=8 -> Bitmap Heap Scan on lineitem (cost=47493.75..1148647.34 rows=2240506 width=12) (actual time=1223.298..5761.116 rows=2245476 loops=1) Recheck Cond: ((l_shipdate >= '1997-09-01'::date) AND (l_shipdate < '1997-11-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=653382 Buffers: shared hit=566902 read=92613 dirtied=201 written=8 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46933.62 rows=2240506 width=0) (actual time=960.973..960.973 rows=2247772 loops=1) Index Cond: ((l_shipdate >= '1997-09-01'::date) AND (l_shipdate < '1997-11-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=1 read=6132 Planning time: 2.628 ms Execution time: 15725.758 ms (38 rows) drop view revenue10; DROP VIEW COMMIT; COMMIT