-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql: allow booleans in SET tracing and friendlier error message #44260
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for spotting it. Just a minor comment.
Reviewed 2 of 2 files at r1.
Reviewable status:complete! 0 of 0 LGTMs obtained (waiting on @yuzefovich)
pkg/sql/conn_executor_exec.go, line 1184 at r1 (raw file):
strVal, ok := v.(*tree.StrVal) if !ok { res.SetError(errors.Newf("expected string for set tracing argument, not %T", v))
I agree we need to fix this but this is not the way to go about it.
The main problem is that it's not good style to show something internal (%T) in a user-facing message.
The second problem is that it could be nice to allow booleans.
There are two ways to go:
- either the way of
(*planner) SetVar
- or that of
(*planner)EvalAsOfTimestamp
(reallytree.EvalAsOfTimestamp
)
It's possible you can't use analyzeExpr
/Eval
like the first option, that's why I am mentioning the second.
(The reason why SET tracing is not an actual SetVar is that we want, I think, to be able to run it even when the txn is in error; in which case scalar evaluation is unavailable. But I'm not 100% sure. For the record, I prefer the SET (SetVar) semantics more.)
Long story short, get the expression, type switch on the result, and print a friendly error message.
Also the pg code for something that doesn't have the right type is pgcode.Syntax
.
pkg/sql/logictest/testdata/logic_test/set, line 305 at r1 (raw file):
SET ssl_renegotiation_limit = 123 statement error pq: expected string for set tracing argument, not \*tree.DBool
when you have a code, do statement pgerror XXXX ....
d2b7073
to
60fcbea
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @knz and @yuzefovich)
pkg/sql/conn_executor_exec.go, line 1184 at r1 (raw file):
Previously, knz (kena) wrote…
I agree we need to fix this but this is not the way to go about it.
The main problem is that it's not good style to show something internal (%T) in a user-facing message.
The second problem is that it could be nice to allow booleans.There are two ways to go:
- either the way of
(*planner) SetVar
- or that of
(*planner)EvalAsOfTimestamp
(reallytree.EvalAsOfTimestamp
)It's possible you can't use
analyzeExpr
/Eval
like the first option, that's why I am mentioning the second.
(The reason why SET tracing is not an actual SetVar is that we want, I think, to be able to run it even when the txn is in error; in which case scalar evaluation is unavailable. But I'm not 100% sure. For the record, I prefer the SET (SetVar) semantics more.)Long story short, get the expression, type switch on the result, and print a friendly error message.
Also the pg code for something that doesn't have the right type is
pgcode.Syntax
.
Thanks for the comment! I added the support for boolean arguments and changed the error to a regular query error.
In terms of SetVar
semantics, I'm also not sure about the behavior there, so I'd rather stick with this least invasive approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM modulo resolution of my comment below
Reviewed 2 of 2 files at r2.
Reviewable status:complete! 0 of 0 LGTMs obtained (waiting on @yuzefovich)
pkg/sql/logictest/testdata/logic_test/set, line 305 at r1 (raw file):
Previously, knz (kena) wrote…
when you have a code, do
statement pgerror XXXX ....
can ou add an additional test that shows the syntax error
Previously, we would fail an assertion if a datum of the wrong type is provided in `SET tracing` query (only strings were allowed). This resulted in an internal error and printing out of the stack trace which can be scary to users. This commit removes the assertion and makes it a regular query error. Also, booleans are now allowed as argument to `SET tracing`, and `true` is mapped to `on` mode and `false` to `off`. Release note (sql change, bug fix): Previously, CockroachDB would return an internal error when using `SET tracing` with any type other than string. Now it will return a regular query error. Additionally, boolean arguments are now supported in `SET tracing`, and `true` is mapped to `on` mode of tracing whereas `false` is mapped to `off`.
60fcbea
to
1e4b039
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TFTR!
bors r+
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @knz)
pkg/sql/logictest/testdata/logic_test/set, line 305 at r1 (raw file):
Previously, knz (kena) wrote…
can ou add an additional test that shows the syntax error
Done.
44260: sql: allow booleans in SET tracing and friendlier error message r=yuzefovich a=yuzefovich Previously, we would fail an assertion if a datum of the wrong type is provided in `SET tracing` query (only strings were allowed). This resulted in an internal error and printing out of the stack trace which can be scary to users. This commit removes the assertion and makes it a regular query error. Also, booleans are now allowed as argument to `SET tracing`, and `true` is mapped to `on` mode and `false` to `off`. Fixes: #44244. Release note (sql change, bug fix): Previously, CockroachDB would return an internal error when using `SET tracing` with any type other than string. Now it will return a regular query error. Additionally, boolean arguments are now supported in `SET tracing`, and `true` is mapped to `on` mode of tracing whereas `false` is mapped to `off`. Co-authored-by: Yahor Yuzefovich <yahor@cockroachlabs.com>
Build succeeded |
Raphael, do you think we should backport it? |
Yes because we don't want this to continue spamming Sentry
--
Verstuurd vanaf mijn Android apparaat met K-9 Mail. Excuseer mijn beknoptheid.
|
Previously, we would fail an assertion if a datum of the wrong type is
provided in
SET tracing
query (only strings were allowed). This resultedin an internal error and printing out of the stack trace which can be
scary to users. This commit removes the assertion and makes it a regular
query error.
Also, booleans are now allowed as argument to
SET tracing
, andtrue
is mapped to
on
mode andfalse
tooff
.Fixes: #44244.
Release note (sql change, bug fix): Previously, CockroachDB would return
an internal error when using
SET tracing
with any type other thanstring. Now it will return a regular query error. Additionally, boolean
arguments are now supported in
SET tracing
, andtrue
is mapped toon
mode of tracing whereasfalse
is mapped tooff
.