diff --git a/pkg/sql/backfill.go b/pkg/sql/backfill.go index 87b2e868ef55..b34ea895859d 100644 --- a/pkg/sql/backfill.go +++ b/pkg/sql/backfill.go @@ -701,9 +701,10 @@ func (sc *SchemaChanger) validateConstraints( // print the check expression back to the user. evalCtx.Txn = txn // Use the DistSQLTypeResolver because we need to resolve types by ID. - semaCtx := tree.MakeSemaContext() collection := evalCtx.Descs - semaCtx.TypeResolver = descs.NewDistSQLTypeResolver(collection, txn) + resolver := descs.NewDistSQLTypeResolver(collection, txn) + semaCtx := tree.MakeSemaContext() + semaCtx.TypeResolver = &resolver // TODO (rohany): When to release this? As of now this is only going to get released // after the check is validated. defer func() { collection.ReleaseAll(ctx) }() diff --git a/pkg/sql/backfill/backfill.go b/pkg/sql/backfill/backfill.go index 0252800f006f..eab39f7563bf 100644 --- a/pkg/sql/backfill/backfill.go +++ b/pkg/sql/backfill/backfill.go @@ -201,12 +201,12 @@ func (cb *ColumnBackfiller) InitForDistributedUse( if err := flowCtx.Cfg.DB.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error { resolver := flowCtx.TypeResolverFactory.NewTypeResolver(txn) // Hydrate all the types present in the table. - if err := typedesc.HydrateTypesInTableDescriptor(ctx, desc.TableDesc(), resolver); err != nil { + if err := typedesc.HydrateTypesInTableDescriptor(ctx, desc.TableDesc(), &resolver); err != nil { return err } // Set up a SemaContext to type check the default and computed expressions. semaCtx := tree.MakeSemaContext() - semaCtx.TypeResolver = resolver + semaCtx.TypeResolver = &resolver var err error defaultExprs, err = schemaexpr.MakeDefaultExprs( ctx, cb.added, &transform.ExprTransformContext{}, evalCtx, &semaCtx, @@ -600,13 +600,13 @@ func (ib *IndexBackfiller) InitForDistributedUse( resolver := flowCtx.TypeResolverFactory.NewTypeResolver(txn) // Hydrate all the types present in the table. if err = typedesc.HydrateTypesInTableDescriptor( - ctx, desc.TableDesc(), resolver, + ctx, desc.TableDesc(), &resolver, ); err != nil { return err } // Set up a SemaContext to type check the default and computed expressions. semaCtx := tree.MakeSemaContext() - semaCtx.TypeResolver = resolver + semaCtx.TypeResolver = &resolver // Convert any partial index predicate strings into expressions. predicates, colExprs, referencedColumns, err = constructExprs( ctx, desc, ib.added, ib.cols, ib.addedCols, ib.computedCols, evalCtx, &semaCtx, diff --git a/pkg/sql/catalog/descs/dist_sql_type_resolver.go b/pkg/sql/catalog/descs/dist_sql_type_resolver.go index fdcf141117d8..d37a5a447f35 100644 --- a/pkg/sql/catalog/descs/dist_sql_type_resolver.go +++ b/pkg/sql/catalog/descs/dist_sql_type_resolver.go @@ -49,8 +49,9 @@ func (df *DistSQLTypeResolverFactory) NewTypeResolver(txn *kv.Txn) DistSQLTypeRe // NewSemaContext creates a new SemaContext with a TypeResolver bound to the // input transaction. func (df *DistSQLTypeResolverFactory) NewSemaContext(txn *kv.Txn) *tree.SemaContext { + resolver := df.NewTypeResolver(txn) semaCtx := tree.MakeSemaContext() - semaCtx.TypeResolver = df.NewTypeResolver(txn) + semaCtx.TypeResolver = &resolver return &semaCtx } @@ -70,14 +71,16 @@ func NewDistSQLTypeResolver(descs *Collection, txn *kv.Txn) DistSQLTypeResolver } // ResolveType implements the tree.TypeReferenceResolver interface. -func (dt DistSQLTypeResolver) ResolveType( +func (dt *DistSQLTypeResolver) ResolveType( context.Context, *tree.UnresolvedObjectName, ) (*types.T, error) { return nil, errors.AssertionFailedf("cannot resolve types in DistSQL by name") } // ResolveTypeByOID implements the tree.TypeReferenceResolver interface. -func (dt DistSQLTypeResolver) ResolveTypeByOID(ctx context.Context, oid oid.Oid) (*types.T, error) { +func (dt *DistSQLTypeResolver) ResolveTypeByOID( + ctx context.Context, oid oid.Oid, +) (*types.T, error) { id, err := typedesc.UserDefinedTypeOIDToID(oid) if err != nil { return nil, err @@ -90,7 +93,7 @@ func (dt DistSQLTypeResolver) ResolveTypeByOID(ctx context.Context, oid oid.Oid) } // GetTypeDescriptor implements the sqlbase.TypeDescriptorResolver interface. -func (dt DistSQLTypeResolver) GetTypeDescriptor( +func (dt *DistSQLTypeResolver) GetTypeDescriptor( ctx context.Context, id descpb.ID, ) (tree.TypeName, catalog.TypeDescriptor, error) { flags := tree.CommonLookupFlags{ @@ -129,7 +132,7 @@ func (dt DistSQLTypeResolver) GetTypeDescriptor( } // HydrateTypeSlice installs metadata into a slice of types.T's. -func (dt DistSQLTypeResolver) HydrateTypeSlice(ctx context.Context, typs []*types.T) error { +func (dt *DistSQLTypeResolver) HydrateTypeSlice(ctx context.Context, typs []*types.T) error { for _, t := range typs { if err := typedesc.EnsureTypeIsHydrated(ctx, t, dt); err != nil { return err diff --git a/pkg/sql/execinfra/processorsbase.go b/pkg/sql/execinfra/processorsbase.go index 4acec2fcbe50..4d8714b5f4c0 100644 --- a/pkg/sql/execinfra/processorsbase.go +++ b/pkg/sql/execinfra/processorsbase.go @@ -790,7 +790,7 @@ func (pb *ProcessorBase) InitWithEvalCtx( return err } pb.SemaCtx = tree.MakeSemaContext() - pb.SemaCtx.TypeResolver = resolver + pb.SemaCtx.TypeResolver = &resolver return pb.OutputHelper.Init(post, coreOutputTypes, &pb.SemaCtx, pb.EvalCtx) }