-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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: refactor the handling of qualified names #8152
Conversation
@petermattis who do you think is best qualified (ha!) to review this? |
Reviewed 22 of 58 files at r1. sql/parser/qnames.go, line 132 [r1] (raw file):
instead of replacing the Target when normalizing, what if you made the targets carry the string representation? the contract would then require you to use the return value of normalize. That would also allow you to remove the NameTarget interface (I think) and all the pointer use that results from it. sql/parser/qnames.go, line 148 [r1] (raw file):
fmt.Stringer? sql/testdata/insert, line 405 [r1] (raw file):
throughout: what does "not supported" mean? sql/testdata/join, line 279 [r1] (raw file):
why does the database name rencer on one side but not the other? sql/testdata/update, line 150 [r1] (raw file):
"or not selected"? sql/testdata/upsert, line 127 [r1] (raw file):
this error seems worse since the database name is far away =/ Comments from Reviewable |
Reviewed 27 of 58 files at r1. sql/insert.go, line 350 [r1] (raw file):
yeah this needs more words, or something sql/select_qvalue.go, line 183 [r1] (raw file):
i dont think we do this, just omit? sql/sort.go, line 93 [r1] (raw file):
no need for String() sql/table.go, line 82 [r1] (raw file):
indentation is off sql/sqlbase/keys.go, line 83 [r1] (raw file):
why isn't this in parser? sql/testdata/subquery, line 318 [r1] (raw file):
this is also weird in that the database name does not appear consistently. Comments from Reviewable |
@tamird TYFR! Review status: 49 of 58 files reviewed at latest revision, 12 unresolved discussions, some commit checks failed. sql/insert.go, line 350 [r1] (raw file):
|
b87ccbc
to
a94fb22
Compare
Reviewed 2 of 58 files at r1, 7 of 11 files at r2, 6 of 7 files at r3. sql/insert.go, line 350 [r1] (raw file):
|
637fba3
to
a2e7ec7
Compare
Review status: 30 of 73 files reviewed at latest revision, 8 unresolved discussions, all commit checks successful. sql/parser/sql.y, line 26 [r1] (raw file):
This entire file has lots of cases where you converted spaces to tabs. Although I agree that tabs are better, they are not standard here and should be changed back to spaces. sql/parser/sql.y, line 939 [r1] (raw file):
tabs -> spaces example. Not commenting on the rest. sql/parser/sql.y, line 1414 [r1] (raw file):
space after "Name:" Comments from Reviewable |
FYI I ran this against the random syntax generator for a while and it didn't find anything. Review status: 30 of 73 files reviewed at latest revision, 8 unresolved discussions, all commit checks successful. Comments from Reviewable |
Great stuff! Some minor comments. I still have to take a closer look at the qnames and table_pattern code. Review status: 30 of 73 files reviewed at latest revision, 22 unresolved discussions, some commit checks failed. sql/alter_table.go, line 79 [r4] (raw file):
[nit] long line, can just do a sql/create.go, line 256 [r4] (raw file):
[nit] long line (here and below), could move outside the if since it's already in its own block sql/create.go, line 342 [r4] (raw file):
[nit] long line sql/data_source.go, line 141 [r4] (raw file):
I like the new types! Nothing like self-documenting code :) sql/data_source.go, line 155 [r4] (raw file):
Why are we using sql/data_source.go, line 432 [r4] (raw file):
[nit] long line sql/data_source.go, line 467 [r4] (raw file):
[nit] long line
sql/rename.go, line 42 [r4] (raw file):
we usually use TODO (it matters when we grep for them) sql/sort.go, line 93 [r4] (raw file):
errors.Errorf sql/table.go, line 342 [r4] (raw file):
if it doesn't all fit on one line, put the args on a separate line (see the code style) sql/parser/qnames.go, line 205 [r4] (raw file):
you can do a sql/parser/qnames.go, line 278 [r4] (raw file):
I think all these should be errors.Errorf sql/parser/sql.y, line 112 [r4] (raw file):
these should be spaces (and below) sql/parser/table_pattern.go, line 26 [r4] (raw file):
Why "pattern"? Comments from Reviewable |
Review status: 30 of 73 files reviewed at latest revision, 26 unresolved discussions, some commit checks failed. sql/parser/qnames.go, line 208 [r3] (raw file):
|
Review status: 30 of 73 files reviewed at latest revision, 27 unresolved discussions, some commit checks failed. sql/show.go, line 226 [r4] (raw file):
Any reason converting to a NameList and running String on it won't work here? Looks the same to me and will prevent duplicating this code. Comments from Reviewable |
Review status: 30 of 73 files reviewed at latest revision, 27 unresolved discussions, some commit checks failed. sql/parser/sql.y, line 26 [r1] (raw file):
|
Some more serious refactorings in there. Also rebased over master. PTAL. @nvanbenschoten you may want to look at the small updates to Review status: 14 of 85 files reviewed at latest revision, 27 unresolved discussions. sql/alter_table.go, line 79 [r4] (raw file):
|
@@ -38,14 +38,15 @@ type Visitor interface { | |||
VisitPost(expr Expr) (newNode Expr) | |||
} | |||
|
|||
func copyQualifiedNames(q QualifiedNames) QualifiedNames { | |||
if q == nil { | |||
// FIXME(knz) Is this really necessary? It seems that unresolved name |
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.
@RaduBerinde I'd like your feedback on this one. I think the entire function can be removed.
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.
If we never change them, yeah that can be removed (and "change" I mean both the interface references inside the slices, and the objects they refer).
Note that as is this function doesn't truly make a copy - the new UnresolvedNames
"points" to the same []NamePart
.
We should call out the immutability explicitly where we define UnresolvedNames
. It is a slice of slices of interface pointers so it's pretty much impossible to see or verify the immutability just from looking at the code.
Review status: 14 of 85 files reviewed at latest revision, 29 unresolved discussions, some commit checks failed. sql/upsert.go, line 98 [r6] (raw file):
|
|
||
// NameParts represents a combination of names with array and | ||
// sub-field subscripts. | ||
type NameParts []NamePart |
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.
How many NamePart
s can be in a slice here? If it's at most two or three, consider making this a fixed-size array (with nil entries for what's unneeded) to avoid the indirection and extra allocations.
I'm having a lot of trouble reviewing this (too many files).. Do you think you could break it up into three commits by files (everything in parser/ in one commit, everything in testdata/ in another, and the rest in another)? You can squash them back before merging. Review status: 14 of 85 files reviewed at latest revision, 29 unresolved discussions, some commit checks failed. sql/parser/qnames.go, line 278 [r4] (raw file):
|
So Review status: 14 of 85 files reviewed at latest revision, 29 unresolved discussions, some commit checks failed. Comments from Reviewable |
@RaduBerinde I went through the remaining mentions of "qualified". Thanks for highlighting that I didn't pass @nvanbenschoten: this is a different normalization! the Review status: 13 of 89 files reviewed at latest revision, 28 unresolved discussions, some commit checks failed. cli/zone.go, line 183 [r16] (raw file):
|
Review status: 12 of 93 files reviewed at latest revision, 28 unresolved discussions, all commit checks successful. sql/parser/function_name.go, line 36 [r9] (raw file):
|
Review status: 12 of 93 files reviewed at latest revision, 17 unresolved discussions, all commit checks successful. sql/parser/function_name.go, line 36 [r9] (raw file):
|
Review status: 12 of 92 files reviewed at latest revision, 17 unresolved discussions, all commit checks successful. sql/parser/function_name.go, line 36 [r9] (raw file):
|
Review status: 12 of 92 files reviewed at latest revision, 17 unresolved discussions, all commit checks successful. sql/parser/function_name.go, line 36 [r9] (raw file):
|
Hi guys so since I am leaving on vacation tomorrow I am passing stewardship of this PR to @RaduBerinde. Ideally there should be a completed review from someone else before the PR is merged (it got just one thumb up for now). |
0cc3d5c
to
4c1f98e
Compare
Rebased. Let me know if there are any major outstanding issues. Note that since I'm not the original author of the change I may be missing subtle details and original motivation for various decisions so I will try to minimize further changes. Review status: 12 of 92 files reviewed at latest revision, 17 unresolved discussions, some commit checks pending. Comments from Reviewable |
4c1f98e
to
f8a9cf0
Compare
Review status: 12 of 92 files reviewed at latest revision, 24 unresolved discussions, some commit checks failed. sql/show.go, line 226 [r4] (raw file):
|
Just some minor comments, but overall Review status: 12 of 92 files reviewed at latest revision, 24 unresolved discussions, some commit checks failed. Comments from Reviewable |
f8a9cf0
to
537628f
Compare
Thanks Matt! Review status: 12 of 92 files reviewed at latest revision, 24 unresolved discussions, some commit checks failed. sql/show.go, line 226 [r4] (raw file):
|
Review status: 12 of 92 files reviewed at latest revision, 23 unresolved discussions, some commit checks failed. sql/parser/parse.go, line 166 [r19] (raw file):
|
Review status: 12 of 92 files reviewed at latest revision, 23 unresolved discussions, some commit checks failed. sql/parser/parse.go, line 166 [r19] (raw file):
|
4cef991
to
b0a2ccd
Compare
@dt after merging with your changes I am hitting a timeout during the logic test, on |
@dt never mind, the problem is due to some new FK tests (crossdb) and is reproducible on master, I will file an issue. |
b0a2ccd
to
5402999
Compare
This patch introduces separate types for qualified names used in different contexts. We now have: - `TablePattern`, interfacing for `UnresolvedName`, `TableName` and `AllTablesSelector`. - `VarName`, interfacing for `UnresolvedName`, `UnqualifiedStar`, `AllColumnsSelector` and `ColumnItem`. - `FunctionName`, interfacing for `UnresolvedName` and `QualifiedFunctionName`. - `NamePart`, interfacing for `Name`, `UnqualifiedStar` and `ArraySubscript`, used for the components of `UnresolvedName`. Each of them only allow a specific syntax, which is checked in a single place. This fixes various panics when invalid expressions were used; as well as enabling foreign key contraints across databases. Also the new types avoid one less level of indirection in memory on all name nodes in the syntax/execution trees. Finally, this patch proposes the following discipline: - names defined as parser.Name are not normalized with regards to case and Unicode; and thus should be normalized using NormalizeName prior to combinations; - names defined as string should be already normalized. The new method `ReNormalizeName` is introduced to highlight/denounce occurrences where a name coming from the database could be pre-normalized but isn't (see issue cockroachdb#8200). *QualifiedName is dead, hail the new Names!*
This patch introduces separate types for qualified names used in
different contexts.
This fixes various panics when invalid expressions were used;
as well as enabling foreign key contraints across databases.
Fixes #8023.
Fixes #8024.
Fixes #8044.
Fixes #8045.
This change is