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 >= '1993-07-01' and l_shipdate < date'1993-07-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=2363184.44..2368281.97 rows=3755 width=79) (actual time=22683.119..22683.124 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue8.supplier_no) Buffers: shared hit=603581 read=717989 InitPlan 1 (returns $0) -> Aggregate (cost=1173010.64..1173010.65 rows=1 width=8) (actual time=12458.500..12458.500 rows=1 loops=1) Buffers: shared hit=257758 read=402264 -> HashAggregate (cost=1172926.15..1172963.70 rows=3755 width=12) (actual time=12374.715..12447.908 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=257758 read=402264 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47851.78..1150339.60 rows=2258655 width=12) (actual time=2094.796..9185.976 rows=2249302 loops=1) Recheck Cond: ((l_shipdate >= '1993-07-01'::date) AND (l_shipdate < '1993-09-29 00:00:00'::timestamp without time zone)) Heap Blocks: exact=653879 Buffers: shared hit=257758 read=402264 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47287.12 rows=2258655 width=0) (actual time=1631.708..1631.708 rows=2253609 loops=1) Index Cond: ((l_shipdate >= '1993-07-01'::date) AND (l_shipdate < '1993-09-29 00:00:00'::timestamp without time zone)) Buffers: shared read=6143 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.034..23.434 rows=55988 loops=1) Buffers: shared hit=1526 -> Sort (cost=1190173.50..1190182.89 rows=3755 width=12) (actual time=22653.967..22653.970 rows=1 loops=1) Sort Key: revenue8.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=602055 read=717989 -> Subquery Scan on revenue8 (cost=1189866.07..1189950.55 rows=3755 width=12) (actual time=22632.404..22653.935 rows=1 loops=1) Buffers: shared hit=602055 read=717989 -> HashAggregate (cost=1189866.07..1189913.00 rows=3755 width=12) (actual time=22632.403..22653.932 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=602055 read=717989 -> Bitmap Heap Scan on lineitem (cost=47851.78..1150339.60 rows=2258655 width=12) (actual time=1325.456..8283.093 rows=2249302 loops=1) Recheck Cond: ((l_shipdate >= '1993-07-01'::date) AND (l_shipdate < '1993-09-29 00:00:00'::timestamp without time zone)) Heap Blocks: exact=653879 Buffers: shared hit=344297 read=315725 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47287.12 rows=2258655 width=0) (actual time=1013.601..1013.601 rows=2253609 loops=1) Index Cond: ((l_shipdate >= '1993-07-01'::date) AND (l_shipdate < '1993-09-29 00:00:00'::timestamp without time zone)) Buffers: shared read=6143 Planning time: 2.622 ms Execution time: 22702.723 ms (38 rows) drop view revenue8; DROP VIEW COMMIT; COMMIT