Skip to content
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

Merged
merged 1 commit into from
Jan 23, 2020

Conversation

yuzefovich
Copy link
Member

@yuzefovich yuzefovich commented Jan 23, 2020

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.

@yuzefovich yuzefovich requested a review from knz January 23, 2020 04:26
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Contributor

@knz knz left a 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: :shipit: 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 (really tree.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 ....

@yuzefovich yuzefovich changed the title sql: downgrade wrong type error when setting tracing sql: allow booleans in SET tracing and friendlier error message Jan 23, 2020
Copy link
Member Author

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: 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 (really tree.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.

Copy link
Contributor

@knz knz left a 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: :shipit: 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`.
Copy link
Member Author

@yuzefovich yuzefovich left a 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: :shipit: 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.

craig bot pushed a commit that referenced this pull request Jan 23, 2020
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>
@craig
Copy link
Contributor

craig bot commented Jan 23, 2020

Build succeeded

@craig craig bot merged commit 1e4b039 into cockroachdb:master Jan 23, 2020
@yuzefovich yuzefovich deleted the adjust-set-tracing branch January 24, 2020 01:25
@yuzefovich
Copy link
Member Author

Raphael, do you think we should backport it?

@knz
Copy link
Contributor

knz commented Jan 24, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Internal error setting tracing=true
3 participants