release-20.2: optbuilder: fix ambiguous column references for FK cascades #57234
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.
Backport 1/1 commits from #57153.
/cc @cockroachdb/release
This commit fixes an issue in optbuilder that caused "ambiguous column
reference" errors. This error would be produced during cascading updates
if a child table's reference column name was equal to the parent column
name concatenated with
_new
, and the child table had a checkconstraint, computed column, or partial index predicate that referenced
the column.
For example, the following
UPDATE
statement would produce an error.The expected behavior is a successful
UPDATE
. Notice thatp_new
ofthe child table references
p
of the parent table.This issue was the result of incorrect scoping while building foreign
key cascading update expressions. A column with the same name and column
ID was added to the update expression's input scope. Because the
mutationBuilder.disambiguateColumns
function is unable to disambiguatecolumns with the same name and column ID, building any expression that
referenced the duplicated column would result in an error.
This commit fixes the issue by no longer duplicating columns in the
update expression's input scope.
mutationBuilder.addUpdateCols
nowdetects the special case when the update expression is a
*scopeColumn
and avoids duplicating it in the generated projection scope.
Fixes #57148
Release note (bug fix): A bug has been fix that caused an "ambiguous
column reference" error during foreign key cascading updates. This error
was incorrectly produced when the child table's reference column name
was equal to the concatenation of the parent's reference column name and
"_new", and when the child table had a CHECK constraint, computed
column, or partial index predicate expression that referenced the
column. This bug was introduce in version 20.2.