From 2bf8569b54e24cd37f766ca207a52f2375d7ba64 Mon Sep 17 00:00:00 2001 From: Marcus Gartner Date: Thu, 6 Oct 2022 22:33:15 +0000 Subject: [PATCH] opt: remove TODOs related to UDFs named "count" Related to #89543 Release note: None --- pkg/sql/opt/optbuilder/scope.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pkg/sql/opt/optbuilder/scope.go b/pkg/sql/opt/optbuilder/scope.go index f6486bb3124d..ad883456007e 100644 --- a/pkg/sql/opt/optbuilder/scope.go +++ b/pkg/sql/opt/optbuilder/scope.go @@ -1534,6 +1534,9 @@ func (s *scope) replaceCount( } f.Exprs[0] = vn + // It is ok to use string equality here, even if there is a UDF named + // "count" because UDFs cannot be aggregate functions. This code path is + // only executed for aggregate functions. if strings.EqualFold(def.Name, "count") && f.Type == 0 { if _, ok := vn.(tree.UnqualifiedStar); ok { if f.Filter != nil { @@ -1548,9 +1551,6 @@ func (s *scope) replaceCount( e := &cpy e.Exprs = tree.Exprs{tree.DBoolTrue} - // TODO(mgartner): What happens if a user defines a UDF named - // "count"? We might need to resolve the function first, not - // just rely on string equality to "count" above. newDef, err := e.Func.Resolve(s.builder.ctx, s.builder.semaCtx.SearchPath, nil /* resolver */) if err != nil { panic(err) @@ -1577,9 +1577,6 @@ func (s *scope) replaceCount( if _, err := e.TypeCheck(s.builder.ctx, &semaCtx, types.Any); err != nil { panic(err) } - // TODO(mgartner): What happens if a user defines a UDF named - // "count"? We might need to resolve the function first, not just - // rely on string equality to "count" above. newDef, err := e.Func.Resolve(s.builder.ctx, s.builder.semaCtx.SearchPath, nil /* resolver */) if err != nil { panic(err)