BEGIN; BEGIN create or replace view revenue0 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1993-11-01' and l_shipdate < date'1993-11-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, revenue0 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue0 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2353082.26..2358178.35 rows=3659 width=79) (actual time=16477.278..16477.279 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue0.supplier_no) Buffers: shared hit=306917 read=1009734 written=10 InitPlan 1 (returns $0) -> Aggregate (cost=1168185.12..1168185.13 rows=1 width=8) (actual time=6378.326..6378.326 rows=1 loops=1) Buffers: shared hit=304719 read=353496 written=10 -> HashAggregate (cost=1168102.79..1168139.38 rows=3659 width=12) (actual time=6348.605..6369.058 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=304719 read=353496 written=10 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=46643.94..1146109.25 rows=2199354 width=12) (actual time=832.322..4914.577 rows=2244040 loops=1) Recheck Cond: ((l_shipdate >= '1993-11-01'::date) AND (l_shipdate < '1994-01-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=652086 Buffers: shared hit=304719 read=353496 written=10 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46094.11 rows=2199354 width=0) (actual time=617.691..617.691 rows=2244040 loops=1) Index Cond: ((l_shipdate >= '1993-11-01'::date) AND (l_shipdate < '1994-01-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6129 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.047..3.547 rows=7917 loops=1) Buffers: shared hit=28 read=193 -> Sort (cost=1184896.84..1184905.99 rows=3659 width=12) (actual time=16473.010..16473.010 rows=1 loops=1) Sort Key: revenue0.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=306889 read=1009541 written=10 -> Subquery Scan on revenue0 (cost=1184597.95..1184680.28 rows=3659 width=12) (actual time=16471.388..16472.956 rows=1 loops=1) Buffers: shared hit=306889 read=1009541 written=10 -> HashAggregate (cost=1184597.95..1184643.69 rows=3659 width=12) (actual time=16471.386..16472.953 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=306889 read=1009541 written=10 -> Bitmap Heap Scan on lineitem (cost=46643.94..1146109.25 rows=2199354 width=12) (actual time=929.826..8363.915 rows=2244040 loops=1) Recheck Cond: ((l_shipdate >= '1993-11-01'::date) AND (l_shipdate < '1994-01-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=652086 Buffers: shared hit=2170 read=656045 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46094.11 rows=2199354 width=0) (actual time=714.023..714.023 rows=2244040 loops=1) Index Cond: ((l_shipdate >= '1993-11-01'::date) AND (l_shipdate < '1994-01-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6129 Planning time: 4.569 ms Execution time: 16483.213 ms (38 rows) drop view revenue0; DROP VIEW COMMIT; COMMIT