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-11-01' and l_shipdate < date'1996-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, revenue12 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue12 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2385457.97..2390554.79 rows=3708 width=79) (actual time=16852.064..16852.067 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue12.supplier_no) Buffers: shared hit=510685 read=825216 dirtied=692 written=440 InitPlan 1 (returns $0) -> Aggregate (cost=1184172.01..1184172.02 rows=1 width=8) (actual time=8426.543..8426.544 rows=1 loops=1) Buffers: shared hit=171604 read=495665 written=243 -> HashAggregate (cost=1184088.58..1184125.66 rows=3708 width=12) (actual time=8392.728..8417.045 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=171604 read=495665 written=243 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47456.80..1161563.47 rows=2252511 width=12) (actual time=895.795..6739.184 rows=2246253 loops=1) Recheck Cond: ((l_shipdate >= '1996-11-01'::date) AND (l_shipdate < '1997-01-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=661131 Buffers: shared hit=171604 read=495665 written=243 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46893.68 rows=2252511 width=0) (actual time=668.568..668.568 rows=2275748 loops=1) Index Cond: ((l_shipdate >= '1996-11-01'::date) AND (l_shipdate < '1997-01-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6138 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.069..19.634 rows=49906 loops=1) Buffers: shared hit=1340 read=23 -> Sort (cost=1201285.66..1201294.93 rows=3708 width=12) (actual time=16827.742..16827.743 rows=1 loops=1) Sort Key: revenue12.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=509345 read=825193 dirtied=692 written=440 -> Subquery Scan on revenue12 (cost=1200982.41..1201065.84 rows=3708 width=12) (actual time=16819.804..16827.704 rows=1 loops=1) Buffers: shared hit=509345 read=825193 dirtied=692 written=440 -> HashAggregate (cost=1200982.41..1201028.76 rows=3708 width=12) (actual time=16819.803..16827.701 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=509345 read=825193 dirtied=692 written=440 -> Bitmap Heap Scan on lineitem (cost=47456.80..1161563.47 rows=2252511 width=12) (actual time=1089.613..6662.447 rows=2246253 loops=1) Recheck Cond: ((l_shipdate >= '1996-11-01'::date) AND (l_shipdate < '1997-01-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=661131 Buffers: shared hit=337741 read=329528 dirtied=692 written=197 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46893.68 rows=2252511 width=0) (actual time=821.559..821.559 rows=2275748 loops=1) Index Cond: ((l_shipdate >= '1996-11-01'::date) AND (l_shipdate < '1997-01-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6138 Planning time: 2.554 ms Execution time: 16859.043 ms (38 rows) drop view revenue12; DROP VIEW COMMIT; COMMIT