BEGIN; BEGIN create or replace view revenue8 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1994-12-01' and l_shipdate < date'1994-12-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, revenue8 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue8 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2365582.66..2370680.71 rows=3790 width=79) (actual time=19876.042..19876.047 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue8.supplier_no) Buffers: shared hit=737285 read=584823 written=59 InitPlan 1 (returns $0) -> Aggregate (cost=1174118.86..1174118.87 rows=1 width=8) (actual time=9119.331..9119.331 rows=1 loops=1) Buffers: shared hit=375055 read=285492 written=59 -> HashAggregate (cost=1174033.58..1174071.48 rows=3790 width=12) (actual time=9070.125..9109.126 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=375055 read=285492 written=59 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=48361.03..1151207.76 rows=2282582 width=12) (actual time=1473.146..7177.296 rows=2248267 loops=1) Recheck Cond: ((l_shipdate >= '1994-12-01'::date) AND (l_shipdate < '1995-03-01 00:00:00'::timestamp without time zone)) Heap Blocks: exact=654406 Buffers: shared hit=375055 read=285492 written=59 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47790.39 rows=2282582 width=0) (actual time=1091.962..1091.962 rows=2252875 loops=1) Index Cond: ((l_shipdate >= '1994-12-01'::date) AND (l_shipdate < '1995-03-01 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.031..13.612 rows=37000 loops=1) Buffers: shared hit=1014 -> Sort (cost=1191463.50..1191472.97 rows=3790 width=12) (actual time=19858.753..19858.755 rows=1 loops=1) Sort Key: revenue8.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=736271 read=584823 written=59 -> Subquery Scan on revenue8 (cost=1191152.95..1191238.22 rows=3790 width=12) (actual time=19858.519..19858.708 rows=1 loops=1) Buffers: shared hit=736271 read=584823 written=59 -> HashAggregate (cost=1191152.95..1191200.32 rows=3790 width=12) (actual time=19858.517..19858.705 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=736271 read=584823 written=59 -> Bitmap Heap Scan on lineitem (cost=48361.03..1151207.76 rows=2282582 width=12) (actual time=1297.661..8198.771 rows=2248267 loops=1) Recheck Cond: ((l_shipdate >= '1994-12-01'::date) AND (l_shipdate < '1995-03-01 00:00:00'::timestamp without time zone)) Heap Blocks: exact=654406 Buffers: shared hit=361216 read=299331 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47790.39 rows=2282582 width=0) (actual time=997.807..997.807 rows=2252875 loops=1) Index Cond: ((l_shipdate >= '1994-12-01'::date) AND (l_shipdate < '1995-03-01 00:00:00'::timestamp without time zone)) Buffers: shared read=6141 Planning time: 2.782 ms Execution time: 19892.498 ms (38 rows) drop view revenue8; DROP VIEW COMMIT; COMMIT