BEGIN; BEGIN create or replace view revenue13 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1995-09-01' and l_shipdate < date'1995-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, revenue13 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue13 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2380782.26..2385878.39 rows=3662 width=79) (actual time=17618.786..17618.790 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue13.supplier_no) Buffers: shared hit=860687 read=475436 dirtied=384 written=4226 InitPlan 1 (returns $0) -> Aggregate (cost=1181933.60..1181933.61 rows=1 width=8) (actual time=8695.569..8695.569 rows=1 loops=1) Buffers: shared hit=395416 read=271316 dirtied=384 written=4217 -> HashAggregate (cost=1181851.20..1181887.82 rows=3662 width=12) (actual time=8629.032..8679.674 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=395416 read=271316 dirtied=384 written=4217 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=46929.18..1159587.19 rows=2226401 width=12) (actual time=1166.546..6627.171 rows=2247372 loops=1) Recheck Cond: ((l_shipdate >= '1995-09-01'::date) AND (l_shipdate < '1995-11-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=660593 Buffers: shared hit=395416 read=271316 dirtied=384 written=4217 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46372.58 rows=2226401 width=0) (actual time=904.578..904.578 rows=2274550 loops=1) Index Cond: ((l_shipdate >= '1995-09-01'::date) AND (l_shipdate < '1995-11-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=1 read=6138 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.031..44.430 rows=97885 loops=1) Buffers: shared hit=2658 read=1 -> Sort (cost=1198848.36..1198857.52 rows=3662 width=12) (actual time=17560.162..17560.163 rows=1 loops=1) Sort Key: revenue13.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=858029 read=475435 dirtied=384 written=4226 -> Subquery Scan on revenue13 (cost=1198549.21..1198631.60 rows=3662 width=12) (actual time=17543.411..17560.126 rows=1 loops=1) Buffers: shared hit=858029 read=475435 dirtied=384 written=4226 -> HashAggregate (cost=1198549.21..1198594.98 rows=3662 width=12) (actual time=17543.409..17560.122 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=858029 read=475435 dirtied=384 written=4226 -> Bitmap Heap Scan on lineitem (cost=46929.18..1159587.19 rows=2226401 width=12) (actual time=1439.021..6925.532 rows=2247372 loops=1) Recheck Cond: ((l_shipdate >= '1995-09-01'::date) AND (l_shipdate < '1995-11-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=660593 Buffers: shared hit=462613 read=204119 written=9 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46372.58 rows=2226401 width=0) (actual time=1140.749..1140.749 rows=2274550 loops=1) Index Cond: ((l_shipdate >= '1995-09-01'::date) AND (l_shipdate < '1995-11-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=1 read=6138 written=5 Planning time: 2.504 ms Execution time: 17629.899 ms (38 rows) drop view revenue13; DROP VIEW COMMIT; COMMIT