BEGIN; BEGIN create or replace view revenue2 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1995-06-01' and l_shipdate < date'1995-06-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, revenue2 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue2 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2369842.62..2374940.70 rows=3792 width=79) (actual time=19431.967..19431.972 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue2.supplier_no) Buffers: shared hit=680392 read=643908 written=21416 InitPlan 1 (returns $0) -> Aggregate (cost=1176245.13..1176245.14 rows=1 width=8) (actual time=10838.495..10838.495 rows=1 loops=1) Buffers: shared hit=299256 read=361933 written=21345 -> HashAggregate (cost=1176159.81..1176197.73 rows=3792 width=12) (actual time=10757.225..10827.941 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=299256 read=361933 written=21345 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=48330.98..1153324.28 rows=2283553 width=12) (actual time=1176.052..7961.141 rows=2246423 loops=1) Recheck Cond: ((l_shipdate >= '1995-06-01'::date) AND (l_shipdate < '1995-08-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=655054 Buffers: shared hit=299256 read=361933 written=21345 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47760.10 rows=2283553 width=0) (actual time=879.192..879.192 rows=2255550 loops=1) Index Cond: ((l_shipdate >= '1995-06-01'::date) AND (l_shipdate < '1995-08-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6135 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.029..26.927 rows=70652 loops=1) Buffers: shared hit=1922 -> Sort (cost=1193597.19..1193606.67 rows=3792 width=12) (actual time=19397.856..19397.858 rows=1 loops=1) Sort Key: revenue2.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=678470 read=643908 written=21416 -> Subquery Scan on revenue2 (cost=1193286.46..1193371.78 rows=3792 width=12) (actual time=19374.253..19397.827 rows=1 loops=1) Buffers: shared hit=678470 read=643908 written=21416 -> HashAggregate (cost=1193286.46..1193333.86 rows=3792 width=12) (actual time=19374.252..19397.826 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=678470 read=643908 written=21416 -> Bitmap Heap Scan on lineitem (cost=48330.98..1153324.28 rows=2283553 width=12) (actual time=1277.923..6757.458 rows=2246423 loops=1) Recheck Cond: ((l_shipdate >= '1995-06-01'::date) AND (l_shipdate < '1995-08-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=655054 Buffers: shared hit=379214 read=281975 written=71 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47760.10 rows=2283553 width=0) (actual time=968.057..968.057 rows=2255550 loops=1) Index Cond: ((l_shipdate >= '1995-06-01'::date) AND (l_shipdate < '1995-08-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6135 Planning time: 2.534 ms Execution time: 19445.335 ms (38 rows) drop view revenue2; DROP VIEW COMMIT; COMMIT