From 86b54f5e69c73b4458feb126ca533640b35a31a0 Mon Sep 17 00:00:00 2001 From: Yahor Yuzefovich Date: Tue, 28 Jun 2022 18:11:15 -0700 Subject: [PATCH 1/7] rowexec: fix recent bug of using nil context In e7e724ead15aa037f9f0188fe18f8179bf3945f0 we moved the creation of a monitor for the streamer's disk usage into the constructor of the join reader but forgot to update the context used during that operation. The thing is that the context on the processors is only set in `Start` meaning it is `nil` in the construct of the processor. This commit fixes the issue. Release note: None --- pkg/sql/rowexec/joinreader.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/sql/rowexec/joinreader.go b/pkg/sql/rowexec/joinreader.go index 4d88690ac0bc..b5b6e2a877a5 100644 --- a/pkg/sql/rowexec/joinreader.go +++ b/pkg/sql/rowexec/joinreader.go @@ -478,7 +478,7 @@ func newJoinReader( var diskBuffer kvstreamer.ResultDiskBuffer if jr.maintainOrdering { jr.streamerInfo.diskMonitor = execinfra.NewMonitor( - jr.Ctx, jr.FlowCtx.DiskMonitor, "streamer-disk", /* name */ + flowCtx.EvalCtx.Ctx(), jr.FlowCtx.DiskMonitor, "streamer-disk", /* name */ ) diskBuffer = rowcontainer.NewKVStreamerResultDiskBuffer( jr.FlowCtx.Cfg.TempStorage, jr.streamerInfo.diskMonitor, From 2681a28490a6d5aa3d02f3c93c2fb47d7458c2e2 Mon Sep 17 00:00:00 2001 From: Xiang Gu Date: Thu, 23 Jun 2022 15:48:29 -0400 Subject: [PATCH 2/7] sql/builtins: Moved constants used in builtins into buildinconstants A few of the constants in builts are used outside of the builtins packages and cause those other packages to pull in all dependencies of builtins. This is not ideal and we fix it by moving all the constants into a separate package `builtinconstants`. Release note: None --- pkg/sql/catalog/seqexpr/BUILD.bazel | 1 + pkg/sql/catalog/seqexpr/sequence.go | 3 +- pkg/sql/row/BUILD.bazel | 1 + pkg/sql/row/expr_walker.go | 6 +- pkg/sql/sem/builtins/BUILD.bazel | 2 + .../sem/builtins/builtinconstants/BUILD.bazel | 8 + .../builtins/builtinconstants/constants.go | 56 +++ pkg/sql/sem/builtins/builtins.go | 439 ++++++++---------- pkg/sql/sem/builtins/builtins_test.go | 9 +- pkg/sql/sem/builtins/generator_builtins.go | 15 +- pkg/sql/sem/builtins/geo_builtins.go | 7 +- pkg/sql/sem/builtins/overlaps_builtins.go | 3 +- pkg/sql/sem/builtins/pg_builtins.go | 29 +- pkg/sql/sem/builtins/pgcrypto_builtins.go | 9 +- pkg/sql/sem/builtins/replication_builtins.go | 15 +- pkg/sql/sem/builtins/trigram_builtins.go | 15 +- 16 files changed, 333 insertions(+), 285 deletions(-) create mode 100644 pkg/sql/sem/builtins/builtinconstants/BUILD.bazel create mode 100644 pkg/sql/sem/builtins/builtinconstants/constants.go diff --git a/pkg/sql/catalog/seqexpr/BUILD.bazel b/pkg/sql/catalog/seqexpr/BUILD.bazel index b3443919eb17..f9092fc22231 100644 --- a/pkg/sql/catalog/seqexpr/BUILD.bazel +++ b/pkg/sql/catalog/seqexpr/BUILD.bazel @@ -9,6 +9,7 @@ go_library( "//pkg/sql/pgwire/pgcode", "//pkg/sql/pgwire/pgerror", "//pkg/sql/sem/builtins", + "//pkg/sql/sem/builtins/builtinconstants", "//pkg/sql/sem/tree", "//pkg/sql/types", ], diff --git a/pkg/sql/catalog/seqexpr/sequence.go b/pkg/sql/catalog/seqexpr/sequence.go index c1767e254ab0..7d4386bbeaad 100644 --- a/pkg/sql/catalog/seqexpr/sequence.go +++ b/pkg/sql/catalog/seqexpr/sequence.go @@ -21,6 +21,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror" "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins" + "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins/builtinconstants" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/types" ) @@ -68,7 +69,7 @@ func GetSequenceFromFunc(funcExpr *tree.FuncExpr) (*SeqIdentifier, error) { for i := 0; i < overload.Types.Length(); i++ { // Find the sequence name arg. argName := argTypes[i].Name - if argName == builtins.SequenceNameArg { + if argName == builtinconstants.SequenceNameArg { arg := funcExpr.Exprs[i] if seqIdentifier := getSequenceIdentifier(arg); seqIdentifier != nil { return seqIdentifier, nil diff --git a/pkg/sql/row/BUILD.bazel b/pkg/sql/row/BUILD.bazel index cf52be6fe156..58b724f6419d 100644 --- a/pkg/sql/row/BUILD.bazel +++ b/pkg/sql/row/BUILD.bazel @@ -52,6 +52,7 @@ go_library( "//pkg/sql/rowinfra", "//pkg/sql/scrub", "//pkg/sql/sem/builtins", + "//pkg/sql/sem/builtins/builtinconstants", "//pkg/sql/sem/eval", "//pkg/sql/sem/transform", "//pkg/sql/sem/tree", diff --git a/pkg/sql/row/expr_walker.go b/pkg/sql/row/expr_walker.go index 54a68db17040..d37065c1b7e9 100644 --- a/pkg/sql/row/expr_walker.go +++ b/pkg/sql/row/expr_walker.go @@ -25,7 +25,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/catalog/seqexpr" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror" - "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins" + "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins/builtinconstants" "github.com/cockroachdb/cockroach/pkg/sql/sem/eval" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/sem/volatility" @@ -650,13 +650,13 @@ var supportedImportFuncOverrides = map[string]*customFunc{ override: makeBuiltinOverride( tree.FunDefs["nextval"], tree.Overload{ - Types: tree.ArgTypes{{builtins.SequenceNameArg, types.String}}, + Types: tree.ArgTypes{{builtinconstants.SequenceNameArg, types.String}}, ReturnType: tree.FixedReturnType(types.Int), Info: "Advances the value of the sequence and returns the final value.", Fn: importNextVal, }, tree.Overload{ - Types: tree.ArgTypes{{builtins.SequenceNameArg, types.RegClass}}, + Types: tree.ArgTypes{{builtinconstants.SequenceNameArg, types.RegClass}}, ReturnType: tree.FixedReturnType(types.Int), Info: "Advances the value of the sequence and returns the final value.", Fn: importNextValByID, diff --git a/pkg/sql/sem/builtins/BUILD.bazel b/pkg/sql/sem/builtins/BUILD.bazel index 27910369e2ea..91587127299e 100644 --- a/pkg/sql/sem/builtins/BUILD.bazel +++ b/pkg/sql/sem/builtins/BUILD.bazel @@ -68,6 +68,7 @@ go_library( "//pkg/sql/rowenc/keyside", "//pkg/sql/rowenc/valueside", "//pkg/sql/sem/asof", + "//pkg/sql/sem/builtins/builtinconstants", "//pkg/sql/sem/catconstants", "//pkg/sql/sem/catid", "//pkg/sql/sem/eval", @@ -151,6 +152,7 @@ go_test( "//pkg/sql/parser", "//pkg/sql/pgwire/pgerror", "//pkg/sql/randgen", + "//pkg/sql/sem/builtins/builtinconstants", "//pkg/sql/sem/eval", "//pkg/sql/sem/tree", "//pkg/sql/sem/tree/treewindow", diff --git a/pkg/sql/sem/builtins/builtinconstants/BUILD.bazel b/pkg/sql/sem/builtins/builtinconstants/BUILD.bazel new file mode 100644 index 000000000000..39e1b205cdb7 --- /dev/null +++ b/pkg/sql/sem/builtins/builtinconstants/BUILD.bazel @@ -0,0 +1,8 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "builtinconstants", + srcs = ["constants.go"], + importpath = "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins/builtinconstants", + visibility = ["//visibility:public"], +) diff --git a/pkg/sql/sem/builtins/builtinconstants/constants.go b/pkg/sql/sem/builtins/builtinconstants/constants.go new file mode 100644 index 000000000000..ca0cc9ac3bec --- /dev/null +++ b/pkg/sql/sem/builtins/builtinconstants/constants.go @@ -0,0 +1,56 @@ +// Copyright 2022 The Cockroach Authors. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +package builtinconstants + +import "time" + +// SequenceNameArg represents the name of sequence (string) arguments in +// builtin functions. +const SequenceNameArg = "sequence_name" + +// DefaultFollowerReadDuration represents the default time span back from the +// statement time which we wish to be recent and old enough for a follower read. +// Such a default will be returned if we do *not* have an enterprise license +// on a CCL distribution, which may not result in reading from the nearest replica. +const DefaultFollowerReadDuration = -4800 * time.Millisecond + +// MaxAllocatedStringSize represents the maximum allowed string length +// in various string related builtin function. +const MaxAllocatedStringSize = 128 * 1024 * 1024 + +// ErrInsufficientArgsFmtString represents illegal or unknown argument(s) to +// builtin functions. +const ErrInsufficientArgsFmtString = "unknown signature: %s()" + +// The following constants are used to categorize builtin functions +// for documentation. +const ( + CategoryArray = "Array" + CategoryComparison = "Comparison" + CategoryCompatibility = "Compatibility" + CategoryCrypto = "Cryptographic" + CategoryDateAndTime = "Date and time" + CategoryEnum = "Enum" + CategoryFullTextSearch = "Full Text Search" + CategoryGenerator = "Set-returning" + CategoryTrigram = "Trigrams" + CategoryFuzzyStringMatching = "Fuzzy String Matching" + CategoryIDGeneration = "ID generation" + CategoryJSON = "JSONB" + CategoryMultiRegion = "Multi-region" + CategoryMultiTenancy = "Multi-tenancy" + CategorySequences = "Sequence" + CategorySpatial = "Spatial" + CategoryString = "String and byte" + CategorySystemInfo = "System info" + CategorySystemRepair = "System repair" + CategoryStreamIngestion = "Stream Ingestion" +) diff --git a/pkg/sql/sem/builtins/builtins.go b/pkg/sql/sem/builtins/builtins.go index ea65ccebf68a..4f240f31b5b8 100644 --- a/pkg/sql/sem/builtins/builtins.go +++ b/pkg/sql/sem/builtins/builtins.go @@ -62,6 +62,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/rowenc" "github.com/cockroachdb/cockroach/pkg/sql/rowenc/keyside" "github.com/cockroachdb/cockroach/pkg/sql/sem/asof" + "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins/builtinconstants" "github.com/cockroachdb/cockroach/pkg/sql/sem/catid" "github.com/cockroachdb/cockroach/pkg/sql/sem/eval" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" @@ -102,48 +103,16 @@ var ( errChrValueTooLarge = pgerror.Newf(pgcode.InvalidParameterValue, "input value must be <= %d (maximum Unicode code point)", utf8.MaxRune) errStringTooLarge = pgerror.Newf(pgcode.ProgramLimitExceeded, - "requested length too large, exceeds %s", humanizeutil.IBytes(maxAllocatedStringSize)) + "requested length too large, exceeds %s", humanizeutil.IBytes(builtinconstants.MaxAllocatedStringSize)) errInvalidNull = pgerror.New(pgcode.InvalidParameterValue, "input cannot be NULL") - // SequenceNameArg represents the name of sequence (string) arguments in - // builtin functions. - SequenceNameArg = "sequence_name" -) - -const defaultFollowerReadDuration = -4800 * time.Millisecond - -const maxAllocatedStringSize = 128 * 1024 * 1024 - -const errInsufficientArgsFmtString = "unknown signature: %s()" - -const ( - categoryArray = "Array" - categoryComparison = "Comparison" - categoryCompatibility = "Compatibility" - categoryCrypto = "Cryptographic" - categoryDateAndTime = "Date and time" - categoryEnum = "Enum" - categoryFullTextSearch = "Full Text Search" - categoryGenerator = "Set-returning" - categoryTrigram = "Trigrams" - categoryFuzzyStringMatching = "Fuzzy String Matching" - categoryIDGeneration = "ID generation" - categoryJSON = "JSONB" - categoryMultiRegion = "Multi-region" - categoryMultiTenancy = "Multi-tenancy" - categorySequences = "Sequence" - categorySpatial = "Spatial" - categoryString = "String and byte" - categorySystemInfo = "System info" - categorySystemRepair = "System repair" - categoryStreamIngestion = "Stream Ingestion" ) func categorizeType(t *types.T) string { switch t.Family() { case types.DateFamily, types.IntervalFamily, types.TimestampFamily, types.TimestampTZFamily: - return categoryDateAndTime + return builtinconstants.CategoryDateAndTime case types.StringFamily, types.BytesFamily: - return categoryString + return builtinconstants.CategoryString default: return strings.ToUpper(t.String()) } @@ -207,7 +176,9 @@ func GetBuiltinProperties(name string) (*tree.FunctionProperties, []tree.Overloa func defProps() tree.FunctionProperties { return tree.FunctionProperties{} } // arrayProps is used below for array functions. -func arrayProps() tree.FunctionProperties { return tree.FunctionProperties{Category: categoryArray} } +func arrayProps() tree.FunctionProperties { + return tree.FunctionProperties{Category: builtinconstants.CategoryArray} +} // arrayPropsNullableArgs is used below for array functions that accept NULLs as arguments. func arrayPropsNullableArgs() tree.FunctionProperties { @@ -250,7 +221,7 @@ var builtins = map[string]builtinDefinition{ "char_length": lengthImpls(false /* includeBitOverload */), "character_length": lengthImpls(false /* includeBitOverload */), - "bit_length": makeBuiltin(tree.FunctionProperties{Category: categoryString}, + "bit_length": makeBuiltin(tree.FunctionProperties{Category: builtinconstants.CategoryString}, stringOverload1( func(_ *eval.Context, s string) (tree.Datum, error) { return tree.NewDInt(tree.DInt(len(s) * 8)), nil @@ -277,7 +248,7 @@ var builtins = map[string]builtinDefinition{ ), ), - "octet_length": makeBuiltin(tree.FunctionProperties{Category: categoryString}, + "octet_length": makeBuiltin(tree.FunctionProperties{Category: builtinconstants.CategoryString}, stringOverload1( func(_ *eval.Context, s string) (tree.Datum, error) { return tree.NewDInt(tree.DInt(len(s))), nil @@ -306,7 +277,7 @@ var builtins = map[string]builtinDefinition{ // TODO(pmattis): What string functions should also support types.Bytes? - "lower": makeBuiltin(tree.FunctionProperties{Category: categoryString}, + "lower": makeBuiltin(tree.FunctionProperties{Category: builtinconstants.CategoryString}, stringOverload1( func(evalCtx *eval.Context, s string) (tree.Datum, error) { return tree.NewDString(strings.ToLower(s)), nil @@ -317,7 +288,7 @@ var builtins = map[string]builtinDefinition{ ), ), - "unaccent": makeBuiltin(tree.FunctionProperties{Category: categoryString}, + "unaccent": makeBuiltin(tree.FunctionProperties{Category: builtinconstants.CategoryString}, stringOverload1( func(evalCtx *eval.Context, s string) (tree.Datum, error) { var b strings.Builder @@ -337,7 +308,7 @@ var builtins = map[string]builtinDefinition{ ), ), - "upper": makeBuiltin(tree.FunctionProperties{Category: categoryString}, + "upper": makeBuiltin(tree.FunctionProperties{Category: builtinconstants.CategoryString}, stringOverload1( func(evalCtx *eval.Context, s string) (tree.Datum, error) { return tree.NewDString(strings.ToUpper(s)), nil @@ -348,7 +319,7 @@ var builtins = map[string]builtinDefinition{ ), ), - "prettify_statement": makeBuiltin(tree.FunctionProperties{Category: categoryString}, + "prettify_statement": makeBuiltin(tree.FunctionProperties{Category: builtinconstants.CategoryString}, stringOverload1( func(evalCtx *eval.Context, s string) (tree.Datum, error) { formattedStmt, err := prettyStatement(tree.DefaultPrettyCfg(), s) @@ -407,7 +378,7 @@ var builtins = map[string]builtinDefinition{ continue } length += len(string(tree.MustBeDString(d))) - if length > maxAllocatedStringSize { + if length > builtinconstants.MaxAllocatedStringSize { return nil, errStringTooLarge } buffer.WriteString(string(tree.MustBeDString(d))) @@ -433,7 +404,7 @@ var builtins = map[string]builtinDefinition{ ReturnType: tree.FixedReturnType(types.String), Fn: func(_ *eval.Context, args tree.Datums) (tree.Datum, error) { if len(args) == 0 { - return nil, pgerror.Newf(pgcode.UndefinedFunction, errInsufficientArgsFmtString, "concat_ws") + return nil, pgerror.Newf(pgcode.UndefinedFunction, builtinconstants.ErrInsufficientArgsFmtString, "concat_ws") } if args[0] == tree.DNull { return tree.DNull, nil @@ -447,7 +418,7 @@ var builtins = map[string]builtinDefinition{ continue } length += len(prefix) + len(string(tree.MustBeDString(d))) - if length > maxAllocatedStringSize { + if length > builtinconstants.MaxAllocatedStringSize { return nil, errStringTooLarge } // Note: we can't use the range index here because that @@ -471,7 +442,7 @@ var builtins = map[string]builtinDefinition{ ), // https://www.postgresql.org/docs/10/static/functions-string.html#FUNCTIONS-STRING-OTHER - "convert_from": makeBuiltin(tree.FunctionProperties{Category: categoryString}, + "convert_from": makeBuiltin(tree.FunctionProperties{Category: builtinconstants.CategoryString}, tree.Overload{ Types: tree.ArgTypes{{"str", types.Bytes}, {"enc", types.String}}, ReturnType: tree.FixedReturnType(types.String), @@ -504,7 +475,7 @@ var builtins = map[string]builtinDefinition{ }), // https://www.postgresql.org/docs/10/static/functions-string.html#FUNCTIONS-STRING-OTHER - "convert_to": makeBuiltin(tree.FunctionProperties{Category: categoryString}, + "convert_to": makeBuiltin(tree.FunctionProperties{Category: builtinconstants.CategoryString}, tree.Overload{ Types: tree.ArgTypes{{"str", types.String}, {"enc", types.String}}, ReturnType: tree.FixedReturnType(types.Bytes), @@ -537,7 +508,7 @@ var builtins = map[string]builtinDefinition{ }), // https://www.postgresql.org/docs/9.0/functions-binarystring.html#FUNCTIONS-BINARYSTRING-OTHER - "get_bit": makeBuiltin(tree.FunctionProperties{Category: categoryString}, + "get_bit": makeBuiltin(tree.FunctionProperties{Category: builtinconstants.CategoryString}, tree.Overload{ Types: tree.ArgTypes{{"bit_string", types.VarBit}, {"index", types.Int}}, ReturnType: tree.FixedReturnType(types.Int), @@ -577,7 +548,7 @@ var builtins = map[string]builtinDefinition{ }), // https://www.postgresql.org/docs/9.0/functions-binarystring.html#FUNCTIONS-BINARYSTRING-OTHER - "get_byte": makeBuiltin(tree.FunctionProperties{Category: categoryString}, + "get_byte": makeBuiltin(tree.FunctionProperties{Category: builtinconstants.CategoryString}, tree.Overload{ Types: tree.ArgTypes{{"byte_string", types.Bytes}, {"index", types.Int}}, ReturnType: tree.FixedReturnType(types.Int), @@ -596,7 +567,7 @@ var builtins = map[string]builtinDefinition{ }), // https://www.postgresql.org/docs/9.0/functions-binarystring.html#FUNCTIONS-BINARYSTRING-OTHER - "set_bit": makeBuiltin(tree.FunctionProperties{Category: categoryString}, + "set_bit": makeBuiltin(tree.FunctionProperties{Category: builtinconstants.CategoryString}, tree.Overload{ Types: tree.ArgTypes{ {"bit_string", types.VarBit}, @@ -658,7 +629,7 @@ var builtins = map[string]builtinDefinition{ }), // https://www.postgresql.org/docs/9.0/functions-binarystring.html#FUNCTIONS-BINARYSTRING-OTHER - "set_byte": makeBuiltin(tree.FunctionProperties{Category: categoryString}, + "set_byte": makeBuiltin(tree.FunctionProperties{Category: builtinconstants.CategoryString}, tree.Overload{ Types: tree.ArgTypes{ {"byte_string", types.Bytes}, @@ -704,7 +675,7 @@ var builtins = map[string]builtinDefinition{ "uuid_generate_v1": makeBuiltin( tree.FunctionProperties{ - Category: categoryIDGeneration, + Category: builtinconstants.CategoryIDGeneration, }, tree.Overload{ Types: tree.ArgTypes{}, @@ -727,7 +698,7 @@ var builtins = map[string]builtinDefinition{ "uuid_generate_v1mc": makeBuiltin( tree.FunctionProperties{ - Category: categoryIDGeneration, + Category: builtinconstants.CategoryIDGeneration, }, tree.Overload{ Types: tree.ArgTypes{}, @@ -748,7 +719,7 @@ var builtins = map[string]builtinDefinition{ "uuid_generate_v3": makeBuiltin( tree.FunctionProperties{ - Category: categoryIDGeneration, + Category: builtinconstants.CategoryIDGeneration, }, tree.Overload{ Types: tree.ArgTypes{{"namespace", types.Uuid}, {"name", types.String}}, @@ -768,7 +739,7 @@ var builtins = map[string]builtinDefinition{ "uuid_generate_v5": makeBuiltin( tree.FunctionProperties{ - Category: categoryIDGeneration, + Category: builtinconstants.CategoryIDGeneration, }, tree.Overload{ Types: tree.ArgTypes{{"namespace", types.Uuid}, {"name", types.String}}, @@ -823,7 +794,7 @@ var builtins = map[string]builtinDefinition{ "gen_random_ulid": makeBuiltin( tree.FunctionProperties{ - Category: categoryIDGeneration, + Category: builtinconstants.CategoryIDGeneration, }, tree.Overload{ Types: tree.ArgTypes{}, @@ -1185,7 +1156,7 @@ var builtins = map[string]builtinDefinition{ } else if ln/count != len(s) { // Detect overflow and trigger an error. return nil, errStringTooLarge - } else if ln > maxAllocatedStringSize { + } else if ln > builtinconstants.MaxAllocatedStringSize { return nil, errStringTooLarge } @@ -1296,7 +1267,7 @@ var builtins = map[string]builtinDefinition{ }, ), - "ascii": makeBuiltin(tree.FunctionProperties{Category: categoryString}, + "ascii": makeBuiltin(tree.FunctionProperties{Category: builtinconstants.CategoryString}, stringOverload1( func(_ *eval.Context, s string) (tree.Datum, error) { for _, ch := range s { @@ -1309,7 +1280,7 @@ var builtins = map[string]builtinDefinition{ volatility.Immutable, )), - "chr": makeBuiltin(tree.FunctionProperties{Category: categoryString}, + "chr": makeBuiltin(tree.FunctionProperties{Category: builtinconstants.CategoryString}, tree.Overload{ Types: tree.ArgTypes{{"val", types.Int}}, ReturnType: tree.FixedReturnType(types.String), @@ -1392,7 +1363,7 @@ var builtins = map[string]builtinDefinition{ ), "to_hex": makeBuiltin( - tree.FunctionProperties{Category: categoryString}, + tree.FunctionProperties{Category: builtinconstants.CategoryString}, tree.Overload{ Types: tree.ArgTypes{{"val", types.Int}}, ReturnType: tree.FixedReturnType(types.String), @@ -1428,7 +1399,7 @@ var builtins = map[string]builtinDefinition{ ), "to_english": makeBuiltin( - tree.FunctionProperties{Category: categoryString}, + tree.FunctionProperties{Category: builtinconstants.CategoryString}, tree.Overload{ Types: tree.ArgTypes{{"val", types.Int}}, ReturnType: tree.FixedReturnType(types.String), @@ -1466,7 +1437,7 @@ var builtins = map[string]builtinDefinition{ // The SQL parser coerces POSITION to STRPOS. "strpos": makeBuiltin( - tree.FunctionProperties{Category: categoryString}, + tree.FunctionProperties{Category: builtinconstants.CategoryString}, stringOverload2( "input", "find", @@ -1552,7 +1523,7 @@ var builtins = map[string]builtinDefinition{ ), "lpad": makeBuiltin( - tree.FunctionProperties{Category: categoryString}, + tree.FunctionProperties{Category: builtinconstants.CategoryString}, tree.Overload{ Types: tree.ArgTypes{{"string", types.String}, {"length", types.Int}}, ReturnType: tree.FixedReturnType(types.String), @@ -1589,7 +1560,7 @@ var builtins = map[string]builtinDefinition{ ), "rpad": makeBuiltin( - tree.FunctionProperties{Category: categoryString}, + tree.FunctionProperties{Category: builtinconstants.CategoryString}, tree.Overload{ Types: tree.ArgTypes{{"string", types.String}, {"length", types.Int}}, ReturnType: tree.FixedReturnType(types.String), @@ -1700,7 +1671,7 @@ var builtins = map[string]builtinDefinition{ "reverse": makeBuiltin(defProps(), stringOverload1( func(evalCtx *eval.Context, s string) (tree.Datum, error) { - if len(s) > maxAllocatedStringSize { + if len(s) > builtinconstants.MaxAllocatedStringSize { return nil, errStringTooLarge } runes := []rune(s) @@ -1733,7 +1704,7 @@ var builtins = map[string]builtinDefinition{ // Largest result is if there are no replacements. maxResultLen = int64(len(input)) } - if maxResultLen > maxAllocatedStringSize { + if maxResultLen > builtinconstants.MaxAllocatedStringSize { return nil, errStringTooLarge } result := strings.Replace(input, from, to, -1) @@ -2018,7 +1989,7 @@ var builtins = map[string]builtinDefinition{ // quote_nullable is the same as quote_literal but accepts NULL arguments. "quote_nullable": makeBuiltin( tree.FunctionProperties{ - Category: categoryString, + Category: builtinconstants.CategoryString, NullableArgs: true, }, tree.Overload{ @@ -2154,7 +2125,7 @@ var builtins = map[string]builtinDefinition{ "unique_rowid": makeBuiltin( tree.FunctionProperties{ - Category: categoryIDGeneration, + Category: builtinconstants.CategoryIDGeneration, }, tree.Overload{ Types: tree.ArgTypes{}, @@ -2173,7 +2144,7 @@ var builtins = map[string]builtinDefinition{ "unordered_unique_rowid": makeBuiltin( tree.FunctionProperties{ - Category: categoryIDGeneration, + Category: builtinconstants.CategoryIDGeneration, }, tree.Overload{ Types: tree.ArgTypes{}, @@ -2194,12 +2165,12 @@ var builtins = map[string]builtinDefinition{ "nextval": makeBuiltin( tree.FunctionProperties{ - Category: categorySequences, + Category: builtinconstants.CategorySequences, DistsqlBlocklist: true, HasSequenceArguments: true, }, tree.Overload{ - Types: tree.ArgTypes{{SequenceNameArg, types.String}}, + Types: tree.ArgTypes{{builtinconstants.SequenceNameArg, types.String}}, ReturnType: tree.FixedReturnType(types.Int), Fn: func(evalCtx *eval.Context, args tree.Datums) (tree.Datum, error) { name := tree.MustBeDString(args[0]) @@ -2217,7 +2188,7 @@ var builtins = map[string]builtinDefinition{ Volatility: volatility.Volatile, }, tree.Overload{ - Types: tree.ArgTypes{{SequenceNameArg, types.RegClass}}, + Types: tree.ArgTypes{{builtinconstants.SequenceNameArg, types.RegClass}}, ReturnType: tree.FixedReturnType(types.Int), Fn: func(evalCtx *eval.Context, args tree.Datums) (tree.Datum, error) { oid := tree.MustBeDOid(args[0]) @@ -2234,12 +2205,12 @@ var builtins = map[string]builtinDefinition{ "currval": makeBuiltin( tree.FunctionProperties{ - Category: categorySequences, + Category: builtinconstants.CategorySequences, DistsqlBlocklist: true, HasSequenceArguments: true, }, tree.Overload{ - Types: tree.ArgTypes{{SequenceNameArg, types.String}}, + Types: tree.ArgTypes{{builtinconstants.SequenceNameArg, types.String}}, ReturnType: tree.FixedReturnType(types.Int), Fn: func(evalCtx *eval.Context, args tree.Datums) (tree.Datum, error) { name := tree.MustBeDString(args[0]) @@ -2257,7 +2228,7 @@ var builtins = map[string]builtinDefinition{ Volatility: volatility.Volatile, }, tree.Overload{ - Types: tree.ArgTypes{{SequenceNameArg, types.RegClass}}, + Types: tree.ArgTypes{{builtinconstants.SequenceNameArg, types.RegClass}}, ReturnType: tree.FixedReturnType(types.Int), Fn: func(evalCtx *eval.Context, args tree.Datums) (tree.Datum, error) { oid := tree.MustBeDOid(args[0]) @@ -2274,7 +2245,7 @@ var builtins = map[string]builtinDefinition{ "lastval": makeBuiltin( tree.FunctionProperties{ - Category: categorySequences, + Category: builtinconstants.CategorySequences, }, tree.Overload{ Types: tree.ArgTypes{}, @@ -2295,12 +2266,12 @@ var builtins = map[string]builtinDefinition{ // See https://github.com/cockroachdb/cockroach/issues/21564 "setval": makeBuiltin( tree.FunctionProperties{ - Category: categorySequences, + Category: builtinconstants.CategorySequences, DistsqlBlocklist: true, HasSequenceArguments: true, }, tree.Overload{ - Types: tree.ArgTypes{{SequenceNameArg, types.String}, {"value", types.Int}}, + Types: tree.ArgTypes{{builtinconstants.SequenceNameArg, types.String}, {"value", types.Int}}, ReturnType: tree.FixedReturnType(types.Int), Fn: func(evalCtx *eval.Context, args tree.Datums) (tree.Datum, error) { name := tree.MustBeDString(args[0]) @@ -2321,7 +2292,7 @@ var builtins = map[string]builtinDefinition{ Volatility: volatility.Volatile, }, tree.Overload{ - Types: tree.ArgTypes{{SequenceNameArg, types.RegClass}, {"value", types.Int}}, + Types: tree.ArgTypes{{builtinconstants.SequenceNameArg, types.RegClass}, {"value", types.Int}}, ReturnType: tree.FixedReturnType(types.Int), Fn: func(evalCtx *eval.Context, args tree.Datums) (tree.Datum, error) { oid := tree.MustBeDOid(args[0]) @@ -2338,7 +2309,7 @@ var builtins = map[string]builtinDefinition{ }, tree.Overload{ Types: tree.ArgTypes{ - {SequenceNameArg, types.String}, {"value", types.Int}, {"is_called", types.Bool}, + {builtinconstants.SequenceNameArg, types.String}, {"value", types.Int}, {"is_called", types.Bool}, }, ReturnType: tree.FixedReturnType(types.Int), Fn: func(evalCtx *eval.Context, args tree.Datums) (tree.Datum, error) { @@ -2362,7 +2333,7 @@ var builtins = map[string]builtinDefinition{ }, tree.Overload{ Types: tree.ArgTypes{ - {SequenceNameArg, types.RegClass}, {"value", types.Int}, {"is_called", types.Bool}, + {builtinconstants.SequenceNameArg, types.RegClass}, {"value", types.Int}, {"is_called", types.Bool}, }, ReturnType: tree.FixedReturnType(types.Int), Fn: func(evalCtx *eval.Context, args tree.Datums) (tree.Datum, error) { @@ -2387,7 +2358,7 @@ var builtins = map[string]builtinDefinition{ "greatest": makeBuiltin( tree.FunctionProperties{ - Category: categoryComparison, + Category: builtinconstants.CategoryComparison, NullableArgs: true, }, tree.Overload{ @@ -2403,7 +2374,7 @@ var builtins = map[string]builtinDefinition{ "least": makeBuiltin( tree.FunctionProperties{ - Category: categoryComparison, + Category: builtinconstants.CategoryComparison, NullableArgs: true, }, tree.Overload{ @@ -2421,7 +2392,7 @@ var builtins = map[string]builtinDefinition{ "experimental_strftime": makeBuiltin( tree.FunctionProperties{ - Category: categoryDateAndTime, + Category: builtinconstants.CategoryDateAndTime, }, tree.Overload{ Types: tree.ArgTypes{{"input", types.Timestamp}, {"extract_format", types.String}}, @@ -2478,7 +2449,7 @@ var builtins = map[string]builtinDefinition{ "experimental_strptime": makeBuiltin( tree.FunctionProperties{ - Category: categoryDateAndTime, + Category: builtinconstants.CategoryDateAndTime, }, tree.Overload{ Types: tree.ArgTypes{{"input", types.String}, {"format", types.String}}, @@ -2652,7 +2623,7 @@ var builtins = map[string]builtinDefinition{ // 2022-03-10 09:57:43.123456+00 // "to_timestamp": makeBuiltin( - tree.FunctionProperties{Category: categoryDateAndTime}, + tree.FunctionProperties{Category: builtinconstants.CategoryDateAndTime}, tree.Overload{ Types: tree.ArgTypes{{"timestamp", types.Float}}, ReturnType: tree.FixedReturnType(types.TimestampTZ), @@ -2774,7 +2745,7 @@ leaseholder for a given range. Note that this function requires an enterprise license on a CCL distribution to return a result that is less likely the closest replica. It is otherwise hardcoded as %s from the statement time, which may not result in reading from the -nearest replica.`, defaultFollowerReadDuration), +nearest replica.`, builtinconstants.DefaultFollowerReadDuration), Volatility: volatility.Volatile, }, ), @@ -2846,7 +2817,7 @@ nearest replica.`, defaultFollowerReadDuration), "cluster_logical_timestamp": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, tree.Overload{ Types: tree.ArgTypes{}, @@ -2905,7 +2876,7 @@ value if you rely on the HLC for accuracy.`, ), "timeofday": makeBuiltin( - tree.FunctionProperties{Category: categoryDateAndTime}, + tree.FunctionProperties{Category: builtinconstants.CategoryDateAndTime}, tree.Overload{ Types: tree.ArgTypes{}, ReturnType: tree.FixedReturnType(types.String), @@ -2925,7 +2896,7 @@ value if you rely on the HLC for accuracy.`, // TODO(knz,otan): Remove in 20.2. "extract_duration": makeBuiltin( - tree.FunctionProperties{Category: categoryDateAndTime}, + tree.FunctionProperties{Category: builtinconstants.CategoryDateAndTime}, tree.Overload{ Types: tree.ArgTypes{{"element", types.String}, {"input", types.Interval}}, ReturnType: tree.FixedReturnType(types.Int), @@ -2998,7 +2969,7 @@ value if you rely on the HLC for accuracy.`, // > respectively.) // "date_trunc": makeBuiltin( - tree.FunctionProperties{Category: categoryDateAndTime}, + tree.FunctionProperties{Category: builtinconstants.CategoryDateAndTime}, tree.Overload{ Types: tree.ArgTypes{{"element", types.String}, {"input", types.Timestamp}}, ReturnType: tree.FixedReturnType(types.Timestamp), @@ -3785,39 +3756,39 @@ value if you rely on the HLC for accuracy.`, })), // Full text search functions. - "ts_match_qv": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: categoryFullTextSearch}), - "ts_match_vq": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: categoryFullTextSearch}), - "tsvector_cmp": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: categoryFullTextSearch}), - "tsvector_concat": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: categoryFullTextSearch}), - "ts_debug": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: categoryFullTextSearch}), - "ts_headline": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: categoryFullTextSearch}), - "ts_lexize": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: categoryFullTextSearch}), - "websearch_to_tsquery": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: categoryFullTextSearch}), - "array_to_tsvector": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: categoryFullTextSearch}), - "get_current_ts_config": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: categoryFullTextSearch}), - "numnode": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: categoryFullTextSearch}), - "plainto_tsquery": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: categoryFullTextSearch}), - "phraseto_tsquery": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: categoryFullTextSearch}), - "querytree": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: categoryFullTextSearch}), - "setweight": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: categoryFullTextSearch}), - "strip": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: categoryFullTextSearch}), - "to_tsquery": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: categoryFullTextSearch}), - "to_tsvector": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: categoryFullTextSearch}), - "json_to_tsvector": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: categoryFullTextSearch}), - "jsonb_to_tsvector": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: categoryFullTextSearch}), - "ts_delete": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: categoryFullTextSearch}), - "ts_filter": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: categoryFullTextSearch}), - "ts_rank": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: categoryFullTextSearch}), - "ts_rank_cd": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: categoryFullTextSearch}), - "ts_rewrite": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: categoryFullTextSearch}), - "tsquery_phrase": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: categoryFullTextSearch}), - "tsvector_to_array": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: categoryFullTextSearch}), - "tsvector_update_trigger": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: categoryFullTextSearch}), - "tsvector_update_trigger_column": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: categoryFullTextSearch}), + "ts_match_qv": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: builtinconstants.CategoryFullTextSearch}), + "ts_match_vq": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: builtinconstants.CategoryFullTextSearch}), + "tsvector_cmp": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: builtinconstants.CategoryFullTextSearch}), + "tsvector_concat": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: builtinconstants.CategoryFullTextSearch}), + "ts_debug": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: builtinconstants.CategoryFullTextSearch}), + "ts_headline": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: builtinconstants.CategoryFullTextSearch}), + "ts_lexize": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: builtinconstants.CategoryFullTextSearch}), + "websearch_to_tsquery": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: builtinconstants.CategoryFullTextSearch}), + "array_to_tsvector": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: builtinconstants.CategoryFullTextSearch}), + "get_current_ts_config": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: builtinconstants.CategoryFullTextSearch}), + "numnode": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: builtinconstants.CategoryFullTextSearch}), + "plainto_tsquery": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: builtinconstants.CategoryFullTextSearch}), + "phraseto_tsquery": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: builtinconstants.CategoryFullTextSearch}), + "querytree": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: builtinconstants.CategoryFullTextSearch}), + "setweight": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: builtinconstants.CategoryFullTextSearch}), + "strip": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: builtinconstants.CategoryFullTextSearch}), + "to_tsquery": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: builtinconstants.CategoryFullTextSearch}), + "to_tsvector": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: builtinconstants.CategoryFullTextSearch}), + "json_to_tsvector": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: builtinconstants.CategoryFullTextSearch}), + "jsonb_to_tsvector": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: builtinconstants.CategoryFullTextSearch}), + "ts_delete": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: builtinconstants.CategoryFullTextSearch}), + "ts_filter": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: builtinconstants.CategoryFullTextSearch}), + "ts_rank": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: builtinconstants.CategoryFullTextSearch}), + "ts_rank_cd": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: builtinconstants.CategoryFullTextSearch}), + "ts_rewrite": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: builtinconstants.CategoryFullTextSearch}), + "tsquery_phrase": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: builtinconstants.CategoryFullTextSearch}), + "tsvector_to_array": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: builtinconstants.CategoryFullTextSearch}), + "tsvector_update_trigger": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: builtinconstants.CategoryFullTextSearch}), + "tsvector_update_trigger_column": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 7821, Category: builtinconstants.CategoryFullTextSearch}), // Fuzzy String Matching "soundex": makeBuiltin( - tree.FunctionProperties{Category: categoryString}, + tree.FunctionProperties{Category: builtinconstants.CategoryString}, tree.Overload{ Types: tree.ArgTypes{{"source", types.String}}, ReturnType: tree.FixedReturnType(types.String), @@ -3834,7 +3805,7 @@ value if you rely on the HLC for accuracy.`, // but this name matches the name in PostgreSQL. // See https://www.postgresql.org/docs/current/fuzzystrmatch.html" "difference": makeBuiltin( - tree.FunctionProperties{Category: categoryString}, + tree.FunctionProperties{Category: builtinconstants.CategoryString}, tree.Overload{ Types: tree.ArgTypes{{"source", types.String}, {"target", types.String}}, ReturnType: tree.FixedReturnType(types.String), @@ -3883,24 +3854,24 @@ value if you rely on the HLC for accuracy.`, "charge for each edit operation. Maximum input length is 255 characters.", Volatility: volatility.Immutable, }), - "levenshtein_less_equal": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 56820, Category: categoryFuzzyStringMatching}), - "metaphone": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 56820, Category: categoryFuzzyStringMatching}), - "dmetaphone_alt": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 56820, Category: categoryFuzzyStringMatching}), + "levenshtein_less_equal": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 56820, Category: builtinconstants.CategoryFuzzyStringMatching}), + "metaphone": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 56820, Category: builtinconstants.CategoryFuzzyStringMatching}), + "dmetaphone_alt": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 56820, Category: builtinconstants.CategoryFuzzyStringMatching}), // JSON functions. // The behavior of both the JSON and JSONB data types in CockroachDB is // similar to the behavior of the JSONB data type in Postgres. - "json_to_recordset": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 33285, Category: categoryJSON}), - "jsonb_to_recordset": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 33285, Category: categoryJSON}), + "json_to_recordset": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 33285, Category: builtinconstants.CategoryJSON}), + "jsonb_to_recordset": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 33285, Category: builtinconstants.CategoryJSON}), - "jsonb_path_exists": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 22513, Category: categoryJSON}), - "jsonb_path_exists_opr": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 22513, Category: categoryJSON}), - "jsonb_path_match": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 22513, Category: categoryJSON}), - "jsonb_path_match_opr": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 22513, Category: categoryJSON}), - "jsonb_path_query": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 22513, Category: categoryJSON}), - "jsonb_path_query_array": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 22513, Category: categoryJSON}), - "jsonb_path_query_first": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 22513, Category: categoryJSON}), + "jsonb_path_exists": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 22513, Category: builtinconstants.CategoryJSON}), + "jsonb_path_exists_opr": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 22513, Category: builtinconstants.CategoryJSON}), + "jsonb_path_match": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 22513, Category: builtinconstants.CategoryJSON}), + "jsonb_path_match_opr": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 22513, Category: builtinconstants.CategoryJSON}), + "jsonb_path_query": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 22513, Category: builtinconstants.CategoryJSON}), + "jsonb_path_query_array": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 22513, Category: builtinconstants.CategoryJSON}), + "jsonb_path_query_first": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 22513, Category: builtinconstants.CategoryJSON}), "json_remove_path": makeBuiltin(jsonProps(), tree.Overload{ @@ -4154,7 +4125,7 @@ value if you rely on the HLC for accuracy.`, "crdb_internal.datums_to_bytes": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, NullableArgs: true, Undocumented: true, CompositeInsensitive: true, @@ -4301,7 +4272,7 @@ value if you rely on the HLC for accuracy.`, // Enum functions. "enum_first": makeBuiltin( - tree.FunctionProperties{NullableArgs: true, Category: categoryEnum}, + tree.FunctionProperties{NullableArgs: true, Category: builtinconstants.CategoryEnum}, tree.Overload{ Types: tree.ArgTypes{{"val", types.AnyEnum}}, ReturnType: tree.IdentityReturnType(0), @@ -4322,7 +4293,7 @@ value if you rely on the HLC for accuracy.`, ), "enum_last": makeBuiltin( - tree.FunctionProperties{NullableArgs: true, Category: categoryEnum}, + tree.FunctionProperties{NullableArgs: true, Category: builtinconstants.CategoryEnum}, tree.Overload{ Types: tree.ArgTypes{{"val", types.AnyEnum}}, ReturnType: tree.IdentityReturnType(0), @@ -4343,7 +4314,7 @@ value if you rely on the HLC for accuracy.`, ), "enum_range": makeBuiltin( - tree.FunctionProperties{NullableArgs: true, Category: categoryEnum}, + tree.FunctionProperties{NullableArgs: true, Category: builtinconstants.CategoryEnum}, tree.Overload{ Types: tree.ArgTypes{{"val", types.AnyEnum}}, ReturnType: tree.ArrayOfFirstNonNullReturnType(), @@ -4446,7 +4417,7 @@ value if you rely on the HLC for accuracy.`, // https://www.postgresql.org/docs/10/static/functions-info.html "version": makeBuiltin( - tree.FunctionProperties{Category: categorySystemInfo}, + tree.FunctionProperties{Category: builtinconstants.CategorySystemInfo}, tree.Overload{ Types: tree.ArgTypes{}, ReturnType: tree.FixedReturnType(types.String), @@ -4460,7 +4431,7 @@ value if you rely on the HLC for accuracy.`, // https://www.postgresql.org/docs/10/static/functions-info.html "current_database": makeBuiltin( - tree.FunctionProperties{Category: categorySystemInfo}, + tree.FunctionProperties{Category: builtinconstants.CategorySystemInfo}, tree.Overload{ Types: tree.ArgTypes{}, ReturnType: tree.FixedReturnType(types.String), @@ -4484,7 +4455,7 @@ value if you rely on the HLC for accuracy.`, // SQL client against a pg server. "current_schema": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, DistsqlBlocklist: true, }, tree.Overload{ @@ -4521,7 +4492,7 @@ value if you rely on the HLC for accuracy.`, // pg_catalog and pg_temp (if one exists). "current_schemas": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, DistsqlBlocklist: true, }, tree.Overload{ @@ -4557,7 +4528,7 @@ value if you rely on the HLC for accuracy.`, // https://www.postgresql.org/docs/10/static/functions-info.html "current_user": makeBuiltin( - tree.FunctionProperties{Category: categorySystemInfo}, + tree.FunctionProperties{Category: builtinconstants.CategorySystemInfo}, tree.Overload{ Types: tree.ArgTypes{}, ReturnType: tree.FixedReturnType(types.String), @@ -4574,7 +4545,7 @@ value if you rely on the HLC for accuracy.`, ), "session_user": makeBuiltin( - tree.FunctionProperties{Category: categorySystemInfo}, + tree.FunctionProperties{Category: builtinconstants.CategorySystemInfo}, tree.Overload{ Types: tree.ArgTypes{}, ReturnType: tree.FixedReturnType(types.String), @@ -4593,7 +4564,7 @@ value if you rely on the HLC for accuracy.`, // Get the current trace ID. "crdb_internal.trace_id": makeBuiltin( - tree.FunctionProperties{Category: categorySystemInfo}, + tree.FunctionProperties{Category: builtinconstants.CategorySystemInfo}, tree.Overload{ Types: tree.ArgTypes{}, ReturnType: tree.FixedReturnType(types.Int), @@ -4626,7 +4597,7 @@ value if you rely on the HLC for accuracy.`, // Toggles all spans of the requested trace to verbose or non-verbose. "crdb_internal.set_trace_verbose": makeBuiltin( - tree.FunctionProperties{Category: categorySystemInfo}, + tree.FunctionProperties{Category: builtinconstants.CategorySystemInfo}, tree.Overload{ Types: tree.ArgTypes{ {"trace_id", types.Int}, @@ -4678,7 +4649,7 @@ value if you rely on the HLC for accuracy.`, ), "crdb_internal.locality_value": makeBuiltin( - tree.FunctionProperties{Category: categorySystemInfo}, + tree.FunctionProperties{Category: builtinconstants.CategorySystemInfo}, tree.Overload{ Types: tree.ArgTypes{{"key", types.String}}, ReturnType: tree.FixedReturnType(types.String), @@ -4702,7 +4673,7 @@ value if you rely on the HLC for accuracy.`, ), "crdb_internal.cluster_setting_encoded_default": makeBuiltin( - tree.FunctionProperties{Category: categorySystemInfo}, + tree.FunctionProperties{Category: builtinconstants.CategorySystemInfo}, tree.Overload{ Types: tree.ArgTypes{{"setting", types.String}}, ReturnType: tree.FixedReturnType(types.String), @@ -4733,7 +4704,7 @@ value if you rely on the HLC for accuracy.`, ), "crdb_internal.decode_cluster_setting": makeBuiltin( - tree.FunctionProperties{Category: categorySystemInfo}, + tree.FunctionProperties{Category: builtinconstants.CategorySystemInfo}, tree.Overload{ Types: tree.ArgTypes{ {"setting", types.String}, @@ -4774,7 +4745,7 @@ value if you rely on the HLC for accuracy.`, ), "crdb_internal.node_executable_version": makeBuiltin( - tree.FunctionProperties{Category: categorySystemInfo}, + tree.FunctionProperties{Category: builtinconstants.CategorySystemInfo}, tree.Overload{ Types: tree.ArgTypes{}, ReturnType: tree.FixedReturnType(types.String), @@ -4788,7 +4759,7 @@ value if you rely on the HLC for accuracy.`, ), "crdb_internal.active_version": makeBuiltin( - tree.FunctionProperties{Category: categorySystemInfo}, + tree.FunctionProperties{Category: builtinconstants.CategorySystemInfo}, tree.Overload{ Types: tree.ArgTypes{}, ReturnType: tree.FixedReturnType(types.Jsonb), @@ -4810,7 +4781,7 @@ value if you rely on the HLC for accuracy.`, ), "crdb_internal.is_at_least_version": makeBuiltin( - tree.FunctionProperties{Category: categorySystemInfo}, + tree.FunctionProperties{Category: builtinconstants.CategorySystemInfo}, tree.Overload{ Types: tree.ArgTypes{{"version", types.String}}, ReturnType: tree.FixedReturnType(types.Bool), @@ -4838,7 +4809,7 @@ value if you rely on the HLC for accuracy.`, ), "crdb_internal.approximate_timestamp": makeBuiltin( - tree.FunctionProperties{Category: categorySystemInfo}, + tree.FunctionProperties{Category: builtinconstants.CategorySystemInfo}, tree.Overload{ Types: tree.ArgTypes{{"timestamp", types.Decimal}}, ReturnType: tree.FixedReturnType(types.Timestamp), @@ -4851,7 +4822,7 @@ value if you rely on the HLC for accuracy.`, ), "crdb_internal.cluster_id": makeBuiltin( - tree.FunctionProperties{Category: categorySystemInfo}, + tree.FunctionProperties{Category: builtinconstants.CategorySystemInfo}, tree.Overload{ Types: tree.ArgTypes{}, ReturnType: tree.FixedReturnType(types.Uuid), @@ -4864,7 +4835,7 @@ value if you rely on the HLC for accuracy.`, ), "crdb_internal.node_id": makeBuiltin( - tree.FunctionProperties{Category: categorySystemInfo}, + tree.FunctionProperties{Category: builtinconstants.CategorySystemInfo}, tree.Overload{ Types: tree.ArgTypes{}, ReturnType: tree.FixedReturnType(types.Int), @@ -4881,7 +4852,7 @@ value if you rely on the HLC for accuracy.`, ), "crdb_internal.cluster_name": makeBuiltin( - tree.FunctionProperties{Category: categorySystemInfo}, + tree.FunctionProperties{Category: builtinconstants.CategorySystemInfo}, tree.Overload{ Types: tree.ArgTypes{}, ReturnType: tree.FixedReturnType(types.String), @@ -4895,7 +4866,7 @@ value if you rely on the HLC for accuracy.`, "crdb_internal.create_tenant": makeBuiltin( tree.FunctionProperties{ - Category: categoryMultiTenancy, + Category: builtinconstants.CategoryMultiTenancy, NullableArgs: true, Undocumented: true, }, @@ -4923,7 +4894,7 @@ value if you rely on the HLC for accuracy.`, ), "crdb_internal.create_join_token": makeBuiltin( - tree.FunctionProperties{Category: categorySystemInfo}, + tree.FunctionProperties{Category: builtinconstants.CategorySystemInfo}, tree.Overload{ Types: tree.ArgTypes{}, ReturnType: tree.FixedReturnType(types.String), @@ -4941,7 +4912,7 @@ value if you rely on the HLC for accuracy.`, "crdb_internal.destroy_tenant": makeBuiltin( tree.FunctionProperties{ - Category: categoryMultiTenancy, + Category: builtinconstants.CategoryMultiTenancy, Undocumented: true, }, tree.Overload{ @@ -4990,7 +4961,7 @@ value if you rely on the HLC for accuracy.`, ), "crdb_internal.encode_key": makeBuiltin( - tree.FunctionProperties{Category: categorySystemInfo}, + tree.FunctionProperties{Category: builtinconstants.CategorySystemInfo}, tree.Overload{ Types: tree.ArgTypes{ {"table_id", types.Int}, @@ -5029,7 +5000,7 @@ value if you rely on the HLC for accuracy.`, "crdb_internal.force_error": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, tree.Overload{ Types: tree.ArgTypes{{"errorCode", types.String}, {"msg", types.String}}, @@ -5059,7 +5030,7 @@ value if you rely on the HLC for accuracy.`, "crdb_internal.notice": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, tree.Overload{ Types: tree.ArgTypes{{"msg", types.String}}, @@ -5101,7 +5072,7 @@ value if you rely on the HLC for accuracy.`, "crdb_internal.force_assertion_error": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, tree.Overload{ Types: tree.ArgTypes{{"msg", types.String}}, @@ -5121,7 +5092,7 @@ value if you rely on the HLC for accuracy.`, "crdb_internal.void_func": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, tree.Overload{ Types: tree.ArgTypes{}, @@ -5136,7 +5107,7 @@ value if you rely on the HLC for accuracy.`, "crdb_internal.force_panic": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, tree.Overload{ Types: tree.ArgTypes{{"msg", types.String}}, @@ -5169,7 +5140,7 @@ value if you rely on the HLC for accuracy.`, "crdb_internal.force_log_fatal": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, tree.Overload{ Types: tree.ArgTypes{{"msg", types.String}}, @@ -5202,7 +5173,7 @@ value if you rely on the HLC for accuracy.`, // different than the current statement's transaction. "crdb_internal.force_retry": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, tree.Overload{ Types: tree.ArgTypes{{"val", types.Interval}}, @@ -5224,7 +5195,7 @@ value if you rely on the HLC for accuracy.`, // Fetches the corresponding lease_holder for the request key. "crdb_internal.lease_holder": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, tree.Overload{ Types: tree.ArgTypes{{"key", types.Bytes}}, @@ -5252,7 +5223,7 @@ value if you rely on the HLC for accuracy.`, // Identity function which is marked as impure to avoid constant folding. "crdb_internal.no_constant_folding": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, tree.Overload{ Types: tree.ArgTypes{{"input", types.Any}}, @@ -5269,7 +5240,7 @@ value if you rely on the HLC for accuracy.`, // fields. "crdb_internal.pretty_key": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, tree.Overload{ Types: tree.ArgTypes{ @@ -5292,7 +5263,7 @@ value if you rely on the HLC for accuracy.`, // fields. "crdb_internal.pretty_span": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, tree.Overload{ Types: tree.ArgTypes{ @@ -5317,7 +5288,7 @@ value if you rely on the HLC for accuracy.`, // Return statistics about a range. "crdb_internal.range_stats": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, tree.Overload{ Types: tree.ArgTypes{ @@ -5357,7 +5328,7 @@ value if you rely on the HLC for accuracy.`, // Returns NULL if none is found. // Errors if there is no permission for the current user to view the descriptor. "crdb_internal.get_namespace_id": makeBuiltin( - tree.FunctionProperties{Category: categorySystemInfo}, + tree.FunctionProperties{Category: builtinconstants.CategorySystemInfo}, tree.Overload{ Types: tree.ArgTypes{{"parent_id", types.Int}, {"name", types.String}}, ReturnType: tree.FixedReturnType(types.Int), @@ -5414,7 +5385,7 @@ value if you rely on the HLC for accuracy.`, // Returns NULL if none is found. // Errors if there is no permission for the current user to view the descriptor. "crdb_internal.get_database_id": makeBuiltin( - tree.FunctionProperties{Category: categorySystemInfo}, + tree.FunctionProperties{Category: builtinconstants.CategorySystemInfo}, tree.Overload{ Types: tree.ArgTypes{{"name", types.String}}, ReturnType: tree.FixedReturnType(types.Int), @@ -5442,7 +5413,7 @@ value if you rely on the HLC for accuracy.`, // Returns NULL if a zone configuration is not found. // Errors if there is no permission for the current user to view the zone config. "crdb_internal.get_zone_config": makeBuiltin( - tree.FunctionProperties{Category: categorySystemInfo}, + tree.FunctionProperties{Category: builtinconstants.CategorySystemInfo}, tree.Overload{ Types: tree.ArgTypes{{"namespace_id", types.Int}}, ReturnType: tree.FixedReturnType(types.Bytes), @@ -5466,7 +5437,7 @@ value if you rely on the HLC for accuracy.`, "crdb_internal.set_vmodule": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, tree.Overload{ Types: tree.ArgTypes{{"vmodule_string", types.String}}, @@ -5498,7 +5469,7 @@ value if you rely on the HLC for accuracy.`, "crdb_internal.get_vmodule": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, tree.Overload{ Types: tree.ArgTypes{}, @@ -5523,7 +5494,7 @@ value if you rely on the HLC for accuracy.`, // generated for a value. "crdb_internal.num_geo_inverted_index_entries": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, NullableArgs: true, }, tree.Overload{ @@ -5576,7 +5547,7 @@ value if you rely on the HLC for accuracy.`, // generated for a value. "crdb_internal.num_inverted_index_entries": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, NullableArgs: true, }, tree.Overload{ @@ -5652,7 +5623,7 @@ value if you rely on the HLC for accuracy.`, // Note: it would be a privacy leak to extend this to check arbitrary usernames. "crdb_internal.is_admin": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, DistsqlBlocklist: true, }, tree.Overload{ @@ -5678,7 +5649,7 @@ value if you rely on the HLC for accuracy.`, // Note: it would be a privacy leak to extend this to check arbitrary usernames. "crdb_internal.has_role_option": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, DistsqlBlocklist: true, }, tree.Overload{ @@ -5709,7 +5680,7 @@ value if you rely on the HLC for accuracy.`, "crdb_internal.assignment_cast": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, // The idiomatic usage of this function is to "pass" a target type T // by passing NULL::T, so we must allow NULL arguments. NullableArgs: true, @@ -5739,7 +5710,7 @@ value if you rely on the HLC for accuracy.`, "crdb_internal.round_decimal_values": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, tree.Overload{ Types: tree.ArgTypes{ @@ -5800,7 +5771,7 @@ value if you rely on the HLC for accuracy.`, ), "crdb_internal.completed_migrations": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, tree.Overload{ Types: tree.ArgTypes{}, @@ -5827,7 +5798,7 @@ value if you rely on the HLC for accuracy.`, ), "crdb_internal.unsafe_upsert_descriptor": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemRepair, + Category: builtinconstants.CategorySystemRepair, DistsqlBlocklist: true, Undocumented: true, }, @@ -5871,7 +5842,7 @@ value if you rely on the HLC for accuracy.`, ), "crdb_internal.unsafe_delete_descriptor": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemRepair, + Category: builtinconstants.CategorySystemRepair, DistsqlBlocklist: true, Undocumented: true, }, @@ -5913,7 +5884,7 @@ value if you rely on the HLC for accuracy.`, ), "crdb_internal.unsafe_upsert_namespace_entry": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemRepair, + Category: builtinconstants.CategorySystemRepair, DistsqlBlocklist: true, Undocumented: true, }, @@ -5969,7 +5940,7 @@ value if you rely on the HLC for accuracy.`, ), "crdb_internal.unsafe_delete_namespace_entry": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemRepair, + Category: builtinconstants.CategorySystemRepair, DistsqlBlocklist: true, Undocumented: true, }, @@ -6026,7 +5997,7 @@ value if you rely on the HLC for accuracy.`, // Returns true iff the given sqlliveness session is not expired. "crdb_internal.sql_liveness_is_alive": makeBuiltin( - tree.FunctionProperties{Category: categoryMultiTenancy}, + tree.FunctionProperties{Category: builtinconstants.CategoryMultiTenancy}, tree.Overload{ Types: tree.ArgTypes{{"session_id", types.Bytes}}, ReturnType: tree.FixedReturnType(types.Bool), @@ -6047,7 +6018,7 @@ value if you rely on the HLC for accuracy.`, // TODO(jeffswenson): Delete internal_crdb.gc_tenant after the DestroyTenant // changes are deployed to all Cockroach Cloud serverless hosts. tree.FunctionProperties{ - Category: categoryMultiTenancy, + Category: builtinconstants.CategoryMultiTenancy, Undocumented: true, }, tree.Overload{ @@ -6073,7 +6044,7 @@ value if you rely on the HLC for accuracy.`, // Used to configure the tenant token bucket. See UpdateTenantResourceLimits. "crdb_internal.update_tenant_resource_limits": makeBuiltin( tree.FunctionProperties{ - Category: categoryMultiTenancy, + Category: builtinconstants.CategoryMultiTenancy, Undocumented: true, }, tree.Overload{ @@ -6117,7 +6088,7 @@ value if you rely on the HLC for accuracy.`, "crdb_internal.compact_engine_span": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemRepair, + Category: builtinconstants.CategorySystemRepair, DistsqlBlocklist: true, Undocumented: true, }, @@ -6154,7 +6125,7 @@ value if you rely on the HLC for accuracy.`, "crdb_internal.increment_feature_counter": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, Undocumented: true, }, tree.Overload{ @@ -6177,7 +6148,7 @@ value if you rely on the HLC for accuracy.`, "num_nulls": makeBuiltin( tree.FunctionProperties{ - Category: categoryComparison, + Category: builtinconstants.CategoryComparison, NullableArgs: true, }, tree.Overload{ @@ -6200,7 +6171,7 @@ value if you rely on the HLC for accuracy.`, ), "num_nonnulls": makeBuiltin( tree.FunctionProperties{ - Category: categoryComparison, + Category: builtinconstants.CategoryComparison, NullableArgs: true, }, tree.Overload{ @@ -6224,7 +6195,7 @@ value if you rely on the HLC for accuracy.`, GatewayRegionBuiltinName: makeBuiltin( tree.FunctionProperties{ - Category: categoryMultiRegion, + Category: builtinconstants.CategoryMultiRegion, // We should always evaluate this built-in at the gateway. DistsqlBlocklist: true, }, @@ -6247,7 +6218,7 @@ the locality flag on node startup. Returns an error if no region is set.`, }, ), DefaultToDatabasePrimaryRegionBuiltinName: makeBuiltin( - tree.FunctionProperties{Category: categoryMultiRegion}, + tree.FunctionProperties{Category: builtinconstants.CategoryMultiRegion}, stringOverload1( func(evalCtx *eval.Context, s string) (tree.Datum, error) { regionConfig, err := evalCtx.Regions.CurrentDatabaseRegionConfig(evalCtx.Context) @@ -6275,7 +6246,7 @@ the locality flag on node startup. Returns an error if no region is set.`, ), ), RehomeRowBuiltinName: makeBuiltin( - tree.FunctionProperties{Category: categoryMultiRegion}, + tree.FunctionProperties{Category: builtinconstants.CategoryMultiRegion}, tree.Overload{ Types: tree.ArgTypes{}, ReturnType: tree.FixedReturnType(types.String), @@ -6311,7 +6282,7 @@ the locality flag on node startup. Returns an error if no region is set.`, }, ), "crdb_internal.validate_multi_region_zone_configs": makeBuiltin( - tree.FunctionProperties{Category: categoryMultiRegion}, + tree.FunctionProperties{Category: builtinconstants.CategoryMultiRegion}, tree.Overload{ Types: tree.ArgTypes{}, ReturnType: tree.FixedReturnType(types.Bool), @@ -6331,7 +6302,7 @@ the locality flag on node startup. Returns an error if no region is set.`, }, ), "crdb_internal.reset_multi_region_zone_configs_for_table": makeBuiltin( - tree.FunctionProperties{Category: categoryMultiRegion}, + tree.FunctionProperties{Category: builtinconstants.CategoryMultiRegion}, tree.Overload{ Types: tree.ArgTypes{{"id", types.Int}}, ReturnType: tree.FixedReturnType(types.Bool), @@ -6353,7 +6324,7 @@ table.`, }, ), "crdb_internal.reset_multi_region_zone_configs_for_database": makeBuiltin( - tree.FunctionProperties{Category: categoryMultiRegion}, + tree.FunctionProperties{Category: builtinconstants.CategoryMultiRegion}, tree.Overload{ Types: tree.ArgTypes{{"id", types.Int}}, ReturnType: tree.FixedReturnType(types.Bool), @@ -6375,7 +6346,7 @@ enabled.`, }, ), "crdb_internal.filter_multiregion_fields_from_zone_config_sql": makeBuiltin( - tree.FunctionProperties{Category: categoryMultiRegion}, + tree.FunctionProperties{Category: builtinconstants.CategoryMultiRegion}, stringOverload1( func(evalCtx *eval.Context, s string) (tree.Datum, error) { stmt, err := parser.ParseOne(s) @@ -6411,7 +6382,7 @@ table's zone configuration this will return NULL.`, ), "crdb_internal.reset_index_usage_stats": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, DistsqlBlocklist: true, // applicable only on the gateway }, tree.Overload{ @@ -6440,7 +6411,7 @@ table's zone configuration this will return NULL.`, ), "crdb_internal.reset_sql_stats": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, DistsqlBlocklist: true, // applicable only on the gateway }, tree.Overload{ @@ -6473,7 +6444,7 @@ table's zone configuration this will return NULL.`, // for table %d" "crdb_internal.force_delete_table_data": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemRepair, + Category: builtinconstants.CategorySystemRepair, }, tree.Overload{ Types: tree.ArgTypes{{"id", types.Int}}, @@ -6494,7 +6465,7 @@ table's zone configuration this will return NULL.`, "crdb_internal.serialize_session": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, tree.Overload{ Types: tree.ArgTypes{}, @@ -6509,7 +6480,7 @@ table's zone configuration this will return NULL.`, "crdb_internal.deserialize_session": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, tree.Overload{ Types: tree.ArgTypes{{"session", types.Bytes}}, @@ -6525,7 +6496,7 @@ table's zone configuration this will return NULL.`, "crdb_internal.create_session_revival_token": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, tree.Overload{ Types: tree.ArgTypes{}, @@ -6539,7 +6510,7 @@ table's zone configuration this will return NULL.`, ), "crdb_internal.validate_session_revival_token": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, tree.Overload{ Types: tree.ArgTypes{{"token", types.Bytes}}, @@ -6555,7 +6526,7 @@ table's zone configuration this will return NULL.`, "crdb_internal.validate_ttl_scheduled_jobs": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, tree.Overload{ Types: tree.ArgTypes{}, @@ -6570,7 +6541,7 @@ table's zone configuration this will return NULL.`, "crdb_internal.repair_ttl_table_scheduled_job": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, tree.Overload{ Types: tree.ArgTypes{{"oid", types.Oid}}, @@ -6589,7 +6560,7 @@ table's zone configuration this will return NULL.`, "crdb_internal.check_password_hash_format": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, tree.Overload{ Types: tree.ArgTypes{{"password", types.Bytes}}, @@ -6613,7 +6584,7 @@ table's zone configuration this will return NULL.`, "crdb_internal.schedule_sql_stats_compaction": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, tree.Overload{ Types: tree.ArgTypes{}, @@ -6636,7 +6607,7 @@ table's zone configuration this will return NULL.`, "crdb_internal.revalidate_unique_constraints_in_all_tables": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, tree.Overload{ Types: tree.ArgTypes{}, @@ -6655,7 +6626,7 @@ in the current database. Returns an error if validation fails.`, "crdb_internal.revalidate_unique_constraints_in_table": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, tree.Overload{ Types: tree.ArgTypes{{"table_name", types.String}}, @@ -6679,7 +6650,7 @@ table. Returns an error if validation fails.`, "crdb_internal.revalidate_unique_constraint": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, tree.Overload{ Types: tree.ArgTypes{{"table_name", types.String}, {"constraint_name", types.String}}, @@ -6705,7 +6676,7 @@ table. Returns an error if validation fails.`, ), "crdb_internal.is_constraint_active": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, tree.Overload{ Types: tree.ArgTypes{{"table_name", types.String}, {"constraint_name", types.String}}, @@ -6736,7 +6707,7 @@ active for the current transaction.`, "crdb_internal.kv_set_queue_active": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemRepair, + Category: builtinconstants.CategorySystemRepair, DistsqlBlocklist: true, // applicable only on the gateway Undocumented: true, }, @@ -6816,7 +6787,7 @@ run from. One of 'mvccGC', 'merge', 'split', 'replicate', 'replicaGC', "crdb_internal.kv_enqueue_replica": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemRepair, + Category: builtinconstants.CategorySystemRepair, DistsqlBlocklist: true, // applicable only on the gateway Undocumented: true, }, @@ -6974,7 +6945,7 @@ specified store on the node it's run from. One of 'mvccGC', 'merge', 'split', "crdb_internal.request_statement_bundle": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, DistsqlBlocklist: true, // applicable only on the gateway }, tree.Overload{ @@ -7040,7 +7011,7 @@ expires until the statement bundle is collected`, } var lengthImpls = func(incBitOverload bool) builtinDefinition { - b := makeBuiltin(tree.FunctionProperties{Category: categoryString}, + b := makeBuiltin(tree.FunctionProperties{Category: builtinconstants.CategoryString}, stringOverload1( func(_ *eval.Context, s string) (tree.Datum, error) { return tree.NewDInt(tree.DInt(utf8.RuneCountInString(s))), nil @@ -7072,7 +7043,7 @@ var lengthImpls = func(incBitOverload bool) builtinDefinition { return b } -var substringImpls = makeBuiltin(tree.FunctionProperties{Category: categoryString}, +var substringImpls = makeBuiltin(tree.FunctionProperties{Category: builtinconstants.CategoryString}, tree.Overload{ Types: tree.ArgTypes{ {"input", types.String}, @@ -7307,7 +7278,7 @@ func getSubstringFromIndexOfLengthBytes(str, errMsg string, start, length int) ( var generateRandomUUID4Impl = makeBuiltin( tree.FunctionProperties{ - Category: categoryIDGeneration, + Category: builtinconstants.CategoryIDGeneration, }, tree.Overload{ Types: tree.ArgTypes{}, @@ -7326,7 +7297,7 @@ var generateRandomUUID4Impl = makeBuiltin( var uuidV4Impl = makeBuiltin( tree.FunctionProperties{ - Category: categoryIDGeneration, + Category: builtinconstants.CategoryIDGeneration, }, tree.Overload{ Types: tree.ArgTypes{}, @@ -7342,7 +7313,7 @@ var uuidV4Impl = makeBuiltin( func generateConstantUUIDImpl(id uuid.UUID, info string) builtinDefinition { return makeBuiltin( tree.FunctionProperties{ - Category: categoryIDGeneration, + Category: builtinconstants.CategoryIDGeneration, }, tree.Overload{ Types: tree.ArgTypes{}, @@ -7462,7 +7433,7 @@ func txnTSWithPrecisionOverloads(preferTZOverload bool) []tree.Overload { func txnTSImplBuiltin(preferTZOverload bool) builtinDefinition { return makeBuiltin( tree.FunctionProperties{ - Category: categoryDateAndTime, + Category: builtinconstants.CategoryDateAndTime, }, txnTSOverloads(preferTZOverload)..., ) @@ -7471,7 +7442,7 @@ func txnTSImplBuiltin(preferTZOverload bool) builtinDefinition { func txnTSWithPrecisionImplBuiltin(preferTZOverload bool) builtinDefinition { return makeBuiltin( tree.FunctionProperties{ - Category: categoryDateAndTime, + Category: builtinconstants.CategoryDateAndTime, }, txnTSWithPrecisionOverloads(preferTZOverload)..., ) @@ -7766,7 +7737,7 @@ var jsonTypeOfImpl = tree.Overload{ func jsonProps() tree.FunctionProperties { return tree.FunctionProperties{ - Category: categoryJSON, + Category: builtinconstants.CategoryJSON, } } @@ -8025,7 +7996,7 @@ func arrayBuiltin(impl func(*types.T) tree.Overload) builtinDefinition { tupleOverload.DistsqlBlocklist = true overloads = append(overloads, tupleOverload) return builtinDefinition{ - props: tree.FunctionProperties{Category: categoryArray}, + props: tree.FunctionProperties{Category: builtinconstants.CategoryArray}, overloads: overloads, } } @@ -8635,7 +8606,7 @@ func arrayLower(arr *tree.DArray, dim int64) tree.Datum { } var extractBuiltin = makeBuiltin( - tree.FunctionProperties{Category: categoryDateAndTime}, + tree.FunctionProperties{Category: builtinconstants.CategoryDateAndTime}, tree.Overload{ Types: tree.ArgTypes{{"element", types.String}, {"input", types.Timestamp}}, ReturnType: tree.FixedReturnType(types.Float), @@ -9371,7 +9342,7 @@ func padMaybeTruncate(s string, length int, fill string) (ok bool, slen int, ret } func lpad(s string, length int, fill string) (string, error) { - if length > maxAllocatedStringSize { + if length > builtinconstants.MaxAllocatedStringSize { return "", errStringTooLarge } ok, slen, ret := padMaybeTruncate(s, length, fill) @@ -9389,7 +9360,7 @@ func lpad(s string, length int, fill string) (string, error) { } func rpad(s string, length int, fill string) (string, error) { - if length > maxAllocatedStringSize { + if length > builtinconstants.MaxAllocatedStringSize { return "", errStringTooLarge } ok, slen, ret := padMaybeTruncate(s, length, fill) @@ -9441,7 +9412,7 @@ func recentTimestamp(ctx *eval.Context) (time.Time, error) { ctx.Context, pgnotice.Newf("follower reads disabled because you are running a non-CCL distribution"), ) - return ctx.StmtTimestamp.Add(defaultFollowerReadDuration), nil + return ctx.StmtTimestamp.Add(builtinconstants.DefaultFollowerReadDuration), nil } offset, err := EvalFollowerReadOffset(ctx.ClusterID, ctx.Settings) if err != nil { @@ -9450,7 +9421,7 @@ func recentTimestamp(ctx *eval.Context) (time.Time, error) { ctx.ClientNoticeSender.BufferClientNotice( ctx.Context, pgnotice.Newf("follower reads disabled: %s", err.Error()), ) - return ctx.StmtTimestamp.Add(defaultFollowerReadDuration), nil + return ctx.StmtTimestamp.Add(builtinconstants.DefaultFollowerReadDuration), nil } return time.Time{}, err } diff --git a/pkg/sql/sem/builtins/builtins_test.go b/pkg/sql/sem/builtins/builtins_test.go index 68722f5ec045..de6223f78991 100644 --- a/pkg/sql/sem/builtins/builtins_test.go +++ b/pkg/sql/sem/builtins/builtins_test.go @@ -21,6 +21,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/base" "github.com/cockroachdb/cockroach/pkg/settings/cluster" + "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins/builtinconstants" "github.com/cockroachdb/cockroach/pkg/sql/sem/eval" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/types" @@ -37,16 +38,16 @@ import ( func TestCategory(t *testing.T) { defer leaktest.AfterTest(t)() - if expected, actual := categoryString, builtins["lower"].props.Category; expected != actual { + if expected, actual := builtinconstants.CategoryString, builtins["lower"].props.Category; expected != actual { t.Fatalf("bad category: expected %q got %q", expected, actual) } - if expected, actual := categoryString, builtins["length"].props.Category; expected != actual { + if expected, actual := builtinconstants.CategoryString, builtins["length"].props.Category; expected != actual { t.Fatalf("bad category: expected %q got %q", expected, actual) } - if expected, actual := categoryDateAndTime, builtins["now"].props.Category; expected != actual { + if expected, actual := builtinconstants.CategoryDateAndTime, builtins["now"].props.Category; expected != actual { t.Fatalf("bad category: expected %q got %q", expected, actual) } - if expected, actual := categorySystemInfo, builtins["version"].props.Category; expected != actual { + if expected, actual := builtinconstants.CategorySystemInfo, builtins["version"].props.Category; expected != actual { t.Fatalf("bad category: expected %q got %q", expected, actual) } } diff --git a/pkg/sql/sem/builtins/generator_builtins.go b/pkg/sql/sem/builtins/generator_builtins.go index 0459220d8df4..e591d8f5d0fc 100644 --- a/pkg/sql/sem/builtins/generator_builtins.go +++ b/pkg/sql/sem/builtins/generator_builtins.go @@ -24,6 +24,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror" "github.com/cockroachdb/cockroach/pkg/sql/protoreflect" + "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins/builtinconstants" "github.com/cockroachdb/cockroach/pkg/sql/sem/eval" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/sem/volatility" @@ -64,14 +65,14 @@ func initGeneratorBuiltins() { func genProps() tree.FunctionProperties { return tree.FunctionProperties{ Class: tree.GeneratorClass, - Category: categoryGenerator, + Category: builtinconstants.CategoryGenerator, } } func genPropsWithLabels(returnLabels []string) tree.FunctionProperties { return tree.FunctionProperties{ Class: tree.GeneratorClass, - Category: categoryGenerator, + Category: builtinconstants.CategoryGenerator, ReturnLabels: returnLabels, } } @@ -332,7 +333,7 @@ var generators = map[string]builtinDefinition{ "crdb_internal.check_consistency": makeBuiltin( tree.FunctionProperties{ Class: tree.GeneratorClass, - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, makeGeneratorOverload( tree.ArgTypes{ @@ -357,7 +358,7 @@ var generators = map[string]builtinDefinition{ "crdb_internal.list_sql_keys_in_range": makeBuiltin( tree.FunctionProperties{ Class: tree.GeneratorClass, - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, makeGeneratorOverload( tree.ArgTypes{ @@ -373,7 +374,7 @@ var generators = map[string]builtinDefinition{ "crdb_internal.payloads_for_span": makeBuiltin( tree.FunctionProperties{ Class: tree.GeneratorClass, - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, makeGeneratorOverload( tree.ArgTypes{ @@ -388,7 +389,7 @@ var generators = map[string]builtinDefinition{ "crdb_internal.payloads_for_trace": makeBuiltin( tree.FunctionProperties{ Class: tree.GeneratorClass, - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, }, makeGeneratorOverload( tree.ArgTypes{ @@ -1423,7 +1424,7 @@ func (g *jsonEachGenerator) Values() (tree.Datums, error) { var jsonPopulateProps = tree.FunctionProperties{ Class: tree.GeneratorClass, - Category: categoryGenerator, + Category: builtinconstants.CategoryGenerator, // The typical way to call json_populate_record is to send NULL::atype as the // first argument, so we have to accept nullable args. NullableArgs: true, diff --git a/pkg/sql/sem/builtins/geo_builtins.go b/pkg/sql/sem/builtins/geo_builtins.go index f000ac0b4b61..f1bf76dd5c8d 100644 --- a/pkg/sql/sem/builtins/geo_builtins.go +++ b/pkg/sql/sem/builtins/geo_builtins.go @@ -30,6 +30,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/parser" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror" + "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins/builtinconstants" "github.com/cockroachdb/cockroach/pkg/sql/sem/eval" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/sem/volatility" @@ -6200,7 +6201,7 @@ See http://developers.google.com/maps/documentation/utilities/polylinealgorithm` "st_estimatedextent": makeBuiltin( tree.FunctionProperties{ - Category: categorySpatial, + Category: builtinconstants.CategorySpatial, }, tree.Overload{ Types: tree.ArgTypes{ @@ -6261,7 +6262,7 @@ The parent_only boolean is always ignored.`, "addgeometrycolumn": makeBuiltin( tree.FunctionProperties{ Class: tree.SQLClass, - Category: categorySpatial, + Category: builtinconstants.CategorySpatial, }, tree.Overload{ Types: tree.ArgTypes{ @@ -7305,7 +7306,7 @@ func initGeoBuiltins() { if _, exists := builtins[k]; exists { panic("duplicate builtin: " + k) } - v.props.Category = categorySpatial + v.props.Category = builtinconstants.CategorySpatial v.props.AvailableOnPublicSchema = true builtins[k] = v } diff --git a/pkg/sql/sem/builtins/overlaps_builtins.go b/pkg/sql/sem/builtins/overlaps_builtins.go index 1745978aa7ae..c18351bab470 100644 --- a/pkg/sql/sem/builtins/overlaps_builtins.go +++ b/pkg/sql/sem/builtins/overlaps_builtins.go @@ -13,6 +13,7 @@ package builtins import ( "time" + "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins/builtinconstants" "github.com/cockroachdb/cockroach/pkg/sql/sem/eval" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/sem/volatility" @@ -57,7 +58,7 @@ func initOverlapsBuiltins() { var overlapsBuiltins = map[string]builtinDefinition{ "overlaps": makeBuiltin( tree.FunctionProperties{ - Category: categoryDateAndTime, + Category: builtinconstants.CategoryDateAndTime, NullableArgs: false, }, makeOverlapsOverloads()..., diff --git a/pkg/sql/sem/builtins/pg_builtins.go b/pkg/sql/sem/builtins/pg_builtins.go index 19027b97cbfd..0104f385ab4f 100644 --- a/pkg/sql/sem/builtins/pg_builtins.go +++ b/pkg/sql/sem/builtins/pg_builtins.go @@ -24,6 +24,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror" "github.com/cockroachdb/cockroach/pkg/sql/privilege" "github.com/cockroachdb/cockroach/pkg/sql/rowenc/valueside" + "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins/builtinconstants" "github.com/cockroachdb/cockroach/pkg/sql/sem/catconstants" "github.com/cockroachdb/cockroach/pkg/sql/sem/eval" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" @@ -101,7 +102,7 @@ func initPGBuiltins() { if _, exists := builtins[k]; exists { panic("duplicate builtin: " + k) } - v.props.Category = categoryCompatibility + v.props.Category = builtinconstants.CategoryCompatibility builtins[k] = v } @@ -156,7 +157,7 @@ var errUnimplemented = pgerror.New(pgcode.FeatureNotSupported, "unimplemented") func makeTypeIOBuiltin(argTypes tree.TypeList, returnType *types.T) builtinDefinition { return builtinDefinition{ props: tree.FunctionProperties{ - Category: categoryCompatibility, + Category: builtinconstants.CategoryCompatibility, }, overloads: []tree.Overload{ { @@ -508,7 +509,7 @@ func makeCreateRegDef(typ *types.T) builtinDefinition { } func makeToRegOverload(typ *types.T, helpText string) builtinDefinition { - return makeBuiltin(tree.FunctionProperties{Category: categorySystemInfo}, + return makeBuiltin(tree.FunctionProperties{Category: builtinconstants.CategorySystemInfo}, tree.Overload{ Types: tree.ArgTypes{ {"text", types.String}, @@ -573,7 +574,7 @@ var pgBuiltins = map[string]builtinDefinition{ // Here getdatabaseencoding just returns UTF8 because, // CockroachDB supports just UTF8 for now. "getdatabaseencoding": makeBuiltin( - tree.FunctionProperties{Category: categorySystemInfo}, + tree.FunctionProperties{Category: builtinconstants.CategorySystemInfo}, tree.Overload{ Types: tree.ArgTypes{}, ReturnType: tree.FixedReturnType(types.String), @@ -734,7 +735,7 @@ var pgBuiltins = map[string]builtinDefinition{ "pg_get_serial_sequence": makeBuiltin( tree.FunctionProperties{ - Category: categorySequences, + Category: builtinconstants.CategorySequences, }, tree.Overload{ Types: tree.ArgTypes{{"table_name", types.String}, {"column_name", types.String}}, @@ -842,7 +843,7 @@ var pgBuiltins = map[string]builtinDefinition{ // https://www.postgresql.org/docs/10/functions-info.html#FUNCTIONS-INFO-CATALOG-TABLE "pg_collation_for": makeBuiltin( - tree.FunctionProperties{Category: categoryString}, + tree.FunctionProperties{Category: builtinconstants.CategoryString}, tree.Overload{ Types: tree.ArgTypes{{"str", types.Any}}, ReturnType: tree.FixedReturnType(types.String), @@ -1765,7 +1766,7 @@ SELECT description // See https://www.postgresql.org/docs/10/functions-admin.html#FUNCTIONS-ADMIN-SET "current_setting": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, DistsqlBlocklist: true, }, tree.Overload{ @@ -1774,7 +1775,7 @@ SELECT description Fn: func(ctx *eval.Context, args tree.Datums) (tree.Datum, error) { return getSessionVar(ctx, string(tree.MustBeDString(args[0])), false /* missingOk */) }, - Info: categorySystemInfo, + Info: builtinconstants.CategorySystemInfo, Volatility: volatility.Stable, }, tree.Overload{ @@ -1783,7 +1784,7 @@ SELECT description Fn: func(ctx *eval.Context, args tree.Datums) (tree.Datum, error) { return getSessionVar(ctx, string(tree.MustBeDString(args[0])), bool(tree.MustBeDBool(args[1]))) }, - Info: categorySystemInfo, + Info: builtinconstants.CategorySystemInfo, Volatility: volatility.Stable, }, ), @@ -1791,7 +1792,7 @@ SELECT description // See https://www.postgresql.org/docs/10/functions-admin.html#FUNCTIONS-ADMIN-SET "set_config": makeBuiltin( tree.FunctionProperties{ - Category: categorySystemInfo, + Category: builtinconstants.CategorySystemInfo, DistsqlBlocklist: true, }, tree.Overload{ @@ -1806,7 +1807,7 @@ SELECT description } return getSessionVar(ctx, varName, false /* missingOk */) }, - Info: categorySystemInfo, + Info: builtinconstants.CategorySystemInfo, Volatility: volatility.Volatile, }, ), @@ -2006,7 +2007,7 @@ SELECT description }, ), - "information_schema._pg_numeric_precision": makeBuiltin(tree.FunctionProperties{Category: categorySystemInfo}, + "information_schema._pg_numeric_precision": makeBuiltin(tree.FunctionProperties{Category: builtinconstants.CategorySystemInfo}, tree.Overload{ Types: tree.ArgTypes{ {"typid", types.Oid}, @@ -2043,7 +2044,7 @@ SELECT description }, ), - "information_schema._pg_numeric_precision_radix": makeBuiltin(tree.FunctionProperties{Category: categorySystemInfo}, + "information_schema._pg_numeric_precision_radix": makeBuiltin(tree.FunctionProperties{Category: builtinconstants.CategorySystemInfo}, tree.Overload{ Types: tree.ArgTypes{ {"typid", types.Oid}, @@ -2065,7 +2066,7 @@ SELECT description }, ), - "information_schema._pg_numeric_scale": makeBuiltin(tree.FunctionProperties{Category: categorySystemInfo}, + "information_schema._pg_numeric_scale": makeBuiltin(tree.FunctionProperties{Category: builtinconstants.CategorySystemInfo}, tree.Overload{ Types: tree.ArgTypes{ {"typid", types.Oid}, diff --git a/pkg/sql/sem/builtins/pgcrypto_builtins.go b/pkg/sql/sem/builtins/pgcrypto_builtins.go index 2e048789ac5c..5dcd3de67da9 100644 --- a/pkg/sql/sem/builtins/pgcrypto_builtins.go +++ b/pkg/sql/sem/builtins/pgcrypto_builtins.go @@ -25,6 +25,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror" + "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins/builtinconstants" "github.com/cockroachdb/cockroach/pkg/sql/sem/eval" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/sem/volatility" @@ -46,7 +47,7 @@ func initPgcryptoBuiltins() { var pgcryptoBuiltins = map[string]builtinDefinition{ "crypt": makeBuiltin( - tree.FunctionProperties{Category: categoryCrypto}, + tree.FunctionProperties{Category: builtinconstants.CategoryCrypto}, tree.Overload{ Types: tree.ArgTypes{{"password", types.String}, {"salt", types.String}}, ReturnType: tree.FixedReturnType(types.String), @@ -65,7 +66,7 @@ var pgcryptoBuiltins = map[string]builtinDefinition{ ), "digest": makeBuiltin( - tree.FunctionProperties{Category: categoryCrypto}, + tree.FunctionProperties{Category: builtinconstants.CategoryCrypto}, tree.Overload{ Types: tree.ArgTypes{{"data", types.String}, {"type", types.String}}, ReturnType: tree.FixedReturnType(types.Bytes), @@ -109,7 +110,7 @@ var pgcryptoBuiltins = map[string]builtinDefinition{ "gen_random_uuid": generateRandomUUID4Impl, "gen_salt": makeBuiltin( - tree.FunctionProperties{Category: categoryCrypto}, + tree.FunctionProperties{Category: builtinconstants.CategoryCrypto}, tree.Overload{ Types: tree.ArgTypes{{"type", types.String}}, ReturnType: tree.FixedReturnType(types.String), @@ -142,7 +143,7 @@ var pgcryptoBuiltins = map[string]builtinDefinition{ ), "hmac": makeBuiltin( - tree.FunctionProperties{Category: categoryCrypto}, + tree.FunctionProperties{Category: builtinconstants.CategoryCrypto}, tree.Overload{ Types: tree.ArgTypes{{"data", types.String}, {"key", types.String}, {"type", types.String}}, ReturnType: tree.FixedReturnType(types.Bytes), diff --git a/pkg/sql/sem/builtins/replication_builtins.go b/pkg/sql/sem/builtins/replication_builtins.go index 41d6ff87f7a6..f7f798e9e703 100644 --- a/pkg/sql/sem/builtins/replication_builtins.go +++ b/pkg/sql/sem/builtins/replication_builtins.go @@ -14,6 +14,7 @@ import ( gojson "encoding/json" "github.com/cockroachdb/cockroach/pkg/jobs/jobspb" + "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins/builtinconstants" "github.com/cockroachdb/cockroach/pkg/sql/sem/eval" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/sem/volatility" @@ -41,7 +42,7 @@ var replicationBuiltins = map[string]builtinDefinition{ // Stream ingestion functions starts here. "crdb_internal.complete_stream_ingestion_job": makeBuiltin( tree.FunctionProperties{ - Category: categoryStreamIngestion, + Category: builtinconstants.CategoryStreamIngestion, DistsqlBlocklist: true, }, tree.Overload{ @@ -79,7 +80,7 @@ var replicationBuiltins = map[string]builtinDefinition{ "crdb_internal.stream_ingestion_stats_json": makeBuiltin( tree.FunctionProperties{ - Category: categoryStreamIngestion, + Category: builtinconstants.CategoryStreamIngestion, DistsqlBlocklist: true, }, @@ -156,7 +157,7 @@ var replicationBuiltins = map[string]builtinDefinition{ // Stream production functions starts here. "crdb_internal.start_replication_stream": makeBuiltin( tree.FunctionProperties{ - Category: categoryStreamIngestion, + Category: builtinconstants.CategoryStreamIngestion, DistsqlBlocklist: true, }, tree.Overload{ @@ -189,7 +190,7 @@ var replicationBuiltins = map[string]builtinDefinition{ "crdb_internal.replication_stream_progress": makeBuiltin( tree.FunctionProperties{ - Category: categoryStreamIngestion, + Category: builtinconstants.CategoryStreamIngestion, DistsqlBlocklist: true, }, tree.Overload{ @@ -229,7 +230,7 @@ var replicationBuiltins = map[string]builtinDefinition{ ), "crdb_internal.stream_partition": makeBuiltin( tree.FunctionProperties{ - Category: categoryStreamIngestion, + Category: builtinconstants.CategoryStreamIngestion, DistsqlBlocklist: false, Class: tree.GeneratorClass, }, @@ -260,7 +261,7 @@ var replicationBuiltins = map[string]builtinDefinition{ "crdb_internal.replication_stream_spec": makeBuiltin( tree.FunctionProperties{ - Category: categoryStreamIngestion, + Category: builtinconstants.CategoryStreamIngestion, DistsqlBlocklist: true, }, tree.Overload{ @@ -294,7 +295,7 @@ var replicationBuiltins = map[string]builtinDefinition{ "crdb_internal.complete_replication_stream": makeBuiltin( tree.FunctionProperties{ - Category: categoryStreamIngestion, + Category: builtinconstants.CategoryStreamIngestion, DistsqlBlocklist: true, }, tree.Overload{ diff --git a/pkg/sql/sem/builtins/trigram_builtins.go b/pkg/sql/sem/builtins/trigram_builtins.go index ce08895c9a2a..61fd541bdbdc 100644 --- a/pkg/sql/sem/builtins/trigram_builtins.go +++ b/pkg/sql/sem/builtins/trigram_builtins.go @@ -11,6 +11,7 @@ package builtins import ( + "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins/builtinconstants" "github.com/cockroachdb/cockroach/pkg/sql/sem/eval" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/sem/volatility" @@ -23,7 +24,7 @@ func initTrigramBuiltins() { if _, exists := builtins[k]; exists { panic("duplicate builtin: " + k) } - v.props.Category = categoryTrigram + v.props.Category = builtinconstants.CategoryTrigram v.props.AvailableOnPublicSchema = true builtins[k] = v } @@ -32,7 +33,7 @@ func initTrigramBuiltins() { var trigramBuiltins = map[string]builtinDefinition{ // Trigram functions. "similarity": makeBuiltin( - tree.FunctionProperties{Category: categoryTrigram}, + tree.FunctionProperties{Category: builtinconstants.CategoryTrigram}, tree.Overload{ Types: tree.ArgTypes{{"left", types.String}, {"right", types.String}}, ReturnType: tree.FixedReturnType(types.Float), @@ -49,7 +50,7 @@ var trigramBuiltins = map[string]builtinDefinition{ }, ), "show_trgm": makeBuiltin( - tree.FunctionProperties{Category: categoryTrigram}, + tree.FunctionProperties{Category: builtinconstants.CategoryTrigram}, tree.Overload{ Types: tree.ArgTypes{{"input", types.String}}, ReturnType: tree.FixedReturnType(types.StringArray), @@ -69,8 +70,8 @@ var trigramBuiltins = map[string]builtinDefinition{ Volatility: volatility.Immutable, }, ), - "word_similarity": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 41285, Category: categoryTrigram}), - "strict_word_similarity": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 41285, Category: categoryTrigram}), - "show_limit": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 41285, Category: categoryTrigram}), - "set_limit": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 41285, Category: categoryTrigram}), + "word_similarity": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 41285, Category: builtinconstants.CategoryTrigram}), + "strict_word_similarity": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 41285, Category: builtinconstants.CategoryTrigram}), + "show_limit": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 41285, Category: builtinconstants.CategoryTrigram}), + "set_limit": makeBuiltin(tree.FunctionProperties{UnsupportedWithIssue: 41285, Category: builtinconstants.CategoryTrigram}), } From ba1901cda49783957a2a0f349d804d95223b804d Mon Sep 17 00:00:00 2001 From: Xiang Gu Date: Thu, 23 Jun 2022 17:38:32 -0400 Subject: [PATCH 3/7] sql/builtins: Removed dependency from seqexpr to builtins 1. We plumbed in the only function call from `builtins` package in `seqexpr` to remove the dependency from seqexpr to builtins 2. We added a bazel rule in seqexpr/BUILD.bazel to disallow depedency to builtins Release note: None --- pkg/BUILD.bazel | 1 + pkg/sql/BUILD.bazel | 1 + pkg/sql/catalog/seqexpr/BUILD.bazel | 12 ++++++-- pkg/sql/catalog/seqexpr/sequence.go | 27 ++++++++++++----- pkg/sql/catalog/seqexpr/sequence_test.go | 30 ++++++++++--------- pkg/sql/create_table.go | 8 ++--- pkg/sql/create_view.go | 5 ++-- pkg/sql/opt/optbuilder/scalar.go | 3 +- pkg/sql/rename_database.go | 3 +- pkg/sql/row/expr_walker.go | 3 +- pkg/sql/row/row_converter.go | 4 +-- pkg/sql/schemachanger/scbuild/BUILD.bazel | 1 + .../schemachanger/scbuild/builder_state.go | 5 ++-- pkg/sql/schemachanger/scdecomp/BUILD.bazel | 1 + pkg/sql/schemachanger/scdecomp/helpers.go | 3 +- .../scexec/scmutationexec/BUILD.bazel | 1 + .../scexec/scmutationexec/helpers.go | 3 +- .../builtins/builtinconstants/constants.go | 20 +++++++++++++ pkg/sql/sem/builtins/builtins.go | 25 +++------------- pkg/sql/sem/builtins/replication_builtins.go | 2 +- pkg/sql/sequence.go | 4 +-- pkg/upgrade/upgrades/BUILD.bazel | 1 + ...upgrade_sequence_to_be_referenced_by_ID.go | 9 +++--- 23 files changed, 106 insertions(+), 66 deletions(-) diff --git a/pkg/BUILD.bazel b/pkg/BUILD.bazel index 1fa3db4a1906..80f5de228de6 100644 --- a/pkg/BUILD.bazel +++ b/pkg/BUILD.bazel @@ -251,6 +251,7 @@ ALL_TESTS = [ "//pkg/sql/catalog/resolver:resolver_test", "//pkg/sql/catalog/schemadesc:schemadesc_test", "//pkg/sql/catalog/schemaexpr:schemaexpr_test", + "//pkg/sql/catalog/seqexpr:seqexpr_disallowed_imports_test", "//pkg/sql/catalog/seqexpr:seqexpr_test", "//pkg/sql/catalog/systemschema_test:systemschema_test_test", "//pkg/sql/catalog/tabledesc:tabledesc_test", diff --git a/pkg/sql/BUILD.bazel b/pkg/sql/BUILD.bazel index ab5e2f0e075b..d6fac8e5d637 100644 --- a/pkg/sql/BUILD.bazel +++ b/pkg/sql/BUILD.bazel @@ -390,6 +390,7 @@ go_library( "//pkg/sql/scrub", "//pkg/sql/sem/asof", "//pkg/sql/sem/builtins", + "//pkg/sql/sem/builtins/builtinconstants", "//pkg/sql/sem/cast", "//pkg/sql/sem/catconstants", "//pkg/sql/sem/catid", diff --git a/pkg/sql/catalog/seqexpr/BUILD.bazel b/pkg/sql/catalog/seqexpr/BUILD.bazel index f9092fc22231..45d375bceb61 100644 --- a/pkg/sql/catalog/seqexpr/BUILD.bazel +++ b/pkg/sql/catalog/seqexpr/BUILD.bazel @@ -1,4 +1,5 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") +load("//pkg/testutils/buildutil:buildutil.bzl", "disallowed_imports_test") go_library( name = "seqexpr", @@ -8,7 +9,6 @@ go_library( deps = [ "//pkg/sql/pgwire/pgcode", "//pkg/sql/pgwire/pgerror", - "//pkg/sql/sem/builtins", "//pkg/sql/sem/builtins/builtinconstants", "//pkg/sql/sem/tree", "//pkg/sql/types", @@ -18,10 +18,18 @@ go_library( go_test( name = "seqexpr_test", srcs = ["sequence_test.go"], - embed = [":seqexpr"], deps = [ + ":seqexpr", "//pkg/sql/parser", + "//pkg/sql/sem/builtins", "//pkg/sql/sem/tree", "//pkg/sql/types", ], ) + +disallowed_imports_test( + "seqexpr", + [ + "//pkg/sql/sem/builtins", + ], +) diff --git a/pkg/sql/catalog/seqexpr/sequence.go b/pkg/sql/catalog/seqexpr/sequence.go index 7d4386bbeaad..1c25dfb239bd 100644 --- a/pkg/sql/catalog/seqexpr/sequence.go +++ b/pkg/sql/catalog/seqexpr/sequence.go @@ -20,7 +20,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror" - "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins" "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins/builtinconstants" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/types" @@ -43,7 +42,12 @@ func (si *SeqIdentifier) IsByID() bool { // takes a sequence identifier as an arg (a sequence identifier can either be // a sequence name or an ID), wrapped in the SeqIdentifier type. // Returns the identifier of the sequence or nil if no sequence was found. -func GetSequenceFromFunc(funcExpr *tree.FuncExpr) (*SeqIdentifier, error) { +// +// `getBuiltinProperties` argument is commonly builtins.GetBuiltinProperties. +func GetSequenceFromFunc( + funcExpr *tree.FuncExpr, + getBuiltinProperties func(name string) (*tree.FunctionProperties, []tree.Overload), +) (*SeqIdentifier, error) { // Resolve doesn't use the searchPath for resolving FunctionDefinitions // so we can pass in an empty SearchPath. @@ -52,7 +56,7 @@ func GetSequenceFromFunc(funcExpr *tree.FuncExpr) (*SeqIdentifier, error) { return nil, err } - fnProps, overloads := builtins.GetBuiltinProperties(def.Name) + fnProps, overloads := getBuiltinProperties(def.Name) if fnProps != nil && fnProps.HasSequenceArguments { found := false for _, overload := range overloads { @@ -126,14 +130,19 @@ func getSequenceIdentifier(expr tree.Expr) *SeqIdentifier { // a call to sequence function in the given expression or nil if no sequence // identifiers are found. The identifier is wrapped in a SeqIdentifier. // e.g. nextval('foo') => "foo"; nextval(123::regclass) => 123; => nil -func GetUsedSequences(defaultExpr tree.Expr) ([]SeqIdentifier, error) { +// +// `getBuiltinProperties` argument is commonly builtins.GetBuiltinProperties. +func GetUsedSequences( + defaultExpr tree.Expr, + getBuiltinProperties func(name string) (*tree.FunctionProperties, []tree.Overload), +) ([]SeqIdentifier, error) { var seqIdentifiers []SeqIdentifier _, err := tree.SimpleVisit( defaultExpr, func(expr tree.Expr) (recurse bool, newExpr tree.Expr, err error) { switch t := expr.(type) { case *tree.FuncExpr: - identifier, err := GetSequenceFromFunc(t) + identifier, err := GetSequenceFromFunc(t, getBuiltinProperties) if err != nil { return false, nil, err } @@ -153,13 +162,17 @@ func GetUsedSequences(defaultExpr tree.Expr) ([]SeqIdentifier, error) { // ReplaceSequenceNamesWithIDs walks the given expression, and replaces // any sequence names in the expression by their IDs instead. // e.g. nextval('foo') => nextval(123::regclass) +// +// `getBuiltinProperties` argument is commonly builtins.GetBuiltinProperties. func ReplaceSequenceNamesWithIDs( - defaultExpr tree.Expr, nameToID map[string]int64, + defaultExpr tree.Expr, + nameToID map[string]int64, + getBuiltinProperties func(name string) (*tree.FunctionProperties, []tree.Overload), ) (tree.Expr, error) { replaceFn := func(expr tree.Expr) (recurse bool, newExpr tree.Expr, err error) { switch t := expr.(type) { case *tree.FuncExpr: - identifier, err := GetSequenceFromFunc(t) + identifier, err := GetSequenceFromFunc(t, getBuiltinProperties) if err != nil { return false, nil, err } diff --git a/pkg/sql/catalog/seqexpr/sequence_test.go b/pkg/sql/catalog/seqexpr/sequence_test.go index 9448b381165a..4414c51f5fd6 100644 --- a/pkg/sql/catalog/seqexpr/sequence_test.go +++ b/pkg/sql/catalog/seqexpr/sequence_test.go @@ -8,14 +8,16 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package seqexpr +package seqexpr_test import ( "context" "fmt" "testing" + "github.com/cockroachdb/cockroach/pkg/sql/catalog/seqexpr" "github.com/cockroachdb/cockroach/pkg/sql/parser" + "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/types" ) @@ -23,13 +25,13 @@ import ( func TestGetSequenceFromFunc(t *testing.T) { testData := []struct { expr string - expected *SeqIdentifier + expected *seqexpr.SeqIdentifier }{ - {`nextval('seq')`, &SeqIdentifier{SeqName: "seq"}}, - {`nextval(123::REGCLASS)`, &SeqIdentifier{SeqID: 123}}, - {`nextval(123)`, &SeqIdentifier{SeqID: 123}}, - {`nextval(123::OID::REGCLASS)`, &SeqIdentifier{SeqID: 123}}, - {`nextval(123::OID)`, &SeqIdentifier{SeqID: 123}}, + {`nextval('seq')`, &seqexpr.SeqIdentifier{SeqName: "seq"}}, + {`nextval(123::REGCLASS)`, &seqexpr.SeqIdentifier{SeqID: 123}}, + {`nextval(123)`, &seqexpr.SeqIdentifier{SeqID: 123}}, + {`nextval(123::OID::REGCLASS)`, &seqexpr.SeqIdentifier{SeqID: 123}}, + {`nextval(123::OID)`, &seqexpr.SeqIdentifier{SeqID: 123}}, } ctx := context.Background() @@ -48,7 +50,7 @@ func TestGetSequenceFromFunc(t *testing.T) { if !ok { t.Fatal("Expr is not a FuncExpr") } - identifier, err := GetSequenceFromFunc(funcExpr) + identifier, err := seqexpr.GetSequenceFromFunc(funcExpr, builtins.GetBuiltinProperties) if err != nil { t.Fatal(err) } @@ -68,15 +70,15 @@ func TestGetSequenceFromFunc(t *testing.T) { func TestGetUsedSequences(t *testing.T) { testData := []struct { expr string - expected []SeqIdentifier + expected []seqexpr.SeqIdentifier }{ - {`nextval('seq')`, []SeqIdentifier{ + {`nextval('seq')`, []seqexpr.SeqIdentifier{ {SeqName: "seq"}, }}, - {`nextval(123::REGCLASS)`, []SeqIdentifier{ + {`nextval(123::REGCLASS)`, []seqexpr.SeqIdentifier{ {SeqID: 123}, }}, - {`nextval(123::REGCLASS) + nextval('seq')`, []SeqIdentifier{ + {`nextval(123::REGCLASS) + nextval('seq')`, []seqexpr.SeqIdentifier{ {SeqID: 123}, {SeqName: "seq"}, }}, @@ -94,7 +96,7 @@ func TestGetUsedSequences(t *testing.T) { if err != nil { t.Fatal(err) } - identifiers, err := GetUsedSequences(typedExpr) + identifiers, err := seqexpr.GetUsedSequences(typedExpr, builtins.GetBuiltinProperties) if err != nil { t.Fatal(err) } @@ -145,7 +147,7 @@ func TestReplaceSequenceNamesWithIDs(t *testing.T) { if err != nil { t.Fatal(err) } - newExpr, err := ReplaceSequenceNamesWithIDs(typedExpr, namesToID) + newExpr, err := seqexpr.ReplaceSequenceNamesWithIDs(typedExpr, namesToID, builtins.GetBuiltinProperties) if err != nil { t.Fatal(err) } diff --git a/pkg/sql/create_table.go b/pkg/sql/create_table.go index c870461c6622..a87506867441 100644 --- a/pkg/sql/create_table.go +++ b/pkg/sql/create_table.go @@ -46,7 +46,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgnotice" "github.com/cockroachdb/cockroach/pkg/sql/privilege" "github.com/cockroachdb/cockroach/pkg/sql/row" - "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins" + "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins/builtinconstants" "github.com/cockroachdb/cockroach/pkg/sql/sem/catid" "github.com/cockroachdb/cockroach/pkg/sql/sem/eval" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" @@ -2766,10 +2766,10 @@ func regionalByRowRegionDefaultExpr(oid oid.Oid, region tree.Name) tree.Expr { func regionalByRowGatewayRegionDefaultExpr(oid oid.Oid) tree.Expr { return &tree.CastExpr{ Expr: &tree.FuncExpr{ - Func: tree.WrapFunction(builtins.DefaultToDatabasePrimaryRegionBuiltinName), + Func: tree.WrapFunction(builtinconstants.DefaultToDatabasePrimaryRegionBuiltinName), Exprs: []tree.Expr{ &tree.FuncExpr{ - Func: tree.WrapFunction(builtins.GatewayRegionBuiltinName), + Func: tree.WrapFunction(builtinconstants.GatewayRegionBuiltinName), }, }, }, @@ -2784,7 +2784,7 @@ func maybeRegionalByRowOnUpdateExpr(evalCtx *eval.Context, enumOid oid.Oid) tree if evalCtx.SessionData().AutoRehomingEnabled { return &tree.CastExpr{ Expr: &tree.FuncExpr{ - Func: tree.WrapFunction(builtins.RehomeRowBuiltinName), + Func: tree.WrapFunction(builtinconstants.RehomeRowBuiltinName), }, Type: &tree.OIDTypeReference{OID: enumOid}, SyntaxMode: tree.CastShort, diff --git a/pkg/sql/create_view.go b/pkg/sql/create_view.go index 70a2eff957e8..f1a109409edd 100644 --- a/pkg/sql/create_view.go +++ b/pkg/sql/create_view.go @@ -33,6 +33,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgnotice" "github.com/cockroachdb/cockroach/pkg/sql/privilege" + "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins" "github.com/cockroachdb/cockroach/pkg/sql/sem/eval" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/sqlerrors" @@ -425,7 +426,7 @@ func replaceSeqNamesWithIDs( ctx context.Context, sc resolver.SchemaResolver, viewQuery string, ) (string, error) { replaceSeqFunc := func(expr tree.Expr) (recurse bool, newExpr tree.Expr, err error) { - seqIdentifiers, err := seqexpr.GetUsedSequences(expr) + seqIdentifiers, err := seqexpr.GetUsedSequences(expr, builtins.GetBuiltinProperties) if err != nil { return false, expr, err } @@ -437,7 +438,7 @@ func replaceSeqNamesWithIDs( } seqNameToID[seqIdentifier.SeqName] = int64(seqDesc.ID) } - newExpr, err = seqexpr.ReplaceSequenceNamesWithIDs(expr, seqNameToID) + newExpr, err = seqexpr.ReplaceSequenceNamesWithIDs(expr, seqNameToID, builtins.GetBuiltinProperties) if err != nil { return false, expr, err } diff --git a/pkg/sql/opt/optbuilder/scalar.go b/pkg/sql/opt/optbuilder/scalar.go index 1d82a33112ef..bd3fffa2a668 100644 --- a/pkg/sql/opt/optbuilder/scalar.go +++ b/pkg/sql/opt/optbuilder/scalar.go @@ -24,6 +24,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror" "github.com/cockroachdb/cockroach/pkg/sql/privilege" + "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins" "github.com/cockroachdb/cockroach/pkg/sql/sem/eval" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree/treebin" @@ -555,7 +556,7 @@ func (b *Builder) buildFunction( // Add a dependency on sequences that are used as a string argument. if b.trackViewDeps { - seqIdentifier, err := seqexpr.GetSequenceFromFunc(f) + seqIdentifier, err := seqexpr.GetSequenceFromFunc(f, builtins.GetBuiltinProperties) if err != nil { panic(err) } diff --git a/pkg/sql/rename_database.go b/pkg/sql/rename_database.go index f92308f4b340..010f2e338440 100644 --- a/pkg/sql/rename_database.go +++ b/pkg/sql/rename_database.go @@ -23,6 +23,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror" "github.com/cockroachdb/cockroach/pkg/sql/privilege" "github.com/cockroachdb/cockroach/pkg/sql/roleoption" + "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/sqlerrors" "github.com/cockroachdb/cockroach/pkg/util" @@ -297,7 +298,7 @@ func isAllowedDependentDescInRenameDatabase( if err != nil { return false, "", err } - seqIdentifiers, err := seqexpr.GetUsedSequences(typedExpr) + seqIdentifiers, err := seqexpr.GetUsedSequences(typedExpr, builtins.GetBuiltinProperties) if err != nil { return false, "", err } diff --git a/pkg/sql/row/expr_walker.go b/pkg/sql/row/expr_walker.go index d37065c1b7e9..e62cddf20212 100644 --- a/pkg/sql/row/expr_walker.go +++ b/pkg/sql/row/expr_walker.go @@ -25,6 +25,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/catalog/seqexpr" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror" + "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins" "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins/builtinconstants" "github.com/cockroachdb/cockroach/pkg/sql/sem/eval" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" @@ -628,7 +629,7 @@ var supportedImportFuncOverrides = map[string]*customFunc{ visitorSideEffect: func(annot *tree.Annotations, fn *tree.FuncExpr) error { // Get sequence name so that we can update the annotation with the number // of nextval calls to this sequence in a row. - seqIdentifier, err := seqexpr.GetSequenceFromFunc(fn) + seqIdentifier, err := seqexpr.GetSequenceFromFunc(fn, builtins.GetBuiltinProperties) if err != nil { return err } diff --git a/pkg/sql/row/row_converter.go b/pkg/sql/row/row_converter.go index c80ae29decb5..43ccae0a61b1 100644 --- a/pkg/sql/row/row_converter.go +++ b/pkg/sql/row/row_converter.go @@ -21,7 +21,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/catalog/descs" "github.com/cockroachdb/cockroach/pkg/sql/catalog/schemaexpr" "github.com/cockroachdb/cockroach/pkg/sql/rowinfra" - "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins" + "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins/builtinconstants" "github.com/cockroachdb/cockroach/pkg/sql/sem/eval" "github.com/cockroachdb/cockroach/pkg/sql/sem/transform" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" @@ -459,7 +459,7 @@ func NewDatumRowConverter( return c, nil } -const rowIDBits = 64 - builtins.NodeIDBits +const rowIDBits = 64 - builtinconstants.NodeIDBits // Row inserts kv operations into the current kv batch, and triggers a SendBatch // if necessary. diff --git a/pkg/sql/schemachanger/scbuild/BUILD.bazel b/pkg/sql/schemachanger/scbuild/BUILD.bazel index 6c8ada563432..9def006efc1f 100644 --- a/pkg/sql/schemachanger/scbuild/BUILD.bazel +++ b/pkg/sql/schemachanger/scbuild/BUILD.bazel @@ -37,6 +37,7 @@ go_library( "//pkg/sql/schemachanger/scerrors", "//pkg/sql/schemachanger/scpb", "//pkg/sql/schemachanger/screl", + "//pkg/sql/sem/builtins", "//pkg/sql/sem/catconstants", "//pkg/sql/sem/catid", "//pkg/sql/sem/eval", diff --git a/pkg/sql/schemachanger/scbuild/builder_state.go b/pkg/sql/schemachanger/scbuild/builder_state.go index 8b01519e9b19..6f9cdebd460a 100644 --- a/pkg/sql/schemachanger/scbuild/builder_state.go +++ b/pkg/sql/schemachanger/scbuild/builder_state.go @@ -33,6 +33,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scerrors" "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scpb" "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/screl" + "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins" "github.com/cockroachdb/cockroach/pkg/sql/sem/catconstants" "github.com/cockroachdb/cockroach/pkg/sql/sem/catid" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" @@ -410,7 +411,7 @@ func (b *builderState) WrapExpression(parentID catid.DescID, expr tree.Expr) *sc // Collect sequence IDs. var seqIDs catalog.DescriptorIDSet { - seqIdentifiers, err := seqexpr.GetUsedSequences(expr) + seqIdentifiers, err := seqexpr.GetUsedSequences(expr, builtins.GetBuiltinProperties) if err != nil { panic(err) } @@ -433,7 +434,7 @@ func (b *builderState) WrapExpression(parentID catid.DescID, expr tree.Expr) *sc seqIDs.Add(seq.SequenceID) } if len(seqNameToID) > 0 { - expr, err = seqexpr.ReplaceSequenceNamesWithIDs(expr, seqNameToID) + expr, err = seqexpr.ReplaceSequenceNamesWithIDs(expr, seqNameToID, builtins.GetBuiltinProperties) if err != nil { panic(err) } diff --git a/pkg/sql/schemachanger/scdecomp/BUILD.bazel b/pkg/sql/schemachanger/scdecomp/BUILD.bazel index dc15d1887fd3..bb1cb2051b1c 100644 --- a/pkg/sql/schemachanger/scdecomp/BUILD.bazel +++ b/pkg/sql/schemachanger/scdecomp/BUILD.bazel @@ -18,6 +18,7 @@ go_library( "//pkg/sql/parser", "//pkg/sql/schemachanger/scerrors", "//pkg/sql/schemachanger/scpb", + "//pkg/sql/sem/builtins", "//pkg/sql/sem/catconstants", "//pkg/sql/sem/catid", "//pkg/sql/sem/tree", diff --git a/pkg/sql/schemachanger/scdecomp/helpers.go b/pkg/sql/schemachanger/scdecomp/helpers.go index 0e0883214eb6..058ee6d75da1 100644 --- a/pkg/sql/schemachanger/scdecomp/helpers.go +++ b/pkg/sql/schemachanger/scdecomp/helpers.go @@ -19,6 +19,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/parser" "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scerrors" "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scpb" + "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/types" "github.com/lib/pq/oid" @@ -65,7 +66,7 @@ func (w *walkCtx) newExpression(expr string) (*scpb.Expression, error) { } var seqIDs catalog.DescriptorIDSet { - seqIdents, err := seqexpr.GetUsedSequences(e) + seqIdents, err := seqexpr.GetUsedSequences(e, builtins.GetBuiltinProperties) if err != nil { return nil, err } diff --git a/pkg/sql/schemachanger/scexec/scmutationexec/BUILD.bazel b/pkg/sql/schemachanger/scexec/scmutationexec/BUILD.bazel index 8128c3994e4c..3823e9bb6f9c 100644 --- a/pkg/sql/schemachanger/scexec/scmutationexec/BUILD.bazel +++ b/pkg/sql/schemachanger/scexec/scmutationexec/BUILD.bazel @@ -34,6 +34,7 @@ go_library( "//pkg/sql/schemachanger/scop", "//pkg/sql/schemachanger/scpb", "//pkg/sql/schemachanger/screl", + "//pkg/sql/sem/builtins", "//pkg/sql/sem/catid", "//pkg/sql/sem/tree", "//pkg/sql/types", diff --git a/pkg/sql/schemachanger/scexec/scmutationexec/helpers.go b/pkg/sql/schemachanger/scexec/scmutationexec/helpers.go index 9640b3206da6..c52c4212146c 100644 --- a/pkg/sql/schemachanger/scexec/scmutationexec/helpers.go +++ b/pkg/sql/schemachanger/scexec/scmutationexec/helpers.go @@ -22,6 +22,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/catalog/typedesc" "github.com/cockroachdb/cockroach/pkg/sql/parser" "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scpb" + "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins" "github.com/cockroachdb/cockroach/pkg/util/log/eventpb" "github.com/cockroachdb/errors" ) @@ -254,7 +255,7 @@ func sequenceIDsInExpr(expr string) (ids catalog.DescriptorIDSet, _ error) { if err != nil { return ids, err } - seqIdents, err := seqexpr.GetUsedSequences(e) + seqIdents, err := seqexpr.GetUsedSequences(e, builtins.GetBuiltinProperties) if err != nil { return ids, err } diff --git a/pkg/sql/sem/builtins/builtinconstants/constants.go b/pkg/sql/sem/builtins/builtinconstants/constants.go index ca0cc9ac3bec..85df6367238d 100644 --- a/pkg/sql/sem/builtins/builtinconstants/constants.go +++ b/pkg/sql/sem/builtins/builtinconstants/constants.go @@ -14,6 +14,9 @@ import "time" // SequenceNameArg represents the name of sequence (string) arguments in // builtin functions. +// Namely, it exists to classify overloads of functions which in postgres +// only take `REGCLASS`, but in cockroach db take both `REGCLASS` and +// `STRING` because we need to be backwards compatible. const SequenceNameArg = "sequence_name" // DefaultFollowerReadDuration represents the default time span back from the @@ -54,3 +57,20 @@ const ( CategorySystemRepair = "System repair" CategoryStreamIngestion = "Stream Ingestion" ) + +const ( + // GatewayRegionBuiltinName is the name for the builtin that returns the gateway + // region of the current node. + GatewayRegionBuiltinName = "gateway_region" + // DefaultToDatabasePrimaryRegionBuiltinName is the name for the builtin that + // takes in a region and returns it if it is a valid region on the database. + // Otherwise, it returns the primary region. + DefaultToDatabasePrimaryRegionBuiltinName = "default_to_database_primary_region" + // RehomeRowBuiltinName is the name for the builtin that rehomes a row to the + // user's gateway region, defaulting to the database primary region. + RehomeRowBuiltinName = "rehome_row" +) + +// NodeIDBits is the number of bits stored in the lower portion of +// GenerateUniqueInt. +const NodeIDBits = 15 diff --git a/pkg/sql/sem/builtins/builtins.go b/pkg/sql/sem/builtins/builtins.go index 4f240f31b5b8..3e239594917a 100644 --- a/pkg/sql/sem/builtins/builtins.go +++ b/pkg/sql/sem/builtins/builtins.go @@ -118,19 +118,6 @@ func categorizeType(t *types.T) string { } } -const ( - // GatewayRegionBuiltinName is the name for the builtin that returns the gateway - // region of the current node. - GatewayRegionBuiltinName = "gateway_region" - // DefaultToDatabasePrimaryRegionBuiltinName is the name for the builtin that - // takes in a region and returns it if it is a valid region on the database. - // Otherwise, it returns the primary region. - DefaultToDatabasePrimaryRegionBuiltinName = "default_to_database_primary_region" - // RehomeRowBuiltinName is the name for the builtin that rehomes a row to the - // user's gateway region, defaulting to the database primary region. - RehomeRowBuiltinName = "rehome_row" -) - var digitNames = [...]string{"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"} const regexpFlagInfo = ` @@ -6193,7 +6180,7 @@ value if you rely on the HLC for accuracy.`, }, ), - GatewayRegionBuiltinName: makeBuiltin( + builtinconstants.GatewayRegionBuiltinName: makeBuiltin( tree.FunctionProperties{ Category: builtinconstants.CategoryMultiRegion, // We should always evaluate this built-in at the gateway. @@ -6217,7 +6204,7 @@ the locality flag on node startup. Returns an error if no region is set.`, Volatility: volatility.Stable, }, ), - DefaultToDatabasePrimaryRegionBuiltinName: makeBuiltin( + builtinconstants.DefaultToDatabasePrimaryRegionBuiltinName: makeBuiltin( tree.FunctionProperties{Category: builtinconstants.CategoryMultiRegion}, stringOverload1( func(evalCtx *eval.Context, s string) (tree.Datum, error) { @@ -6245,7 +6232,7 @@ the locality flag on node startup. Returns an error if no region is set.`, volatility.Stable, ), ), - RehomeRowBuiltinName: makeBuiltin( + builtinconstants.RehomeRowBuiltinName: makeBuiltin( tree.FunctionProperties{Category: builtinconstants.CategoryMultiRegion}, tree.Overload{ Types: tree.ArgTypes{}, @@ -8498,10 +8485,6 @@ func overlay(s, to string, pos, size int) (tree.Datum, error) { return tree.NewDString(string(runes[:pos]) + to + string(runes[after:])), nil } -// NodeIDBits is the number of bits stored in the lower portion of -// GenerateUniqueInt. -const NodeIDBits = 15 - // GenerateUniqueUnorderedID creates a unique int64 composed of the current time // at a 10-microsecond granularity and the instance-id. The top-bit is left // empty so that negative values are not returned. The 48 bits following after @@ -8560,7 +8543,7 @@ func GenerateUniqueInt(instanceID base.SQLInstanceID) tree.DInt { func GenerateUniqueID(instanceID int32, timestamp uint64) tree.DInt { // We xor in the instanceID so that instanceIDs larger than 32K will flip bits // in the timestamp portion of the final value instead of always setting them. - id := (timestamp << NodeIDBits) ^ uint64(instanceID) + id := (timestamp << builtinconstants.NodeIDBits) ^ uint64(instanceID) return tree.DInt(id) } diff --git a/pkg/sql/sem/builtins/replication_builtins.go b/pkg/sql/sem/builtins/replication_builtins.go index f7f798e9e703..2001bd14936b 100644 --- a/pkg/sql/sem/builtins/replication_builtins.go +++ b/pkg/sql/sem/builtins/replication_builtins.go @@ -120,7 +120,7 @@ var replicationBuiltins = map[string]builtinDefinition{ "crdb_internal.stream_ingestion_stats_pb": makeBuiltin( tree.FunctionProperties{ - Category: categoryStreamIngestion, + Category: builtinconstants.CategoryStreamIngestion, DistsqlBlocklist: true, }, diff --git a/pkg/sql/sequence.go b/pkg/sql/sequence.go index fb0f81716946..30db52e91c5e 100644 --- a/pkg/sql/sequence.go +++ b/pkg/sql/sequence.go @@ -826,7 +826,7 @@ func maybeAddSequenceDependencies( backrefs map[descpb.ID]*tabledesc.Mutable, colExprKind tabledesc.ColExprKind, ) ([]*tabledesc.Mutable, error) { - seqIdentifiers, err := seqexpr.GetUsedSequences(expr) + seqIdentifiers, err := seqexpr.GetUsedSequences(expr, builtins.GetBuiltinProperties) if err != nil { return nil, err } @@ -901,7 +901,7 @@ func maybeAddSequenceDependencies( // If sequences are present in the expr (and the cluster is the right version), // walk the expr tree and replace any sequences names with their IDs. if len(seqIdentifiers) > 0 { - newExpr, err := seqexpr.ReplaceSequenceNamesWithIDs(expr, seqNameToID) + newExpr, err := seqexpr.ReplaceSequenceNamesWithIDs(expr, seqNameToID, builtins.GetBuiltinProperties) if err != nil { return nil, err } diff --git a/pkg/upgrade/upgrades/BUILD.bazel b/pkg/upgrade/upgrades/BUILD.bazel index c10a70216338..012cfbd576b2 100644 --- a/pkg/upgrade/upgrades/BUILD.bazel +++ b/pkg/upgrade/upgrades/BUILD.bazel @@ -49,6 +49,7 @@ go_library( "//pkg/sql/catalog/typedesc", "//pkg/sql/parser", "//pkg/sql/privilege", + "//pkg/sql/sem/builtins", "//pkg/sql/sem/tree", "//pkg/sql/sessiondata", "//pkg/sql/sqlutil", diff --git a/pkg/upgrade/upgrades/upgrade_sequence_to_be_referenced_by_ID.go b/pkg/upgrade/upgrades/upgrade_sequence_to_be_referenced_by_ID.go index 6fd6189a91ab..462c3d716334 100644 --- a/pkg/upgrade/upgrades/upgrade_sequence_to_be_referenced_by_ID.go +++ b/pkg/upgrade/upgrades/upgrade_sequence_to_be_referenced_by_ID.go @@ -23,6 +23,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/catalog/seqexpr" "github.com/cockroachdb/cockroach/pkg/sql/catalog/tabledesc" "github.com/cockroachdb/cockroach/pkg/sql/parser" + "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/sqlutil" "github.com/cockroachdb/cockroach/pkg/upgrade" @@ -175,7 +176,7 @@ func upgradeSequenceReferenceInTable( if err != nil { return err } - seqIdentifiers, err := seqexpr.GetUsedSequences(parsedExpr) + seqIdentifiers, err := seqexpr.GetUsedSequences(parsedExpr, builtins.GetBuiltinProperties) if err != nil { return err } @@ -189,7 +190,7 @@ func upgradeSequenceReferenceInTable( } // Perform the sequence replacement in the default expression. - newExpr, err := seqexpr.ReplaceSequenceNamesWithIDs(parsedExpr, seqNameToID) + newExpr, err := seqexpr.ReplaceSequenceNamesWithIDs(parsedExpr, seqNameToID, builtins.GetBuiltinProperties) if err != nil { return err } @@ -234,7 +235,7 @@ func upgradeSequenceReferenceInView( ) error { var changedSeqDescs []*tabledesc.Mutable replaceSeqFunc := func(expr tree.Expr) (recurse bool, newExpr tree.Expr, err error) { - seqIdentifiers, err := seqexpr.GetUsedSequences(expr) + seqIdentifiers, err := seqexpr.GetUsedSequences(expr, builtins.GetBuiltinProperties) if err != nil { return false, expr, err } @@ -243,7 +244,7 @@ func upgradeSequenceReferenceInView( return false, expr, err } - newExpr, err = seqexpr.ReplaceSequenceNamesWithIDs(expr, seqNameToID) + newExpr, err = seqexpr.ReplaceSequenceNamesWithIDs(expr, seqNameToID, builtins.GetBuiltinProperties) if err != nil { return false, expr, err } From 063df017fbb21882b1ad2cde44f8b081dd3d39b5 Mon Sep 17 00:00:00 2001 From: Andrew Werner Date: Tue, 28 Jun 2022 12:36:48 -0400 Subject: [PATCH 4/7] sql/schemachanger/scexec: remove debug log line This just merged by mistake. Release note: None --- pkg/sql/schemachanger/scexec/scmutationexec/BUILD.bazel | 1 - pkg/sql/schemachanger/scexec/scmutationexec/index.go | 2 -- 2 files changed, 3 deletions(-) diff --git a/pkg/sql/schemachanger/scexec/scmutationexec/BUILD.bazel b/pkg/sql/schemachanger/scexec/scmutationexec/BUILD.bazel index 8128c3994e4c..6682edb3e89f 100644 --- a/pkg/sql/schemachanger/scexec/scmutationexec/BUILD.bazel +++ b/pkg/sql/schemachanger/scexec/scmutationexec/BUILD.bazel @@ -38,7 +38,6 @@ go_library( "//pkg/sql/sem/tree", "//pkg/sql/types", "//pkg/util/iterutil", - "//pkg/util/log", "//pkg/util/log/eventpb", "//pkg/util/protoutil", "//pkg/util/timeutil", diff --git a/pkg/sql/schemachanger/scexec/scmutationexec/index.go b/pkg/sql/schemachanger/scexec/scmutationexec/index.go index 7cbacee6c9a5..db1936fe32cf 100644 --- a/pkg/sql/schemachanger/scexec/scmutationexec/index.go +++ b/pkg/sql/schemachanger/scexec/scmutationexec/index.go @@ -21,7 +21,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/catalog/tabledesc" "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scop" "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scpb" - "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/log/eventpb" "github.com/cockroachdb/errors" "github.com/cockroachdb/redact" @@ -382,7 +381,6 @@ func (m *visitor) RemoveColumnFromIndex(ctx context.Context, op scop.RemoveColum // As a special case, avoid removing any columns from dropped indexes. // The index is going to be removed, so it doesn't matter if it references // dropped columns. - log.Infof(ctx, "yo sup, %d %d %v %v %v", op.IndexID, op.ColumnID, index.Dropped(), index.DeleteOnly(), index.Public()) if index.Dropped() { return nil } From 2aa047a29dc59b7d47b03c51451a6c11b07bc3bc Mon Sep 17 00:00:00 2001 From: Andrew Werner Date: Wed, 29 Jun 2022 14:00:02 -0400 Subject: [PATCH 5/7] sql/syntheticprivilege: remove BUILD.bazel cruft This was added as part of the rename. Release note: None --- pkg/BUILD.bazel | 1 - pkg/sql/syntheticprivilege/BUILD.bazel | 21 --------------------- 2 files changed, 22 deletions(-) diff --git a/pkg/BUILD.bazel b/pkg/BUILD.bazel index 1fa3db4a1906..00aa844d22ef 100644 --- a/pkg/BUILD.bazel +++ b/pkg/BUILD.bazel @@ -422,7 +422,6 @@ ALL_TESTS = [ "//pkg/sql/stats:stats_test", "//pkg/sql/stmtdiagnostics:stmtdiagnostics_test", "//pkg/sql/syntheticprivilege:syntheticprivilege_test", - "//pkg/sql/syntheticprivilege:systemprivilege_test", "//pkg/sql/tests:tests_test", "//pkg/sql/ttl/ttljob:ttljob_test", "//pkg/sql/types:types_disallowed_imports_test", diff --git a/pkg/sql/syntheticprivilege/BUILD.bazel b/pkg/sql/syntheticprivilege/BUILD.bazel index d3259cb5f8fc..cb4cd80f43a1 100644 --- a/pkg/sql/syntheticprivilege/BUILD.bazel +++ b/pkg/sql/syntheticprivilege/BUILD.bazel @@ -1,26 +1,5 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") -go_library( - name = "systemprivilege", - srcs = ["system_privilege.go"], - importpath = "github.com/cockroachdb/cockroach/pkg/sql/systemprivilege", - visibility = ["//visibility:public"], - deps = [ - "//pkg/sql/catalog", - "@com_github_cockroachdb_errors//:errors", - ], -) - -go_test( - name = "systemprivilege_test", - srcs = ["system_privilege_test.go"], - embed = [":systemprivilege"], - deps = [ - "//pkg/sql/catalog", - "@com_github_stretchr_testify//require", - ], -) - go_library( name = "syntheticprivilege", srcs = [ From bfcebc98d6fe5abe623b0f4fec4d77d11feb01c9 Mon Sep 17 00:00:00 2001 From: Xin Hao Zhang Date: Mon, 27 Jun 2022 15:12:34 -0400 Subject: [PATCH 6/7] sql: rename `oldest_query_start` column in sessions table Closes #80676 Previously, the `oldest_query_start` column in the cluster and node sessions tables was misleadingly named. The column implies that it contains the time at which the oldest query in a session was started. This column is actually the time at which the session's currently active query started. This commit renames `oldest_query_start` to `active_query_start` to more accurately represent the column data. Release note (sql change): `oldest_query_start` in the `crdb_internal.cluster_sessions` and `crdb_internal.node_sessions` has been renamed to `active_query_start`, as this column contains the time at which the currently active query was started, not the time at which the session's first query was started. --- .../testdata/logic_test/crdb_internal_tenant | 4 +-- pkg/sql/crdb_internal.go | 31 +++++++++---------- pkg/sql/delegate/show_sessions.go | 2 +- .../testdata/logic_test/crdb_internal | 4 +-- .../testdata/logic_test/create_statements | 8 ++--- 5 files changed, 23 insertions(+), 26 deletions(-) diff --git a/pkg/ccl/logictestccl/testdata/logic_test/crdb_internal_tenant b/pkg/ccl/logictestccl/testdata/logic_test/crdb_internal_tenant index ec7309b07d59..8f6566a115b2 100644 --- a/pkg/ccl/logictestccl/testdata/logic_test/crdb_internal_tenant +++ b/pkg/ccl/logictestccl/testdata/logic_test/crdb_internal_tenant @@ -248,12 +248,12 @@ id node_id session_id start txn_string application_name num_stmts num_ret query ITTTTTTTTTTTTTT colnames SELECT * FROM crdb_internal.node_sessions WHERE node_id < 0 ---- -node_id session_id user_name client_address application_name active_queries last_active_query num_txns_executed session_start oldest_query_start kv_txn alloc_bytes max_alloc_bytes status session_end +node_id session_id user_name client_address application_name active_queries last_active_query num_txns_executed session_start active_query_start kv_txn alloc_bytes max_alloc_bytes status session_end query ITTTTTTTTTTTTTT colnames SELECT * FROM crdb_internal.cluster_sessions WHERE node_id < 0 ---- -node_id session_id user_name client_address application_name active_queries last_active_query num_txns_executed session_start oldest_query_start kv_txn alloc_bytes max_alloc_bytes status session_end +node_id session_id user_name client_address application_name active_queries last_active_query num_txns_executed session_start active_query_start kv_txn alloc_bytes max_alloc_bytes status session_end query IIITTTI colnames SELECT * FROM crdb_internal.node_contention_events WHERE table_id < 0 diff --git a/pkg/sql/crdb_internal.go b/pkg/sql/crdb_internal.go index 2c708a75bc8f..338c35198a74 100644 --- a/pkg/sql/crdb_internal.go +++ b/pkg/sql/crdb_internal.go @@ -1924,7 +1924,7 @@ CREATE TABLE crdb_internal.%s ( last_active_query STRING, -- the query that finished last on this session as SQL num_txns_executed INT, -- the number of transactions that were executed so far on this session session_start TIMESTAMP, -- the time when the session was opened - oldest_query_start TIMESTAMP, -- the time when the oldest query in the session was started + active_query_start TIMESTAMP, -- the time when the current active query in the session was started kv_txn STRING, -- the ID of the current KV transaction alloc_bytes INT, -- the number of bytes allocated by the session max_alloc_bytes INT, -- the high water mark of bytes allocated by the session @@ -1973,27 +1973,24 @@ func populateSessionsTable( ctx context.Context, addRow func(...tree.Datum) error, response *serverpb.ListSessionsResponse, ) error { for _, session := range response.Sessions { - // Generate active_queries and oldest_query_start + // Generate active_queries and active_query_start var activeQueries bytes.Buffer - var oldestStart time.Time - var oldestStartDatum tree.Datum + var activeQueryStart time.Time + var activeQueryStartDatum tree.Datum - for idx, query := range session.ActiveQueries { - if idx > 0 { - activeQueries.WriteString("; ") - } + for _, query := range session.ActiveQueries { + // Note that the max length of ActiveQueries is 1. + // The array is leftover from a time when we allowed multiple + // queries to be executed at once in a session. + activeQueryStart = query.Start activeQueries.WriteString(query.Sql) - - if oldestStart.IsZero() || query.Start.Before(oldestStart) { - oldestStart = query.Start - } } var err error - if oldestStart.IsZero() { - oldestStartDatum = tree.DNull + if activeQueryStart.IsZero() { + activeQueryStartDatum = tree.DNull } else { - oldestStartDatum, err = tree.MakeDTimestamp(oldestStart, time.Microsecond) + activeQueryStartDatum, err = tree.MakeDTimestamp(activeQueryStart, time.Microsecond) if err != nil { return err } @@ -2026,7 +2023,7 @@ func populateSessionsTable( tree.NewDString(session.LastActiveQuery), tree.NewDInt(tree.DInt(session.NumTxnsExecuted)), startTSDatum, - oldestStartDatum, + activeQueryStartDatum, kvTxnIDDatum, tree.NewDInt(tree.DInt(session.AllocBytes)), tree.NewDInt(tree.DInt(session.MaxAllocBytes)), @@ -2052,7 +2049,7 @@ func populateSessionsTable( tree.DNull, // last active query tree.DNull, // num txns executed tree.DNull, // session start - tree.DNull, // oldest_query_start + tree.DNull, // active_query_start tree.DNull, // kv_txn tree.DNull, // alloc_bytes tree.DNull, // max_alloc_bytes diff --git a/pkg/sql/delegate/show_sessions.go b/pkg/sql/delegate/show_sessions.go index 8c8ea6ed8895..1918c726ca31 100644 --- a/pkg/sql/delegate/show_sessions.go +++ b/pkg/sql/delegate/show_sessions.go @@ -16,7 +16,7 @@ import ( ) func (d *delegator) delegateShowSessions(n *tree.ShowSessions) (tree.Statement, error) { - const query = `SELECT node_id, session_id, status, user_name, client_address, application_name, active_queries, last_active_query, session_start, oldest_query_start, num_txns_executed FROM crdb_internal.` + const query = `SELECT node_id, session_id, status, user_name, client_address, application_name, active_queries, last_active_query, session_start, active_query_start, num_txns_executed FROM crdb_internal.` table := `node_sessions` if n.Cluster { table = `cluster_sessions` diff --git a/pkg/sql/logictest/testdata/logic_test/crdb_internal b/pkg/sql/logictest/testdata/logic_test/crdb_internal index 7d4b983b309e..b803bbeeb10e 100644 --- a/pkg/sql/logictest/testdata/logic_test/crdb_internal +++ b/pkg/sql/logictest/testdata/logic_test/crdb_internal @@ -368,12 +368,12 @@ id node_id session_id start txn_string application_name num_stmts num_ret query ITTTTTTTTTTTTTT colnames SELECT * FROM crdb_internal.node_sessions WHERE node_id < 0 ---- -node_id session_id user_name client_address application_name active_queries last_active_query num_txns_executed session_start oldest_query_start kv_txn alloc_bytes max_alloc_bytes status session_end +node_id session_id user_name client_address application_name active_queries last_active_query num_txns_executed session_start active_query_start kv_txn alloc_bytes max_alloc_bytes status session_end query ITTTTTTTTTTTTTT colnames SELECT * FROM crdb_internal.cluster_sessions WHERE node_id < 0 ---- -node_id session_id user_name client_address application_name active_queries last_active_query num_txns_executed session_start oldest_query_start kv_txn alloc_bytes max_alloc_bytes status session_end +node_id session_id user_name client_address application_name active_queries last_active_query num_txns_executed session_start active_query_start kv_txn alloc_bytes max_alloc_bytes status session_end query IIITTTI colnames SELECT * FROM crdb_internal.node_contention_events WHERE table_id < 0 diff --git a/pkg/sql/logictest/testdata/logic_test/create_statements b/pkg/sql/logictest/testdata/logic_test/create_statements index ea12199cea8d..54e5c8ec337e 100644 --- a/pkg/sql/logictest/testdata/logic_test/create_statements +++ b/pkg/sql/logictest/testdata/logic_test/create_statements @@ -336,7 +336,7 @@ CREATE TABLE crdb_internal.cluster_sessions ( last_active_query STRING NULL, num_txns_executed INT8 NULL, session_start TIMESTAMP NULL, - oldest_query_start TIMESTAMP NULL, + active_query_start TIMESTAMP NULL, kv_txn STRING NULL, alloc_bytes INT8 NULL, max_alloc_bytes INT8 NULL, @@ -352,7 +352,7 @@ CREATE TABLE crdb_internal.cluster_sessions ( last_active_query STRING NULL, num_txns_executed INT8 NULL, session_start TIMESTAMP NULL, - oldest_query_start TIMESTAMP NULL, + active_query_start TIMESTAMP NULL, kv_txn STRING NULL, alloc_bytes INT8 NULL, max_alloc_bytes INT8 NULL, @@ -976,7 +976,7 @@ CREATE TABLE crdb_internal.node_sessions ( last_active_query STRING NULL, num_txns_executed INT8 NULL, session_start TIMESTAMP NULL, - oldest_query_start TIMESTAMP NULL, + active_query_start TIMESTAMP NULL, kv_txn STRING NULL, alloc_bytes INT8 NULL, max_alloc_bytes INT8 NULL, @@ -992,7 +992,7 @@ CREATE TABLE crdb_internal.node_sessions ( last_active_query STRING NULL, num_txns_executed INT8 NULL, session_start TIMESTAMP NULL, - oldest_query_start TIMESTAMP NULL, + active_query_start TIMESTAMP NULL, kv_txn STRING NULL, alloc_bytes INT8 NULL, max_alloc_bytes INT8 NULL, From 7f6a0f5f38da295d13a8e2b7026c07b5b584374d Mon Sep 17 00:00:00 2001 From: Yahor Yuzefovich Date: Mon, 27 Jun 2022 16:10:04 -0700 Subject: [PATCH 7/7] kvstreamer: add more observability This commit adds the following statistics about the streamer: - number of Enqueue calls - number of enqueued requests - number of single-range enqueue requests - number of issued BatchRequests (which is also exposed on EXPLAIN ANALYZE) - number of resume BatchRequests - number of resume single-range requests - number of spilled results - number of empty batch responses - number of dropped batch responses - the final average response size. This information provides more visibility into how the streamer behaved. It is only added to the verbose logs / tracing since these are pretty low level details that would only pollute the output of EXPLAIN or something like that. Release note: None --- pkg/kv/kvclient/kvstreamer/BUILD.bazel | 2 + pkg/kv/kvclient/kvstreamer/results_buffer.go | 18 +++++ pkg/kv/kvclient/kvstreamer/streamer.go | 71 +++++++++++++++++++- 3 files changed, 88 insertions(+), 3 deletions(-) diff --git a/pkg/kv/kvclient/kvstreamer/BUILD.bazel b/pkg/kv/kvclient/kvstreamer/BUILD.bazel index 3a2221614d8b..274dcc3ac0ec 100644 --- a/pkg/kv/kvclient/kvstreamer/BUILD.bazel +++ b/pkg/kv/kvclient/kvstreamer/BUILD.bazel @@ -23,6 +23,8 @@ go_library( "//pkg/util/admission", "//pkg/util/admission/admissionpb", "//pkg/util/buildutil", + "//pkg/util/humanizeutil", + "//pkg/util/log", "//pkg/util/mon", "//pkg/util/quotapool", "//pkg/util/stop", diff --git a/pkg/kv/kvclient/kvstreamer/results_buffer.go b/pkg/kv/kvclient/kvstreamer/results_buffer.go index 7ceebecf4def..c04123140270 100644 --- a/pkg/kv/kvclient/kvstreamer/results_buffer.go +++ b/pkg/kv/kvclient/kvstreamer/results_buffer.go @@ -95,6 +95,10 @@ type resultsBuffer interface { // It is assumed that the budget's mutex is already being held. spill(_ context.Context, atLeastBytes int64, spillingPriority int) (bool, error) + // numSpilledResults returns the number of Results that have been spilled to + // disk by the resultsBuffer so far. + numSpilledResults() int + // error returns the first error encountered by the buffer. error() error @@ -269,6 +273,10 @@ func (b *outOfOrderResultsBuffer) spill(context.Context, int64, int) (bool, erro return false, nil } +func (b *outOfOrderResultsBuffer) numSpilledResults() int { + return 0 +} + func (b *outOfOrderResultsBuffer) close(context.Context) { // Note that only the client's goroutine can be blocked waiting for the // results, and close() is called only by the same goroutine, so signaling @@ -327,6 +335,9 @@ type inOrderResultsBuffer struct { diskBuffer ResultDiskBuffer + // numSpilled tracks how many Results have been spilled to disk so far. + numSpilled int + // addCounter tracks the number of times add() has been called. See // inOrderBufferedResult.addEpoch for why this is needed. addCounter int @@ -569,6 +580,7 @@ func (b *inOrderResultsBuffer) spill( return false, err } r.spill(diskResultID) + b.numSpilled++ b.budget.releaseLocked(ctx, r.memoryTok.toRelease) atLeastBytes -= r.memoryTok.toRelease if atLeastBytes <= 0 { @@ -582,6 +594,12 @@ func (b *inOrderResultsBuffer) spill( return false, nil } +func (b *inOrderResultsBuffer) numSpilledResults() int { + b.Lock() + defer b.Unlock() + return b.numSpilled +} + func (b *inOrderResultsBuffer) close(ctx context.Context) { b.Lock() defer b.Unlock() diff --git a/pkg/kv/kvclient/kvstreamer/streamer.go b/pkg/kv/kvclient/kvstreamer/streamer.go index 71b328563bef..760ccc91bcf1 100644 --- a/pkg/kv/kvclient/kvstreamer/streamer.go +++ b/pkg/kv/kvclient/kvstreamer/streamer.go @@ -30,6 +30,8 @@ import ( "github.com/cockroachdb/cockroach/pkg/util/admission" "github.com/cockroachdb/cockroach/pkg/util/admission/admissionpb" "github.com/cockroachdb/cockroach/pkg/util/buildutil" + "github.com/cockroachdb/cockroach/pkg/util/humanizeutil" + "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/mon" "github.com/cockroachdb/cockroach/pkg/util/quotapool" "github.com/cockroachdb/cockroach/pkg/util/stop" @@ -226,9 +228,7 @@ type Streamer struct { maxKeysPerRow int32 budget *budget - atomics struct { - batchRequestsIssued *int64 - } + streamerStatistics coordinator workerCoordinator coordinatorStarted bool @@ -276,6 +276,37 @@ type Streamer struct { } } +type streamerStatistics struct { + atomics struct { + batchRequestsIssued *int64 + // resumeBatchRequests tracks the number of BatchRequests created for + // the ResumeSpans throughout the lifetime of the Streamer. + resumeBatchRequests int64 + // resumeSingleRangeRequests tracks the number of single-range requests + // that were created for the ResumeSpans throughout the lifetime of the + // Streamer. + resumeSingleRangeRequests int64 + // emptyBatchResponses tracks the number of BatchRequests that resulted + // in empty BatchResponses because they were issued with too low value + // of TargetBytes parameter. + emptyBatchResponses int64 + // droppedBatchResponses tracks the number of the received + // BatchResponses that were dropped because the memory reservation + // during the budget reconciliation was denied (i.e. the original + // estimate was too low, and the budget has been used up by the time + // response came). + droppedBatchResponses int64 + } + // enqueueCalls tracks the number of times Enqueue() has been called. + enqueueCalls int + // enqueuedRequests tracks the number of possibly-multi-range requests that + // have been Enqueue()'d into the Streamer. + enqueuedRequests int + // enqueuedSingleRangeRequests tracks the number of single-range + // sub-requests that were created during the truncation process in Enqueue() + enqueuedSingleRangeRequests int +} + // streamerConcurrencyLimit is an upper bound on the number of asynchronous // requests that a single Streamer can have in flight. The default value for // this setting is chosen arbitrarily as 1/8th of the default value for the @@ -434,6 +465,9 @@ func (s *Streamer) Enqueue(ctx context.Context, reqs []roachpb.RequestUnion) (re return err } + s.enqueueCalls++ + s.enqueuedRequests += len(reqs) + // The minimal key range encompassing all requests contained within. // Local addressing has already been resolved. rs, err := keys.Range(reqs) @@ -542,6 +576,7 @@ func (s *Streamer) Enqueue(ctx context.Context, reqs []roachpb.RequestUnion) (re } requestsToServe = append(requestsToServe, r) + s.enqueuedSingleRangeRequests += len(singleRangeReqs) // Determine next seek key, taking potentially sparse requests into // consideration. @@ -625,6 +660,7 @@ func (s *Streamer) GetResults(ctx context.Context) ([]Result, error) { // other calls on s are allowed after this. func (s *Streamer) Close(ctx context.Context) { if s.coordinatorStarted { + s.coordinator.logStatistics(ctx) s.coordinatorCtxCancel() s.mu.Lock() s.mu.done = true @@ -742,6 +778,31 @@ func (w *workerCoordinator) mainLoop(ctx context.Context) { } } +// logStatistics logs some of the statistics about the Streamer. It should be +// called at the end of the Streamer's lifecycle. +// TODO(yuzefovich): at the moment, these statistics will be attached to the +// tracing span of the Streamer's user. Some time has been spent to figure it +// out but led to no success. This should be cleaned up. +func (w *workerCoordinator) logStatistics(ctx context.Context) { + avgResponseSize, _ := w.getAvgResponseSize() + log.VEventf( + ctx, 1, + "enqueueCalls=%d enqueuedRequests=%d enqueuedSingleRangeRequests=%d "+ + "batchRequestsIssued=%d resumeBatchRequests=%d resumeSingleRangeRequests=%d "+ + "numSpilledResults=%d emptyBatchResponses=%d droppedBatchResponses=%d avgResponseSize=%s", + w.s.enqueueCalls, + w.s.enqueuedRequests, + w.s.enqueuedSingleRangeRequests, + atomic.LoadInt64(w.s.atomics.batchRequestsIssued), + atomic.LoadInt64(&w.s.atomics.resumeBatchRequests), + atomic.LoadInt64(&w.s.atomics.resumeSingleRangeRequests), + w.s.results.numSpilledResults(), + atomic.LoadInt64(&w.s.atomics.emptyBatchResponses), + atomic.LoadInt64(&w.s.atomics.droppedBatchResponses), + humanizeutil.IBytes(avgResponseSize), + ) +} + // waitForRequests blocks until there is at least one request to be served. func (w *workerCoordinator) waitForRequests(ctx context.Context) error { w.s.requestsToServe.Lock() @@ -1129,6 +1190,7 @@ func (w *workerCoordinator) performRequestAsync( // but not enough for that large row). toConsume := -overaccountedTotal if err := w.s.budget.consume(ctx, toConsume, headOfLine /* allowDebt */); err != nil { + atomic.AddInt64(&w.s.atomics.droppedBatchResponses, 1) w.s.budget.release(ctx, targetBytes) if !headOfLine { // Since this is not the head of the line, we'll just @@ -1413,6 +1475,7 @@ func (w *workerCoordinator) processSingleRangeResults( ) } else { // We received an empty response. + atomic.AddInt64(&w.s.atomics.emptyBatchResponses, 1) if req.minTargetBytes != 0 { // We previously have already received an empty response for this // request, and minTargetBytes wasn't sufficient. Make sure that @@ -1444,6 +1507,8 @@ func (w *workerCoordinator) processSingleRangeResults( req.reqs[i] = roachpb.RequestUnion{} } w.s.requestsToServe.add(resumeReq) + atomic.AddInt64(&w.s.atomics.resumeBatchRequests, 1) + atomic.AddInt64(&w.s.atomics.resumeSingleRangeRequests, int64(numIncompleteRequests)) } return nil