Skip to content

Commit

Permalink
sql: add notice for custom var with the same name as a cluster setting
Browse files Browse the repository at this point in the history
No release note since custom session variables are new in 22.1.

Release note: None
  • Loading branch information
rafiss committed Feb 15, 2022
1 parent 9514f13 commit 03a8885
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/set
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,13 @@ SHOW tracing.custom
----
ijk

# Show a notice if a custom session variable has the same name as a cluster setting.
query T noticetrace
SET server.shutdown.drain_wait = '10s'
----
NOTICE: setting custom variable "server.shutdown.drain_wait"
HINT: did you mean SET CLUSTER SETTING?

# Test that RESET ALL changes custom options to empty strings.
statement ok
RESET ALL
Expand Down
10 changes: 10 additions & 0 deletions pkg/sql/set_var.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/cockroachdb/apd/v3"
"github.com/cockroachdb/cockroach/pkg/server/telemetry"
"github.com/cockroachdb/cockroach/pkg/settings"
"github.com/cockroachdb/cockroach/pkg/sql/paramparse"
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode"
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror"
Expand Down Expand Up @@ -61,6 +62,15 @@ func (p *planner) SetVar(ctx context.Context, n *tree.SetVar) (planNode, error)
if err != nil {
return nil, err
}
if _, ok := settings.Lookup(name, settings.LookupForLocalAccess, p.ExecCfg().Codec.ForSystemTenant()); ok {
p.BufferClientNotice(
ctx,
errors.WithHint(
pgnotice.Newf("setting custom variable %q", name),
"did you mean SET CLUSTER SETTING?",
),
)
}

var typedValues []tree.TypedExpr
if len(n.Values) > 0 {
Expand Down

0 comments on commit 03a8885

Please sign in to comment.