Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
119886: sql: optimize some allocations when establishing new connections r=yuzefovich a=yuzefovich

Epic: None

Release note: None

Co-authored-by: Yahor Yuzefovich <[email protected]>
  • Loading branch information
craig[bot] and yuzefovich committed Mar 5, 2024
2 parents 4fbadd4 + 798af07 commit 1516e36
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
20 changes: 16 additions & 4 deletions pkg/sql/sessiondatapb/local_only_session_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,26 @@ var qosLevelsDict = map[QoSLevel]string{
SystemHigh: SystemHighName,
}

func init() {
// Sanity check that all names for QoS levels use lower case (this
// assumption is used in ParseQoSLevelFromString).
for _, val := range qosLevelsDict {
if strings.ToLower(val) != val {
panic(errors.AssertionFailedf(
"expected only lower case letters in QoS level name %s", val,
))
}
}
}

// ParseQoSLevelFromString converts a string into a QoSLevel
func ParseQoSLevelFromString(val string) (_ QoSLevel, ok bool) {
switch strings.ToUpper(val) {
case strings.ToUpper(UserHighName):
switch strings.ToLower(val) {
case UserHighName:
return UserHigh, true
case strings.ToUpper(UserLowName):
case UserLowName:
return UserLow, true
case strings.ToUpper(NormalName):
case NormalName:
return Normal, true
default:
return 0, false
Expand Down
10 changes: 5 additions & 5 deletions pkg/sql/set_var.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func makeTimeoutVarGetter(
case *tree.DString:
return string(*v), nil
case *tree.DInterval:
timeout, err = intervalToDuration(v)
timeout, err = durationToTotalNanos(v.Duration)
if err != nil {
return "", wrapSetVarError(err, varName, values[0].String())
}
Expand All @@ -378,7 +378,7 @@ func makeTimeoutVarGetter(
func validateTimeoutVar(
style duration.IntervalStyle, timeString string, varName string,
) (time.Duration, error) {
interval, err := tree.ParseDIntervalWithTypeMetadata(
interval, err := tree.ParseIntervalWithTypeMetadata(
style,
timeString,
types.IntervalTypeMetadata{
Expand All @@ -390,7 +390,7 @@ func validateTimeoutVar(
if err != nil {
return 0, wrapSetVarError(err, varName, timeString)
}
timeout, err := intervalToDuration(interval)
timeout, err := durationToTotalNanos(interval)
if err != nil {
return 0, wrapSetVarError(err, varName, timeString)
}
Expand Down Expand Up @@ -474,8 +474,8 @@ func idleInTransactionSessionTimeoutVarSet(
return nil
}

func intervalToDuration(interval *tree.DInterval) (time.Duration, error) {
nanos, _, _, err := interval.Encode()
func durationToTotalNanos(duration duration.Duration) (time.Duration, error) {
nanos, _, _, err := duration.Encode()
if err != nil {
return 0, err
}
Expand Down

0 comments on commit 1516e36

Please sign in to comment.