github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/sqltelemetry/scalar.go (about) 1 // Copyright 2019 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package sqltelemetry 12 13 import ( 14 "fmt" 15 16 "github.com/cockroachdb/cockroach/pkg/server/telemetry" 17 ) 18 19 // BuiltinCounter creates a telemetry counter for a built-in function. 20 // This is to be incremented upon type checking of a function application. 21 func BuiltinCounter(name, signature string) telemetry.Counter { 22 return telemetry.GetCounterOnce(fmt.Sprintf("sql.plan.builtins.%s%s", name, signature)) 23 } 24 25 // UnaryOpCounter creates a telemetry counter for a scalar unary operator. 26 // This is to be incremented upon type checking of this type of scalar operation. 27 func UnaryOpCounter(op, typ string) telemetry.Counter { 28 return telemetry.GetCounterOnce(fmt.Sprintf("sql.plan.ops.un.%s %s", op, typ)) 29 } 30 31 // CmpOpCounter creates a telemetry counter for a scalar comparison operator. 32 // This is to be incremented upon type checking of this type of scalar operation. 33 func CmpOpCounter(op, ltyp, rtyp string) telemetry.Counter { 34 return telemetry.GetCounterOnce(fmt.Sprintf("sql.plan.ops.cmp.%s %s %s", ltyp, op, rtyp)) 35 } 36 37 // BinOpCounter creates a telemetry counter for a scalar binary operator. 38 // This is to be incremented upon type checking of this type of scalar operation. 39 func BinOpCounter(op, ltyp, rtyp string) telemetry.Counter { 40 return telemetry.GetCounterOnce(fmt.Sprintf("sql.plan.ops.bin.%s %s %s", ltyp, op, rtyp)) 41 } 42 43 // CastOpCounter creates a telemetry counter for a scalar cast operator. 44 // This is to be incremented upon type checking of this type of scalar operation. 45 func CastOpCounter(ftyp, ttyp string) telemetry.Counter { 46 return telemetry.GetCounterOnce(fmt.Sprintf("sql.plan.ops.cast.%s::%s", ftyp, ttyp)) 47 } 48 49 // ArrayCastCounter is to be incremented when type checking all casts 50 // that involve arrays. This separate telemetry counter is needed 51 // because an inter-array cast lands on `sql.plan.ops.cast` telemetry 52 // counter for the element type. 53 var ArrayCastCounter = telemetry.GetCounterOnce("sql.plan.ops.cast.arrays") 54 55 // EnumCastCounter is to be incremented when typechecking casts that 56 // are between enums. 57 var EnumCastCounter = telemetry.GetCounterOnce("sql.plan.ops.cast.enums") 58 59 // ArrayConstructorCounter is to be incremented upon type checking 60 // of ARRAY[...] expressions/ 61 var ArrayConstructorCounter = telemetry.GetCounterOnce("sql.plan.ops.array.cons") 62 63 // ArrayFlattenCounter is to be incremented upon type checking 64 // of ARRAY(...) expressions. 65 var ArrayFlattenCounter = telemetry.GetCounterOnce("sql.plan.ops.array.flatten") 66 67 // ArraySubscriptCounter is to be incremented upon type checking an 68 // array subscript expression x[...]. 69 var ArraySubscriptCounter = telemetry.GetCounterOnce("sql.plan.ops.array.ind") 70 71 // IfErrCounter is to be incremented upon type checking an 72 // IFERROR(...) expression or analogous. 73 var IfErrCounter = telemetry.GetCounterOnce("sql.plan.ops.iferr") 74 75 // LargeLShiftArgumentCounter is to be incremented upon evaluating a scalar 76 // expressions a << b when b is larger than 64 or negative. 77 var LargeLShiftArgumentCounter = telemetry.GetCounterOnce("sql.large_lshift_argument") 78 79 // LargeRShiftArgumentCounter is to be incremented upon evaluating a scalar 80 // expressions a >> b when b is larger than 64 or negative. 81 var LargeRShiftArgumentCounter = telemetry.GetCounterOnce("sql.large_rshift_argument")