Skip to content

opt: error when an UPDATE cascades to a table with a check constraint on an ambiguous column #57148

@mgartner

Description

@mgartner

When an UPDATE cascades to a child table with a check constraint on a column with a name <fk_column>_new, CRDB incorrectly errs with an ambiguous column reference error. The expected behavior is for the UPDATE to succeed.

This error also occurs if the child table has a partial index that references the <fk_column>_new column.

To Reproduce

root@127.0.0.1:51932/defaultdb> CREATE TABLE parent_check_ambig (p INT PRIMARY KEY);
CREATE TABLE

root@127.0.0.1:51932/defaultdb> CREATE TABLE child_check_ambig (
  c INT PRIMARY KEY,
  p_new INT REFERENCES parent_check_ambig(p) ON UPDATE CASCADE,
  i INT,
  CHECK (p_new > 0)
);
CREATE TABLE

root@127.0.0.1:51932/defaultdb> insert into parent_check_ambig values (1);
INSERT 1

root@127.0.0.1:51932/defaultdb> insert into child_check_ambig values( 1, 1, 1);
INSERT 1

root@127.0.0.1:51932/defaultdb> UPDATE parent_check_ambig SET p = p * 10 WHERE p = 1
;
ERROR: while building cascade expression: column reference "p_new" is ambiguous (candidates: <anonymous>.p_new)
SQLSTATE: 42702

To Reproduce in an Optbuilder Test

exec-ddl
CREATE TABLE parent_check_ambig (p INT PRIMARY KEY)
----

exec-ddl
CREATE TABLE child_check_ambig (
  c INT PRIMARY KEY,
  p_new INT REFERENCES parent_check_ambig(p) ON UPDATE CASCADE,
  i INT,
  CHECK (p_new > 0)
)
----

build-cascades
UPDATE parent_check_ambig SET p = p * 10 WHERE p > 1
----

Environment

Build Tag:        v20.2.1
Build Time:       2020/11/20 18:37:02
Distribution:     CCL
Platform:         darwin amd64 (x86_64-apple-darwin14)
Go Version:       go1.13.14
C Compiler:       4.2.1 Compatible Clang 3.8.0 (tags/RELEASE_380/final)
Build Commit ID:  fe9afecdaf3ffc41c6822897595e85451dad26f2
Build Type:       release

Metadata

Metadata

Assignees

Labels

A-sql-optimizerSQL logical planning and optimizations.C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions