BEGIN; BEGIN create or replace view revenue1 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1996-09-01' and l_shipdate < date'1996-09-01' + interval '90 days' group by l_suppkey; CREATE VIEW EXPLAIN select s_suppkey, s_name, s_address, s_phone, total_revenue from supplier, revenue1 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue1 ) order by s_suppkey; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------ Nested Loop (cost=3265463.82..3294563.51 rows=497 width=104) InitPlan 1 (returns $1) -> Aggregate (cost=1646306.85..1646306.86 rows=1 width=32) -> Finalize GroupAggregate (cost=1619156.67..1645065.30 rows=99324 width=36) Group Key: lineitem_1.l_suppkey -> Gather Merge (cost=1619156.67..1642333.89 rows=198648 width=36) Workers Planned: 2 -> Sort (cost=1618156.65..1618404.96 rows=99324 width=36) Sort Key: lineitem_1.l_suppkey -> Partial HashAggregate (cost=1596706.47..1607196.83 rows=99324 width=36) Group Key: lineitem_1.l_suppkey Planned Partitions: 8 -> Parallel Seq Scan on lineitem lineitem_1 (cost=0.00..1531298.89 rows=947078 width=16) Filter: ((l_shipdate >= '1996-09-01'::date) AND (l_shipdate < '1996-11-30 00:00:00'::timestamp without time zone)) -> Finalize GroupAggregate (cost=1619156.67..1645313.61 rows=497 width=36) Group Key: lineitem.l_suppkey Filter: (sum((lineitem.l_extendedprice * ('1'::numeric - lineitem.l_discount))) = $1) -> Gather Merge (cost=1619156.67..1642333.89 rows=198648 width=36) Workers Planned: 2 -> Sort (cost=1618156.65..1618404.96 rows=99324 width=36) Sort Key: lineitem.l_suppkey -> Partial HashAggregate (cost=1596706.47..1607196.83 rows=99324 width=36) Group Key: lineitem.l_suppkey Planned Partitions: 8 -> Parallel Seq Scan on lineitem (cost=0.00..1531298.89 rows=947078 width=16) Filter: ((l_shipdate >= '1996-09-01'::date) AND (l_shipdate < '1996-11-30 00:00:00'::timestamp without time zone)) -> Index Scan using pk_supplier on supplier (cost=0.29..5.91 rows=1 width=72) Index Cond: (s_suppkey = lineitem.l_suppkey) (28 rows) drop view revenue1; DROP VIEW COMMIT; COMMIT