Skip to content

Commit 58c3ce5

Browse files
committed
sql: reduce allocations for unsupported type checker
Release note: None
1 parent 45057e1 commit 58c3ce5

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

pkg/sql/planner.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,12 +930,15 @@ func (p *planner) resetPlanner(
930930

931931
p.cancelChecker.Reset(ctx)
932932

933+
utc := p.semaCtx.UnsupportedTypeChecker
933934
p.semaCtx = tree.MakeSemaContext(p)
934935
p.semaCtx.SearchPath = &sd.SearchPath
935936
p.semaCtx.Annotations = nil
936937
p.semaCtx.DateStyle = sd.GetDateStyle()
937938
p.semaCtx.IntervalStyle = sd.GetIntervalStyle()
938-
p.semaCtx.UnsupportedTypeChecker = eval.NewUnsupportedTypeChecker(p.execCfg.Settings.Version)
939+
p.semaCtx.UnsupportedTypeChecker = eval.ResetUnsupportedTypeChecker(
940+
p.execCfg.Settings.Version, utc,
941+
)
939942
p.semaCtx.UsePre_25_2VariadicBuiltins = sd.UsePre_25_2VariadicBuiltins
940943

941944
p.autoCommit = false

pkg/sql/sem/eval/unsupported_types.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,22 @@ type unsupportedTypeChecker struct {
2424
// NewUnsupportedTypeChecker returns a new tree.UnsupportedTypeChecker that can
2525
// be used to check whether a type is allowed by the current cluster version.
2626
func NewUnsupportedTypeChecker(handle clusterversion.Handle) tree.UnsupportedTypeChecker {
27-
// There are currently no types to check. Uncomment this code if a new type is introduced.
2827
return &unsupportedTypeChecker{version: handle}
2928
}
3029

30+
// ResetUnsupportedTypeChecker is similar to NewUnsupportedTypeChecker, but
31+
// reuses an existing, non-nil tree.UnsupportedTypeChecker if one is given,
32+
// instead of allocating a new one.
33+
func ResetUnsupportedTypeChecker(
34+
handle clusterversion.Handle, existing tree.UnsupportedTypeChecker,
35+
) tree.UnsupportedTypeChecker {
36+
if u, ok := existing.(*unsupportedTypeChecker); ok && u != nil {
37+
u.version = handle
38+
return existing
39+
}
40+
return NewUnsupportedTypeChecker(handle)
41+
}
42+
3143
var _ tree.UnsupportedTypeChecker = (*unsupportedTypeChecker)(nil)
3244

3345
// CheckType implements the tree.UnsupportedTypeChecker interface.

0 commit comments

Comments
 (0)