BEGIN; BEGIN create or replace view revenue0 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1994-02-01' and l_shipdate < date'1994-02-01' + interval '90 days' group by l_suppkey; CREATE VIEW EXPLAIN select s_suppkey, s_name, s_address, s_phone, total_revenue from supplier, revenue0 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue0 ) order by s_suppkey; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------ Nested Loop (cost=3267723.80..3296823.49 rows=497 width=104) InitPlan 1 (returns $1) -> Aggregate (cost=1647436.84..1647436.85 rows=1 width=32) -> Finalize GroupAggregate (cost=1620286.66..1646195.29 rows=99324 width=36) Group Key: lineitem_1.l_suppkey -> Gather Merge (cost=1620286.66..1643463.88 rows=198648 width=36) Workers Planned: 2 -> Sort (cost=1619286.64..1619534.95 rows=99324 width=36) Sort Key: lineitem_1.l_suppkey -> Partial HashAggregate (cost=1597508.25..1608326.82 rows=99324 width=36) Group Key: lineitem_1.l_suppkey Planned Partitions: 8 -> Parallel Seq Scan on lineitem lineitem_1 (cost=0.00..1529779.55 rows=980687 width=16) Filter: ((l_shipdate >= '1994-02-01'::date) AND (l_shipdate < '1994-05-02 00:00:00'::timestamp without time zone)) -> Finalize GroupAggregate (cost=1620286.66..1646443.60 rows=497 width=36) Group Key: lineitem.l_suppkey Filter: (sum((lineitem.l_extendedprice * ('1'::numeric - lineitem.l_discount))) = $1) -> Gather Merge (cost=1620286.66..1643463.88 rows=198648 width=36) Workers Planned: 2 -> Sort (cost=1619286.64..1619534.95 rows=99324 width=36) Sort Key: lineitem.l_suppkey -> Partial HashAggregate (cost=1597508.25..1608326.82 rows=99324 width=36) Group Key: lineitem.l_suppkey Planned Partitions: 8 -> Parallel Seq Scan on lineitem (cost=0.00..1529779.55 rows=980687 width=16) Filter: ((l_shipdate >= '1994-02-01'::date) AND (l_shipdate < '1994-05-02 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 revenue0; DROP VIEW COMMIT; COMMIT