schemachanger/rel: fix notJoin subquery depth calculation for non-entity variables #157031
+213
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, the subquery depth calculation in setSubqueryDepth only considered
direct entity dependencies when determining when a notJoin subquery should
execute. It tracked the maximum entity slot among the subquery's inputs but
ignored when non-entity variables (like table-id, index-id) were actually bound.
This caused notJoin subqueries to execute too early, before all their required
variables were available, leading to "unbound variable" errors.
This commit fixes the depth calculation by tracking which entity provides each
variable through the facts. When a subquery needs a non-entity variable, we now
find which entity binds that variable and use that entity's slot to determine
the correct execution depth. This ensures notJoin subqueries only execute after
all their input variables have been bound by the appropriate entities in the
join order.
The fix is needed for rules that pass non-entity variables to notJoin
predicates, particularly in constraint rename scenarios where variables may
be bound at different join depths. (At the time of this writing, we
don't yet have rules like this, but we soon will add one.)
informs #148341
Release note: None