-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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: properly handle parenthesized/nested tuples as operands for ANY/ALL operations #18266
Conversation
Can you see if there's a way this can be done without Review status: 0 of 4 files reviewed at latest revision, 5 unresolved discussions, some commit checks failed. pkg/sql/parser/expr.go, line 272 at r1 (raw file):
I think you can maybe write this with fewer jumpy statements:
? Also, you never use the return value of this so consider either making this not return a value or using its return value. Since it's mutative I would lean towards not returning a value to emphasize that. pkg/sql/parser/expr_test.go, line 237 at r1 (raw file):
you can make these subtests (which can give you slightly cleaner output) if you use pkg/sql/parser/expr_test.go, line 244 at r1 (raw file):
I think you can put this on the pkg/sql/parser/type_check.go, line 913 at r1 (raw file):
nit: period pkg/sql/parser/type_check.go, line 925 at r1 (raw file):
super nit: wrap "tuple" with backticks so it's clearer that this is referring to a variable Comments from Reviewable |
Thanks for bringing this up! I decided to leave in I've verified that the types are propagated to the surrounding Review status: 0 of 4 files reviewed at latest revision, 5 unresolved discussions, some commit checks failed. pkg/sql/parser/expr.go, line 272 at r1 (raw file): Previously, justinj (Justin Jaffray) wrote…
Done. pkg/sql/parser/expr_test.go, line 237 at r1 (raw file): Previously, justinj (Justin Jaffray) wrote…
Done. pkg/sql/parser/expr_test.go, line 244 at r1 (raw file): Previously, justinj (Justin Jaffray) wrote…
I needed to scope the pkg/sql/parser/type_check.go, line 913 at r1 (raw file): Previously, justinj (Justin Jaffray) wrote…
Removed comment so n/a anymore. pkg/sql/parser/type_check.go, line 925 at r1 (raw file): Previously, justinj (Justin Jaffray) wrote…
Removed comment so n/a anymore. Comments from Reviewable |
(I think you didn't push up your changes) Review status: 0 of 4 files reviewed at latest revision, 5 unresolved discussions, some commit checks pending. Comments from Reviewable |
7a7e08e
to
c8e23ba
Compare
One more thing I don't fully understand - why do we need to type every layer of parentheses rather than just typing the outermost ones? Otherwise LGTM but @knz might have comments so wait for him to take a look. Review status: 0 of 4 files reviewed at latest revision, 3 unresolved discussions. pkg/sql/parser/expr.go, line 278 at r2 (raw file):
nit: extra line pkg/sql/parser/expr_test.go, line 244 at r1 (raw file): Previously, richardwu (Richard Wu) wrote…
Ah yeah, my bad! Comments from Reviewable |
I think you're still missing one intellectual step about the power of functional rewrites. In particular, it is valid to remove any remaining ParenExpr here. So strip away! And don't bother to "annotate types on them". See my comments below for some suggestions, but please also grep for Reviewed 1 of 4 files at r1, 2 of 3 files at r2. pkg/sql/parser/expr.go, line 269 at r2 (raw file):
wut? no!! 😆 pkg/sql/parser/type_check.go, line 918 at r2 (raw file):
Man you're making this so complicated! Replace this entire conditional by
bam! pkg/sql/parser/type_check.go, line 980 at r2 (raw file):
Insert pkg/sql/parser/type_check.go, line 981 at r2 (raw file):
Remove the call to pkg/sql/parser/type_check.go, line 1006 at r2 (raw file):
Remove (see above -- the parentheses are gone if you arrive here.) pkg/sql/parser/type_check.go, line 1024 at r2 (raw file):
remove the call to StripParens here, already done above Comments from Reviewable |
I'm wondering if we might run into bugs later on with precedence when we serialize it for distsql. For example, this came up with negative numbers #15617. I can't think of an example off the top of my head (perhaps someone more familiar with SQL grammar gotchas would fare better) where serializing the functional rewrite of an expression without parentheses would cause mis-parsing, but I think you're absolutely correct! Comments from Reviewable |
c8e23ba
to
481bb34
Compare
Review status: 0 of 2 files reviewed at latest revision, 9 unresolved discussions. pkg/sql/parser/type_check.go, line 918 at r2 (raw file): Previously, knz (kena) wrote…
I've decided to require that the expression passed in be strictly a Tuple and let parentheses unwrapping be handled by its callers. pkg/sql/parser/type_check.go, line 980 at r2 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/parser/type_check.go, line 981 at r2 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/parser/type_check.go, line 1006 at r2 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/parser/type_check.go, line 1024 at r2 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/parser/expr.go, line 269 at r2 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/parser/expr.go, line 278 at r2 (raw file): Previously, justinj (Justin Jaffray) wrote…
Done. Comments from Reviewable |
d9caed6
to
9790b69
Compare
9790b69
to
7a02e3a
Compare
In order to keep things consistent across the board, I've decided to strip ParenExpr from all expressions in general during type checking. It would be great to get another look/LGTM if this is okay (@knz, @justinj). I can also move this to another PR if necessary! Comments from Reviewable |
Reviewed 5 of 5 files at r3. Comments from Reviewable |
Type checking for tuples in ANY/ALL operations were added in #18094.
It was initially implemented such that it assumed the
right Expr
was either a literaltuple
(of which it would require every element be equivalent to the type ofleft
after upcasting), an array, or a subquery.We did not however check for tuples nested within parentheses, thus a semantically-incorrect expression such as
would not type error but succeed.