BEGIN; BEGIN create or replace view revenue4 (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, revenue4 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue4 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2366927.72..2372026.23 rows=3821 width=79) (actual time=19989.051..19989.057 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue4.supplier_no) Buffers: shared hit=797067 read=525988 dirtied=357 written=2861 InitPlan 1 (returns $0) -> Aggregate (cost=1174738.45..1174738.46 rows=1 width=8) (actual time=9469.642..9469.642 rows=1 loops=1) Buffers: shared hit=325621 read=334577 written=19 -> HashAggregate (cost=1174652.48..1174690.69 rows=3821 width=12) (actual time=9422.095..9459.506 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=325621 read=334577 written=19 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=48654.90..1151688.25 rows=2296423 width=12) (actual time=1253.864..7358.920 rows=2245417 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=654059 Buffers: shared hit=325621 read=334577 written=19 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..48080.79 rows=2296423 width=0) (actual time=931.747..931.747 rows=2252136 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 read=6139 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.032..40.605 rows=97885 loops=1) Buffers: shared hit=2659 -> Sort (cost=1192188.97..1192198.52 rows=3821 width=12) (actual time=19938.846..19938.848 rows=1 loops=1) Sort Key: revenue4.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=794408 read=525988 dirtied=357 written=2861 -> Subquery Scan on revenue4 (cost=1191875.65..1191961.62 rows=3821 width=12) (actual time=19912.983..19938.813 rows=1 loops=1) Buffers: shared hit=794408 read=525988 dirtied=357 written=2861 -> HashAggregate (cost=1191875.65..1191923.41 rows=3821 width=12) (actual time=19912.981..19938.808 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=794408 read=525988 dirtied=357 written=2861 -> Bitmap Heap Scan on lineitem (cost=48654.90..1151688.25 rows=2296423 width=12) (actual time=1237.254..7452.400 rows=2245417 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=654059 Buffers: shared hit=468787 read=191411 dirtied=357 written=2842 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..48080.79 rows=2296423 width=0) (actual time=949.679..949.679 rows=2252132 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=478 read=5661 written=333 Planning time: 2.392 ms Execution time: 20011.061 ms (38 rows) drop view revenue4; DROP VIEW COMMIT; COMMIT