Skip to content

Commit

Permalink
tree: tag RESET statements as RESET
Browse files Browse the repository at this point in the history
Release note (sql change): We now correctly send the RESET tag instead
of the SET tag when a RESET statement is run.
  • Loading branch information
otan committed Aug 18, 2021
1 parent 5d2c91c commit 06989a9
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pkg/sql/logictest/testdata/logic_test/crdb_internal
Original file line number Diff line number Diff line change
Expand Up @@ -583,10 +583,10 @@ ORDER BY key, f
----
CREATE SEQUENCE s 0 false
DROP SEQUENCE s 0 false
RESET application_name 0 false
SELECT IF(nextval(_) < _, crdb_internal.force_retry(_), _) 2 false
SELECT IF(nextval(_) < _, crdb_internal.force_retry(_), _) 1 true
SELECT IF(nextval(_) < _, crdb_internal.force_retry(_::INTERVAL), _) 0 true
SET application_name = DEFAULT 0 false

query T
SELECT database_name FROM crdb_internal.node_statement_statistics limit 1
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/logictest/testdata/logic_test/crdb_internal_tenant
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,10 @@ ORDER BY key, f
----
CREATE SEQUENCE s 0 false
DROP SEQUENCE s 0 false
RESET application_name 0 false
SELECT IF(nextval(_) < _, crdb_internal.force_retry(_), _) 2 false
SELECT IF(nextval(_) < _, crdb_internal.force_retry(_), _) 1 true
SELECT IF(nextval(_) < _, crdb_internal.force_retry(_::INTERVAL), _) 0 true
SET application_name = DEFAULT 0 false

query T
SELECT crdb_internal.cluster_name()
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -4381,11 +4381,11 @@ reset_stmt:
reset_session_stmt:
RESET session_var
{
$$.val = &tree.SetVar{Name: $2, Values:tree.Exprs{tree.DefaultVal{}}}
$$.val = &tree.SetVar{Name: $2, Values:tree.Exprs{tree.DefaultVal{}}, Reset: true}
}
| RESET SESSION session_var
{
$$.val = &tree.SetVar{Name: $3, Values:tree.Exprs{tree.DefaultVal{}}}
$$.val = &tree.SetVar{Name: $3, Values:tree.Exprs{tree.DefaultVal{}}, Reset: true}
}
| RESET error // SHOW HELP: RESET

Expand Down
16 changes: 8 additions & 8 deletions pkg/sql/parser/testdata/set
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,10 @@ SET client_encoding = DEFAULT -- identifiers removed
parse
RESET a
----
SET a = DEFAULT -- normalized!
SET a = (DEFAULT) -- fully parenthesized
SET a = DEFAULT -- literals removed
SET a = DEFAULT -- identifiers removed
RESET a
RESET a -- fully parenthesized
RESET a -- literals removed
RESET a -- identifiers removed

parse
RESET CLUSTER SETTING a
Expand All @@ -487,7 +487,7 @@ SET CLUSTER SETTING a = DEFAULT -- identifiers removed
parse
RESET NAMES
----
SET client_encoding = DEFAULT -- normalized!
SET client_encoding = (DEFAULT) -- fully parenthesized
SET client_encoding = DEFAULT -- literals removed
SET client_encoding = DEFAULT -- identifiers removed
RESET client_encoding -- normalized!
RESET client_encoding -- fully parenthesized
RESET client_encoding -- literals removed
RESET client_encoding -- identifiers removed
10 changes: 10 additions & 0 deletions pkg/sql/pgwire/testdata/pgtest/set
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
send
Query {"String": "RESET intervalstyle"}
----

until
ReadyForQuery
----
{"Type":"ParameterStatus","Name":"IntervalStyle","Value":"postgres"}
{"Type":"CommandComplete","CommandTag":"RESET"}
{"Type":"ReadyForQuery","TxStatus":"I"}
10 changes: 10 additions & 0 deletions pkg/sql/sem/tree/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package tree
type SetVar struct {
Name string
Values Exprs
Reset bool
ResetAll bool
}

Expand All @@ -32,6 +33,15 @@ func (node *SetVar) Format(ctx *FmtCtx) {
ctx.WriteString("RESET ALL")
return
}
if node.Reset {
ctx.WriteString("RESET ")
ctx.WithFlags(ctx.flags & ^FmtAnonymize & ^FmtMarkRedactionNode, func() {
// Session var names never contain PII and should be distinguished
// for feature tracking purposes.
ctx.FormatNameP(&node.Name)
})
return
}
ctx.WriteString("SET ")
if node.Name == "" {
ctx.WriteString("ROW (")
Expand Down
7 changes: 6 additions & 1 deletion pkg/sql/sem/tree/stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,12 @@ func (*SetVar) StatementReturnType() StatementReturnType { return Ack }
func (*SetVar) StatementType() StatementType { return TypeDCL }

// StatementTag returns a short string identifying the type of statement.
func (*SetVar) StatementTag() string { return "SET" }
func (n *SetVar) StatementTag() string {
if n.Reset || n.ResetAll {
return "RESET"
}
return "SET"
}

// StatementReturnType implements the Statement interface.
func (*SetClusterSetting) StatementReturnType() StatementReturnType { return Ack }
Expand Down

0 comments on commit 06989a9

Please sign in to comment.