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

validate: use immutable descriptors only #95830

Merged
Merged
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
21 changes: 19 additions & 2 deletions pkg/sql/catalog/internal/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ func Validate(
targetLevel catalog.ValidationLevel,
descriptors ...catalog.Descriptor,
) catalog.ValidationErrors {
for i, d := range descriptors {
// Replace mutable descriptors with immutable copies. Validation is
// read-only in any case, and using immutables can have a significant
// impact on performance when validating tables due to columns, indexes,
// and so forth being cached.
if mut, ok := d.(catalog.MutableDescriptor); ok {
descriptors[i] = mut.ImmutableCopy()
}
}
vea := validationErrorAccumulator{
ValidationTelemetry: telemetry,
targetLevel: targetLevel,
Expand Down Expand Up @@ -409,9 +418,17 @@ func (cs *collectorState) getMissingDescs(
return nil, err
}
for _, desc := range resps {
if desc != nil {
cs.vdg.descriptors[desc.GetID()] = desc
if desc == nil {
continue
}
if mut, ok := desc.(catalog.MutableDescriptor); ok {
// Replace mutable descriptors with immutable copies. Validation is
// read-only in any case, and using immutables can have a significant
// impact on performance when validating tables due to columns, indexes,
// and so forth being cached.
desc = mut.ImmutableCopy()
}
cs.vdg.descriptors[desc.GetID()] = desc
}
return resps, nil
}
Expand Down