From 514b39d3596969eb697c948812ec6a05bf176113 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Wed, 20 Dec 2023 13:35:46 +0100 Subject: [PATCH] [jOOQ/jOOQ#15967] Implicit path correlation shouldn't generate correlation predicate if correlation isn't in scope --- .../src/main/java/org/jooq/impl/SelectQueryImpl.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java b/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java index 18fc4ade17..20e31766aa 100644 --- a/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java @@ -2926,10 +2926,14 @@ final class SelectQueryImpl extends AbstractResultQuery imp while ((next = TableImpl.path(curr)) != null) { tables.add(curr); + // [#14985] [#15967] In some edge cases, users may have chosen to use a path in the FROM + // clause, whose path root isn't in scope. We mustn't put it in scope here! + if (!ctx.inScope(curr)) + ctx.scopeRegister(curr, true); + if (ctx.inScope(next)) break; - ctx.scopeRegister(next, true); curr = next; } @@ -4355,8 +4359,10 @@ final class SelectQueryImpl extends AbstractResultQuery imp private static final void addPathConditions(Context ctx, ConditionProviderImpl result, Table t) { if (t instanceof TableImpl ti) { - // [#14985] TODO: Should we check whether ti.child is in scope, or leave that to the user? - if (ti.path != null) + // [#14985] [#15967] In some edge cases, users may have chosen to use a path in the FROM + // clause, whose path root isn't in scope. In that case, we must ignore + // the path. + if (ti.path != null && ctx.inScope(ti.path)) result.addConditions(ti.pathCondition()); } }