BEGIN; BEGIN create or replace view revenue3 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1996-12-01' and l_shipdate < date'1996-12-01' + interval '90 days' group by l_suppkey; CREATE VIEW EXPLAIN select s_suppkey, s_name, s_address, s_phone, total_revenue from supplier, revenue3 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue3 ) order by s_suppkey; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------ Nested Loop (cost=3263754.04..3292853.73 rows=497 width=104) InitPlan 1 (returns $1) -> Aggregate (cost=1645451.96..1645451.97 rows=1 width=32) -> Finalize GroupAggregate (cost=1618301.78..1644210.41 rows=99324 width=36) Group Key: lineitem_1.l_suppkey -> Gather Merge (cost=1618301.78..1641479.00 rows=198648 width=36) Workers Planned: 2 -> Sort (cost=1617301.76..1617550.07 rows=99324 width=36) Sort Key: lineitem_1.l_suppkey -> Partial HashAggregate (cost=1595957.49..1606341.94 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=936233 width=16) Filter: ((l_shipdate >= '1996-12-01'::date) AND (l_shipdate < '1997-03-01 00:00:00'::timestamp without time zone)) -> Finalize GroupAggregate (cost=1618301.78..1644458.72 rows=497 width=36) Group Key: lineitem.l_suppkey Filter: (sum((lineitem.l_extendedprice * ('1'::numeric - lineitem.l_discount))) = $1) -> Gather Merge (cost=1618301.78..1641479.00 rows=198648 width=36) Workers Planned: 2 -> Sort (cost=1617301.76..1617550.07 rows=99324 width=36) Sort Key: lineitem.l_suppkey -> Partial HashAggregate (cost=1595957.49..1606341.94 rows=99324 width=36) Group Key: lineitem.l_suppkey Planned Partitions: 8 -> Parallel Seq Scan on lineitem (cost=0.00..1531298.89 rows=936233 width=16) Filter: ((l_shipdate >= '1996-12-01'::date) AND (l_shipdate < '1997-03-01 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 revenue3; DROP VIEW COMMIT; COMMIT