BEGIN; BEGIN create or replace view revenue9 (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, revenue9 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue9 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2373560.43..2378658.21 rows=3772 width=79) (actual time=23208.516..23208.521 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue9.supplier_no) Buffers: shared hit=645472 read=683147 dirtied=288 written=11024 InitPlan 1 (returns $0) -> Aggregate (cost=1178120.08..1178120.09 rows=1 width=8) (actual time=11635.865..11635.865 rows=1 loops=1) Buffers: shared hit=340674 read=322494 dirtied=2 written=10903 -> HashAggregate (cost=1178035.21..1178072.93 rows=3772 width=12) (actual time=11593.342..11625.507 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=340674 read=322494 dirtied=2 written=10903 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=48192.94..1155240.70 rows=2279451 width=12) (actual time=3509.056..9655.159 rows=2249916 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=657022 Buffers: shared hit=340674 read=322494 dirtied=2 written=10903 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47623.08 rows=2279451 width=0) (actual time=3041.254..3041.254 rows=2263284 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 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.033..31.151 rows=83967 loops=1) Buffers: shared hit=2283 -> Sort (cost=1195440.04..1195449.47 rows=3772 width=12) (actual time=23168.971..23168.973 rows=1 loops=1) Sort Key: revenue9.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=643189 read=683147 dirtied=288 written=11024 -> Subquery Scan on revenue9 (cost=1195131.10..1195215.97 rows=3772 width=12) (actual time=23126.319..23168.932 rows=1 loops=1) Buffers: shared hit=643189 read=683147 dirtied=288 written=11024 -> HashAggregate (cost=1195131.10..1195178.25 rows=3772 width=12) (actual time=23126.317..23168.927 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=643189 read=683147 dirtied=288 written=11024 -> Bitmap Heap Scan on lineitem (cost=48192.94..1155240.70 rows=2279451 width=12) (actual time=1248.844..8964.999 rows=2249916 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=657022 Buffers: shared hit=302515 read=360653 dirtied=286 written=121 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47623.08 rows=2279451 width=0) (actual time=977.252..977.252 rows=2263284 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=10 Planning time: 3.128 ms Execution time: 23224.324 ms (38 rows) drop view revenue9; DROP VIEW COMMIT; COMMIT