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

tree: handle null in suboperator expressions #37775

Merged
merged 1 commit into from
May 24, 2019

Conversation

rafiss
Copy link
Collaborator

@rafiss rafiss commented May 23, 2019

Before this change, a null right operand in a suboperator would cause an
unhandled error. We were receiving stack trace reports from the wild.
Add a test and fix it.

fixes #37547
Release note (bug fix): a null right operand now causes the suboperator
expression to return null

@rafiss rafiss requested review from jordanlewis, asubiotto and a team May 23, 2019 16:07
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@rafiss rafiss added the first-pr Use to mark the first PR sent by a contributor / team member. Reviewers should be mindful of this. label May 23, 2019
Copy link
Member

@jordanlewis jordanlewis left a comment

Choose a reason for hiding this comment

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

This :lgtm: - nice! Thinking again about it, I think you could solve the problem and also clean up the previous code a tiny bit at the same time with a small change. I left an inline suggestion.

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @asubiotto, @jordanlewis, and @rafiss)


pkg/sql/sem/tree/eval.go, line 3686 at r1 (raw file):

	_, newLeft, newRight, _, not := foldComparisonExpr(op, left, right)
	if !expr.fn.NullableArgs && (newLeft == DNull || newRight == DNull) {

I just realized that this code should also apply to the case with suboperators, so I think we could pull this check up above the suboperator check and avoid the new special case.

This should be valid because NULL = ANY (...) is always NULL, and x = ANY NULL is always NULL as well.

(and the detail about running this on newLeft and newRight isn't important - if you click into foldComparisonExpr, that might just reverse the order of left and right - but since we're checking if either of them for NULL-ness, we can just as well run the check before folding as after.)


pkg/sql/sem/tree/testdata/eval/any_some_all, line 74 at r1 (raw file):


eval
1 = ANY(NULL::int[])

small style thing: For test cases like this one, (e.g. it might not be super obvious why you need the extra cast), we typically add a comment above the test case that says that it's a regression test for an issue. So you'd say something approximately like "# Regression test for #issuenum - ensure that null RHS of comparions with suboperators are correctly handled."

Copy link
Collaborator Author

@rafiss rafiss 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! 1 of 0 LGTMs obtained (waiting on @asubiotto and @jordanlewis)


pkg/sql/sem/tree/eval.go, line 3686 at r1 (raw file):

Previously, jordanlewis (Jordan Lewis) wrote…

I just realized that this code should also apply to the case with suboperators, so I think we could pull this check up above the suboperator check and avoid the new special case.

This should be valid because NULL = ANY (...) is always NULL, and x = ANY NULL is always NULL as well.

(and the detail about running this on newLeft and newRight isn't important - if you click into foldComparisonExpr, that might just reverse the order of left and right - but since we're checking if either of them for NULL-ness, we can just as well run the check before folding as after.)

Done.


pkg/sql/sem/tree/testdata/eval/any_some_all, line 74 at r1 (raw file):

Previously, jordanlewis (Jordan Lewis) wrote…

small style thing: For test cases like this one, (e.g. it might not be super obvious why you need the extra cast), we typically add a comment above the test case that says that it's a regression test for an issue. So you'd say something approximately like "# Regression test for #issuenum - ensure that null RHS of comparions with suboperators are correctly handled."

Done.

@rafiss rafiss force-pushed the suboperator-null-handling branch from 62a8e63 to 66edbc4 Compare May 23, 2019 17:43
Copy link
Member

@jordanlewis jordanlewis left a comment

Choose a reason for hiding this comment

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

:lgtm_strong:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @asubiotto)

Copy link
Contributor

@asubiotto asubiotto left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r2.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained

@rafiss rafiss force-pushed the suboperator-null-handling branch from 66edbc4 to a317980 Compare May 23, 2019 18:39
@asubiotto
Copy link
Contributor

Looks like CI is failing. TeamCity is pretty confusing so let me know if you want a hand in figuring out what's wrong.

Before this change, a null right operand in a suboperator would cause an
unhandled error. We were receiving stack trace reports from the wild.
Add a test and fix it. Also add a few additional tests to verify correct
behavior with a null left operand.

Release note (bug fix): a null right operand now causes the suboperator
expression to return null
@rafiss rafiss force-pushed the suboperator-null-handling branch from a317980 to d610375 Compare May 24, 2019 14:44
Copy link
Collaborator Author

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

turns out the earlier suggestion to move the check earlier in the code breaks other behavior -- a null LHS in suboperators has different behavior. i went back to the original version and added more tests.

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @asubiotto)

@rafiss
Copy link
Collaborator Author

rafiss commented May 24, 2019

bors r+

craig bot pushed a commit that referenced this pull request May 24, 2019
37775: tree: handle null in suboperator expressions r=rafiss a=rafiss

Before this change, a null right operand in a suboperator would cause an
unhandled error. We were receiving stack trace reports from the wild.
Add a test and fix it.

fixes #37547 
Release note (bug fix): a null right operand now causes the suboperator
expression to return null

Co-authored-by: Rafi Shamim <[email protected]>
@craig
Copy link
Contributor

craig bot commented May 24, 2019

Build succeeded

@craig craig bot merged commit d610375 into cockroachdb:master May 24, 2019
@jordanlewis
Copy link
Member

Woo!

Since this is an isolated bugfix for a correctness issue that people have been seeing in the wild, you should also backport it to the 19.1 release branch so that it will be available in the next 19.1 patch release. There are instructions for this on the wiki.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
first-pr Use to mark the first PR sent by a contributor / team member. Reviewers should be mindful of this.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sentry: comparison ops with suboperators don't handle NULLs
4 participants