Skip to content

Commit acb34f9

Browse files
committed
opt: move some assignment cast execbuilder logic to init-time
Lookups for the `crdb_internal.assignment_cast` function properties and overload are now performed once at init-time instead of for every assignment cast built at execbuild-time. Release note: None
1 parent 287999c commit acb34f9

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

pkg/sql/opt/exec/execbuilder/scalar.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,13 @@ func (b *Builder) buildCast(ctx *buildScalarCtx, scalar opt.ScalarExpr) (tree.Ty
370370
return tree.NewTypedCastExpr(input, cast.Typ), nil
371371
}
372372

373+
const assnCastFnName = "crdb_internal.assignment_cast"
374+
375+
var (
376+
assnCastFuncRef = tree.WrapFunction(assnCastFnName)
377+
assnCastProps, assnCastOverloads = builtinsregistry.GetBuiltinProperties(assnCastFnName)
378+
)
379+
373380
// buildAssignmentCast builds an AssignmentCastExpr with input i and type T into
374381
// a built-in function call crdb_internal.assignment_cast(i, NULL::T).
375382
func (b *Builder) buildAssignmentCast(
@@ -388,21 +395,15 @@ func (b *Builder) buildAssignmentCast(
388395
return input, nil
389396
}
390397

391-
const fnName = "crdb_internal.assignment_cast"
392-
funcRef, err := b.wrapBuiltinFunction(fnName)
393-
if err != nil {
394-
return nil, err
395-
}
396-
props, overloads := builtinsregistry.GetBuiltinProperties(fnName)
397398
return tree.NewTypedFuncExpr(
398-
funcRef,
399+
assnCastFuncRef,
399400
0, /* aggQualifier */
400401
tree.TypedExprs{input, tree.NewTypedCastExpr(tree.DNull, cast.Typ)},
401402
nil, /* filter */
402403
nil, /* windowDef */
403404
cast.Typ,
404-
props,
405-
&overloads[0],
405+
assnCastProps,
406+
&assnCastOverloads[0],
406407
), nil
407408
}
408409

0 commit comments

Comments
 (0)