BEGIN; BEGIN create or replace view revenue22 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1995-02-01' and l_shipdate < date'1995-02-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, revenue22 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue22 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2382292.85..2387391.05 rows=3800 width=79) (actual time=25709.811..25709.816 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue22.supplier_no) Buffers: shared hit=581326 read=751167 dirtied=442 written=9865 InitPlan 1 (returns $0) -> Aggregate (cost=1182391.65..1182391.66 rows=1 width=8) (actual time=12447.642..12447.642 rows=1 loops=1) Buffers: shared hit=297784 read=367321 written=377 -> HashAggregate (cost=1182306.15..1182344.15 rows=3800 width=12) (actual time=12331.170..12436.247 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=297784 read=367321 written=377 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=48649.10..1159261.73 rows=2304442 width=12) (actual time=1818.847..9260.548 rows=2247378 loops=1) Recheck Cond: ((l_shipdate >= '1995-02-01'::date) AND (l_shipdate < '1995-05-02 00:00:00'::timestamp without time zone)) Heap Blocks: exact=658959 Buffers: shared hit=297784 read=367321 written=377 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..48072.99 rows=2304442 width=0) (actual time=1504.104..1504.104 rows=2272240 loops=1) Index Cond: ((l_shipdate >= '1995-02-01'::date) AND (l_shipdate < '1995-05-02 00:00:00'::timestamp without time zone)) Buffers: shared read=6146 written=14 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.031..37.626 rows=83967 loops=1) Buffers: shared hit=2283 -> Sort (cost=1199900.90..1199910.40 rows=3800 width=12) (actual time=25663.284..25663.287 rows=1 loops=1) Sort Key: revenue22.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=579043 read=751167 dirtied=442 written=9865 -> Subquery Scan on revenue22 (cost=1199589.46..1199674.96 rows=3800 width=12) (actual time=25625.715..25663.242 rows=1 loops=1) Buffers: shared hit=579043 read=751167 dirtied=442 written=9865 -> HashAggregate (cost=1199589.46..1199636.96 rows=3800 width=12) (actual time=25625.713..25663.239 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=579043 read=751167 dirtied=442 written=9865 -> Bitmap Heap Scan on lineitem (cost=48649.10..1159261.73 rows=2304442 width=12) (actual time=1624.961..10196.398 rows=2247378 loops=1) Recheck Cond: ((l_shipdate >= '1995-02-01'::date) AND (l_shipdate < '1995-05-02 00:00:00'::timestamp without time zone)) Heap Blocks: exact=658959 Buffers: shared hit=281259 read=383846 dirtied=442 written=9488 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..48072.99 rows=2304442 width=0) (actual time=1270.777..1270.777 rows=2269909 loops=1) Index Cond: ((l_shipdate >= '1995-02-01'::date) AND (l_shipdate < '1995-05-02 00:00:00'::timestamp without time zone)) Buffers: shared read=6146 written=11 Planning time: 3.027 ms Execution time: 25725.024 ms (38 rows) drop view revenue22; DROP VIEW COMMIT; COMMIT