Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release-22.1: sql/catalog/tabledesc: permit zero-valued column IDs in DependedOnBy #82859

Merged
merged 1 commit into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/sql/catalog/tabledesc/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,13 @@ func (desc *wrapper) validateInboundTableRef(
// descriptor is for a sequence. In this case, they refer to the columns
// in the referenced descriptor instead.
for _, colID := range by.ColumnIDs {
// Skip this check if the column ID is zero. This can happen due to
// bugs in 20.2.
//
// TODO(ajwerner): Make sure that a migration in 22.2 fixes this issue.
ajwerner marked this conversation as resolved.
Show resolved Hide resolved
if colID == 0 {
continue
}
col, _ := backReferencedTable.FindColumnWithID(colID)
if col == nil {
return errors.AssertionFailedf("depended-on-by relation %q (%d) does not have a column with ID %d",
Expand Down
34 changes: 34 additions & 0 deletions pkg/sql/catalog/tabledesc/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2491,6 +2491,40 @@ func TestValidateCrossTableReferences(t *testing.T) {
},
}},
},
{ // 14
// This case deals with a bug in version 21.1 and prior when
// ALTER TABLE ... ADD COLUMN ... DEFAULT nextval(...) would set the
// backreference ID to be 0 because it set up the backreference before
// calling AllocateIDs.
desc: descpb.TableDescriptor{
Name: "foo",
ID: 51,
ParentID: 1,
UnexposedParentSchemaID: keys.PublicSchemaID,
SequenceOpts: &descpb.TableDescriptor_SequenceOpts{
Increment: 1,
},
DependedOnBy: []descpb.TableDescriptor_Reference{
{ID: 52, ColumnIDs: []descpb.ColumnID{0}},
},
},
otherDescs: []descpb.TableDescriptor{{
Name: "bar",
ID: 52,
ParentID: 1,
UnexposedParentSchemaID: keys.PublicSchemaID,
PrimaryIndex: descpb.IndexDescriptor{
ID: 1,
Name: "primary",
KeyColumnIDs: []descpb.ColumnID{1},
KeyColumnNames: []string{"a"},
},
Columns: []descpb.ColumnDescriptor{
{Name: "a", ID: 1, Type: types.Int},
},
DependsOn: []descpb.ID{51},
}},
},
}

for i, test := range tests {
Expand Down