Hi Robert,
On Tue, Nov 3, 2026 at 9:21 AM Robert Haas <[email protected]>
wrote:
> It's also important that the set of names we end up with
> doesn't depend on what the planner chooses to do. We want expr_5 to
> mean the same thing no matter how the query gets planned, because
> advice strings can refer to it.
On master that already doesn't hold when a custom plan folds a sublink
away:
CREATE TABLE t (a int, b int); CREATE TABLE t2 (a int, b int);
PREPARE p(int) AS
SELECT CASE WHEN $1 = 0 THEN NULL
ELSE (SELECT sum(b) FROM t2 WHERE a = t.a AND b = 1) END,
(SELECT sum(b) FROM t2 WHERE a = t.a AND b = 2),
(SELECT sum(b) FROM t2 WHERE a = t.a AND b = 3)
FROM t;
With EXECUTE p(0), the custom plan names the b = 2 and b = 3 sublinks
expr_1 and expr_2, and the generic plan names them expr_2 and expr_3,
so expr_2 is a different subquery in each. v5 keeps master's names,
so it behaves the same; a single counter would extend this to
subplans of other kinds.
Regards,
Manu