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 >= '1993-05-01' and l_shipdate < date'1993-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, revenue10 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue10 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2363361.47..2368459.55 rows=3792 width=79) (actual time=20369.767..20369.774 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue10.supplier_no) Buffers: shared hit=988572 read=333191 dirtied=342 written=21 InitPlan 1 (returns $0) -> Aggregate (cost=1173013.65..1173013.66 rows=1 width=8) (actual time=11072.432..11072.432 rows=1 loops=1) Buffers: shared hit=430623 read=229118 written=2 -> HashAggregate (cost=1172928.33..1172966.25 rows=3792 width=12) (actual time=10984.892..11061.412 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=430623 read=229118 written=2 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=48354.13..1150117.05 rows=2281128 width=12) (actual time=1730.052..7985.024 rows=2248696 loops=1) Recheck Cond: ((l_shipdate >= '1993-05-01'::date) AND (l_shipdate < '1993-07-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=653600 Buffers: shared hit=430623 read=229118 written=2 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47783.85 rows=2281128 width=0) (actual time=1345.741..1345.741 rows=2250934 loops=1) Index Cond: ((l_shipdate >= '1993-05-01'::date) AND (l_shipdate < '1993-07-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6141 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.040..34.984 rows=83935 loops=1) Buffers: shared hit=2281 -> Sort (cost=1190347.52..1190357.00 rows=3792 width=12) (actual time=20326.068..20326.070 rows=1 loops=1) Sort Key: revenue10.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=986291 read=333191 dirtied=342 written=21 -> Subquery Scan on revenue10 (cost=1190036.79..1190122.11 rows=3792 width=12) (actual time=20319.724..20326.025 rows=1 loops=1) Buffers: shared hit=986291 read=333191 dirtied=342 written=21 -> HashAggregate (cost=1190036.79..1190084.19 rows=3792 width=12) (actual time=20319.722..20326.019 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=986291 read=333191 dirtied=342 written=21 -> Bitmap Heap Scan on lineitem (cost=48354.13..1150117.05 rows=2281128 width=12) (actual time=1823.979..7014.207 rows=2248696 loops=1) Recheck Cond: ((l_shipdate >= '1993-05-01'::date) AND (l_shipdate < '1993-07-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=653600 Buffers: shared hit=555668 read=104073 dirtied=342 written=19 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47783.85 rows=2281128 width=0) (actual time=1432.507..1432.507 rows=2250934 loops=1) Index Cond: ((l_shipdate >= '1993-05-01'::date) AND (l_shipdate < '1993-07-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=2 read=6139 Planning time: 3.698 ms Execution time: 20379.755 ms (38 rows) drop view revenue10; DROP VIEW COMMIT; COMMIT