BEGIN; BEGIN create or replace view revenue30 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1996-04-01' and l_shipdate < date'1996-04-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, revenue30 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue30 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2383025.51..2388123.79 rows=3805 width=79) (actual time=24687.300..24687.303 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue30.supplier_no) Buffers: shared hit=730925 read=598678 dirtied=67 written=5565 InitPlan 1 (returns $0) -> Aggregate (cost=1182745.40..1182745.41 rows=1 width=8) (actual time=11754.065..11754.066 rows=1 loops=1) Buffers: shared hit=283830 read=380411 written=309 -> HashAggregate (cost=1182659.79..1182697.84 rows=3805 width=12) (actual time=11690.661..11743.186 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=283830 read=380411 written=309 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=48715.01..1159582.28 rows=2307751 width=12) (actual time=1482.422..8914.716 rows=2244427 loops=1) Recheck Cond: ((l_shipdate >= '1996-04-01'::date) AND (l_shipdate < '1996-06-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=658106 Buffers: shared hit=283830 read=380411 written=309 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..48138.08 rows=2307751 width=0) (actual time=1138.859..1138.859 rows=2268788 loops=1) Index Cond: ((l_shipdate >= '1996-04-01'::date) AND (l_shipdate < '1996-06-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6135 written=13 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.039..16.856 rows=40980 loops=1) Buffers: shared hit=1121 -> Sort (cost=1200279.81..1200289.32 rows=3805 width=12) (actual time=24666.126..24666.127 rows=1 loops=1) Sort Key: revenue30.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=729804 read=598678 dirtied=67 written=5565 -> Subquery Scan on revenue30 (cost=1199967.92..1200053.53 rows=3805 width=12) (actual time=24654.229..24666.092 rows=1 loops=1) Buffers: shared hit=729804 read=598678 dirtied=67 written=5565 -> HashAggregate (cost=1199967.92..1200015.48 rows=3805 width=12) (actual time=24654.227..24666.086 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=729804 read=598678 dirtied=67 written=5565 -> Bitmap Heap Scan on lineitem (cost=48715.01..1159582.28 rows=2307751 width=12) (actual time=1932.254..9386.246 rows=2244427 loops=1) Recheck Cond: ((l_shipdate >= '1996-04-01'::date) AND (l_shipdate < '1996-06-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=658106 Buffers: shared hit=445974 read=218267 dirtied=67 written=5256 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..48138.08 rows=2307751 width=0) (actual time=1496.236..1496.236 rows=2267272 loops=1) Index Cond: ((l_shipdate >= '1996-04-01'::date) AND (l_shipdate < '1996-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=428 read=5707 written=244 Planning time: 3.367 ms Execution time: 24704.372 ms (38 rows) drop view revenue30; DROP VIEW COMMIT; COMMIT