Skip to content

Commit

Permalink
tabledesc: fix bug in unupgraded descriptor validation
Browse files Browse the repository at this point in the history
In the haste of cockroachdb#57066 we erroneously checked the origin rather than reference
column ID when validating an inbound fk reference. The tests did not catch this
error because the column IDs were the same on both sides.

Release note (bug fix): Fix a bug related validation of unupgraded pre-19.2
inbound foreign keys.
  • Loading branch information
ajwerner committed Nov 25, 2020
1 parent 8ef0622 commit 107b6a4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/sql/catalog/tabledesc/structured.go
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,7 @@ func (desc *Immutable) validateCrossReferences(ctx context.Context, dg catalog.D
fk.Index, desc.Name, backref.Name, originTable.GetName(),
)
}
if originalReferencedIndex.IsValidReferencedIndex(backref.OriginColumnIDs) {
if originalReferencedIndex.IsValidReferencedIndex(backref.ReferencedColumnIDs) {
found = true
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/catalog/tabledesc/structured_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ func TestValidateCrossTableReferences(t *testing.T) {
Indexes: []descpb.IndexDescriptor{
{
ID: 2,
ColumnIDs: []descpb.ColumnID{1},
ColumnIDs: []descpb.ColumnID{7},
Unique: true,
},
},
Expand All @@ -831,7 +831,7 @@ func TestValidateCrossTableReferences(t *testing.T) {
ReferencedTableID: 51,
ReferencedColumnIDs: []descpb.ColumnID{1},
OriginTableID: 52,
OriginColumnIDs: []descpb.ColumnID{1},
OriginColumnIDs: []descpb.ColumnID{7},
},
},
},
Expand Down

0 comments on commit 107b6a4

Please sign in to comment.