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 >= '1994-04-01' and l_shipdate < date'1994-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, revenue2 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue2 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2360762.97..2365859.82 rows=3710 width=79) (actual time=17767.291..17767.295 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue2.supplier_no) Buffers: shared hit=198552 read=1122207 dirtied=591 written=225 InitPlan 1 (returns $0) -> Aggregate (cost=1171892.19..1171892.20 rows=1 width=8) (actual time=7860.262..7860.262 rows=1 loops=1) Buffers: shared hit=107360 read=552282 -> HashAggregate (cost=1171808.72..1171845.82 rows=3710 width=12) (actual time=7827.443..7850.720 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=107360 read=552282 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47339.62..1149464.28 rows=2234444 width=12) (actual time=1153.204..6171.823 rows=2243386 loops=1) Recheck Cond: ((l_shipdate >= '1994-04-01'::date) AND (l_shipdate < '1994-06-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=653508 Buffers: shared hit=107360 read=552282 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46781.01 rows=2234444 width=0) (actual time=856.798..856.798 rows=2250325 loops=1) Index Cond: ((l_shipdate >= '1994-04-01'::date) AND (l_shipdate < '1994-06-30 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.034..20.054 rows=53995 loops=1) Buffers: shared hit=1474 read=1 -> Sort (cost=1188870.47..1188879.75 rows=3710 width=12) (actual time=17742.355..17742.356 rows=1 loops=1) Sort Key: revenue2.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=197078 read=1122206 dirtied=591 written=225 -> Subquery Scan on revenue2 (cost=1188567.05..1188650.52 rows=3710 width=12) (actual time=17736.704..17742.316 rows=1 loops=1) Buffers: shared hit=197078 read=1122206 dirtied=591 written=225 -> HashAggregate (cost=1188567.05..1188613.42 rows=3710 width=12) (actual time=17736.703..17742.315 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=197078 read=1122206 dirtied=591 written=225 -> Bitmap Heap Scan on lineitem (cost=47339.62..1149464.28 rows=2234444 width=12) (actual time=1276.453..8007.177 rows=2243386 loops=1) Recheck Cond: ((l_shipdate >= '1994-04-01'::date) AND (l_shipdate < '1994-06-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=653508 Buffers: shared hit=89718 read=569924 dirtied=591 written=225 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46781.01 rows=2234444 width=0) (actual time=973.721..973.721 rows=2250325 loops=1) Index Cond: ((l_shipdate >= '1994-04-01'::date) AND (l_shipdate < '1994-06-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6134 Planning time: 2.290 ms Execution time: 17773.904 ms (38 rows) drop view revenue2; DROP VIEW COMMIT; COMMIT