Skip to content

Commit

Permalink
sql: fix FK check bug in ALTER COLUMN TYPE
Browse files Browse the repository at this point in the history
This commit fixes an implementation bug when checking that the table's
foreign keys didn't hold a reference to the altered column.

Fixes cockroachdb#71089.

Release justification: simple fix for blatant correctness bug

Release note (bug fix): fixes a bug which caused ALTER COLUMN TYPE
statements to fail when they shouldn't have.
  • Loading branch information
Marius Posta committed Oct 26, 2021
1 parent 0b4fd4e commit d05034e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pkg/sql/alter_column_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,18 @@ func alterColumnTypeGeneralOld(
}

for _, fk := range tableDesc.AllActiveAndInactiveForeignKeys() {
for _, id := range append(fk.OriginColumnIDs, fk.ReferencedColumnIDs...) {
if col.ID == id {
return colWithConstraintNotSupportedErr
if fk.OriginTableID == tableDesc.GetID() {
for _, id := range fk.OriginColumnIDs {
if col.ID == id {
return colWithConstraintNotSupportedErr
}
}
}
if fk.ReferencedTableID == tableDesc.GetID() {
for _, id := range fk.ReferencedColumnIDs {
if col.ID == id {
return colWithConstraintNotSupportedErr
}
}
}
}
Expand Down

0 comments on commit d05034e

Please sign in to comment.