BEGIN; BEGIN create or replace view revenue7 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1993-09-01' and l_shipdate < date'1993-09-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, revenue7 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue7 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2385129.99..2390227.29 rows=3740 width=79) (actual time=18824.114..18824.119 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue7.supplier_no) Buffers: shared hit=576221 read=758745 written=54 InitPlan 1 (returns $0) -> Aggregate (cost=1183941.64..1183941.65 rows=1 width=8) (actual time=8567.924..8567.924 rows=1 loops=1) Buffers: shared hit=285112 read=381379 -> HashAggregate (cost=1183857.49..1183894.89 rows=3740 width=12) (actual time=8526.227..8557.593 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=285112 read=381379 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47847.32..1161158.22 rows=2269927 width=12) (actual time=1333.518..6725.915 rows=2249633 loops=1) Recheck Cond: ((l_shipdate >= '1993-09-01'::date) AND (l_shipdate < '1993-11-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=660350 Buffers: shared hit=285112 read=381379 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47279.84 rows=2269927 width=0) (actual time=1018.294..1018.294 rows=2275805 loops=1) Index Cond: ((l_shipdate >= '1993-09-01'::date) AND (l_shipdate < '1993-11-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6141 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.038..28.013 rows=72980 loops=1) Buffers: shared hit=1984 -> Sort (cost=1201188.04..1201197.39 rows=3740 width=12) (actual time=18789.099..18789.101 rows=1 loops=1) Sort Key: revenue7.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=574237 read=758745 written=54 -> Subquery Scan on revenue7 (cost=1200881.94..1200966.09 rows=3740 width=12) (actual time=18760.871..18789.057 rows=1 loops=1) Buffers: shared hit=574237 read=758745 written=54 -> HashAggregate (cost=1200881.94..1200928.69 rows=3740 width=12) (actual time=18760.870..18789.055 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=574237 read=758745 written=54 -> Bitmap Heap Scan on lineitem (cost=47847.32..1161158.22 rows=2269927 width=12) (actual time=1375.657..7631.762 rows=2249633 loops=1) Recheck Cond: ((l_shipdate >= '1993-09-01'::date) AND (l_shipdate < '1993-11-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=660350 Buffers: shared hit=289125 read=377366 written=54 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47279.84 rows=2269927 width=0) (actual time=1020.847..1020.847 rows=2275805 loops=1) Index Cond: ((l_shipdate >= '1993-09-01'::date) AND (l_shipdate < '1993-11-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6141 Planning time: 2.958 ms Execution time: 18838.371 ms (38 rows) drop view revenue7; DROP VIEW COMMIT; COMMIT