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 >= '1996-07-01' and l_shipdate < date'1996-07-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=2361753.57..2366851.37 rows=3773 width=79) (actual time=20822.662..20822.665 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue10.supplier_no) Buffers: shared hit=687363 read=631788 dirtied=369 written=148 InitPlan 1 (returns $0) -> Aggregate (cost=1172270.61..1172270.62 rows=1 width=8) (actual time=10211.510..10211.510 rows=1 loops=1) Buffers: shared hit=328910 read=329834 written=93 -> HashAggregate (cost=1172185.72..1172223.45 rows=3773 width=12) (actual time=10168.338..10201.850 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=328910 read=329834 written=93 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=48013.37..1149535.18 rows=2265054 width=12) (actual time=2297.700..8267.825 rows=2245981 loops=1) Recheck Cond: ((l_shipdate >= '1996-07-01'::date) AND (l_shipdate < '1996-09-29 00:00:00'::timestamp without time zone)) Heap Blocks: exact=652610 Buffers: shared hit=328910 read=329834 written=93 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47447.11 rows=2265054 width=0) (actual time=1797.697..1797.697 rows=2248171 loops=1) Index Cond: ((l_shipdate >= '1996-07-01'::date) AND (l_shipdate < '1996-09-29 00:00:00'::timestamp without time zone)) Buffers: shared read=6134 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.030..24.743 rows=60982 loops=1) Buffers: shared hit=1663 -> Sort (cost=1189482.66..1189492.09 rows=3773 width=12) (actual time=20792.185..20792.187 rows=1 loops=1) Sort Key: revenue10.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=685700 read=631788 dirtied=369 written=148 -> Subquery Scan on revenue10 (cost=1189173.62..1189258.52 rows=3773 width=12) (actual time=20762.836..20792.154 rows=1 loops=1) Buffers: shared hit=685700 read=631788 dirtied=369 written=148 -> HashAggregate (cost=1189173.62..1189220.79 rows=3773 width=12) (actual time=20762.836..20792.153 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=685700 read=631788 dirtied=369 written=148 -> Bitmap Heap Scan on lineitem (cost=48013.37..1149535.18 rows=2265054 width=12) (actual time=1728.203..8165.565 rows=2245981 loops=1) Recheck Cond: ((l_shipdate >= '1996-07-01'::date) AND (l_shipdate < '1996-09-29 00:00:00'::timestamp without time zone)) Heap Blocks: exact=652610 Buffers: shared hit=356790 read=301954 dirtied=369 written=55 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47447.11 rows=2265054 width=0) (actual time=1314.346..1314.346 rows=2248171 loops=1) Index Cond: ((l_shipdate >= '1996-07-01'::date) AND (l_shipdate < '1996-09-29 00:00:00'::timestamp without time zone)) Buffers: shared read=6134 written=55 Planning time: 2.658 ms Execution time: 20844.521 ms (38 rows) drop view revenue10; DROP VIEW COMMIT; COMMIT