BEGIN; BEGIN create or replace view revenue2 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1994-05-01' and l_shipdate < date'1994-05-01' + interval '90 days' group by l_suppkey; CREATE VIEW EXPLAIN select s_suppkey, s_name, s_address, s_phone, total_revenue from supplier, revenue2 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue2 ) order by s_suppkey; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------ Nested Loop (cost=3264494.55..3293594.24 rows=497 width=104) InitPlan 1 (returns $1) -> Aggregate (cost=1645822.21..1645822.22 rows=1 width=32) -> Finalize GroupAggregate (cost=1618672.04..1644580.66 rows=99324 width=36) Group Key: lineitem_1.l_suppkey -> Gather Merge (cost=1618672.04..1641849.25 rows=198648 width=36) Workers Planned: 2 -> Sort (cost=1617672.01..1617920.32 rows=99324 width=36) Sort Key: lineitem_1.l_suppkey -> Partial HashAggregate (cost=1596281.87..1606712.19 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=940930 width=16) Filter: ((l_shipdate >= '1994-05-01'::date) AND (l_shipdate < '1994-07-30 00:00:00'::timestamp without time zone)) -> Finalize GroupAggregate (cost=1618672.04..1644828.97 rows=497 width=36) Group Key: lineitem.l_suppkey Filter: (sum((lineitem.l_extendedprice * ('1'::numeric - lineitem.l_discount))) = $1) -> Gather Merge (cost=1618672.04..1641849.25 rows=198648 width=36) Workers Planned: 2 -> Sort (cost=1617672.01..1617920.32 rows=99324 width=36) Sort Key: lineitem.l_suppkey -> Partial HashAggregate (cost=1596281.87..1606712.19 rows=99324 width=36) Group Key: lineitem.l_suppkey Planned Partitions: 8 -> Parallel Seq Scan on lineitem (cost=0.00..1531298.89 rows=940930 width=16) Filter: ((l_shipdate >= '1994-05-01'::date) AND (l_shipdate < '1994-07-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 revenue2; DROP VIEW COMMIT; COMMIT