Skip to content

Commit

Permalink
tabledesc,descs: ensure to propagate IsUncommittedVersion when hydrating
Browse files Browse the repository at this point in the history
When we hydrate a table descriptor which has been modified during the
transaction we want to ensure that we propagate the information that
indicates that it has been modified.

Release justification: Part of a larger fix to a major performance
enhancement for user-defined types, a new feature in this release.

Release note: None
  • Loading branch information
ajwerner committed Aug 27, 2020
1 parent de028d9 commit 2b6e7c9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 1 addition & 2 deletions pkg/sql/catalog/descs/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -1110,13 +1110,12 @@ func (tc *Collection) hydrateTypesInTableDesc(
// Proceed to hydrating a fresh copy.
}

// TODO(ajwerner): Propagate the IsModified status here.
// Make a copy of the underlying descriptor before hydration.
descBase := protoutil.Clone(t.TableDesc()).(*descpb.TableDescriptor)
if err := typedesc.HydrateTypesInTableDescriptor(ctx, descBase, getType); err != nil {
return nil, err
}
return tabledesc.NewImmutable(*descBase), nil
return tabledesc.NewImmutableWithIsUncommittedVersion(*descBase, t.IsUncommittedVersion()), nil
default:
return desc, nil
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/sql/catalog/tabledesc/structured.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,21 @@ func MakeImmutable(tbl descpb.TableDescriptor) Immutable {
}

// NewImmutable returns a Immutable from the given TableDescriptor.
// This function assumes that this descriptor has not been modified from the
// version stored in the key-value store.
func NewImmutable(tbl descpb.TableDescriptor) *Immutable {
return NewImmutableWithIsUncommittedVersion(tbl, false /* isUncommittedVersion */)
}

// NewImmutableWithIsUncommittedVersion returns a Immutable from the given
// TableDescriptor and allows the caller to mark the table as corresponding to
// an uncommitted version. This should be used when constructing a new copy of
// an Immutable from an existing descriptor which may have a new version.
func NewImmutableWithIsUncommittedVersion(
tbl descpb.TableDescriptor, isUncommittedVersion bool,
) *Immutable {
desc := MakeImmutable(tbl)
desc.isUncommittedVersion = isUncommittedVersion
return &desc
}

Expand Down

0 comments on commit 2b6e7c9

Please sign in to comment.