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: make ParseQualifiedTableName do what it's meant to do #22577

Merged
merged 1 commit into from
Feb 12, 2018

Conversation

knz
Copy link
Contributor

@knz knz commented Feb 11, 2018

Prior to this patch, ParseQualifiedTableName() was using
ParseTableNameWithIndex and thus was overly generous in the syntax it
accepted. Worse than that, it would even silently drop the index part,
so one could e.g. compute nextval('someseq@invalidindex') without
error.

This patch corrects this oversight by ensuring the method only parses
table names.

Release note (bug fix): various primitives that expect table names as
argument now properly reject invalid table names.

@knz knz requested review from m-schneider and a team February 11, 2018 17:24
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Prior to this patch, ParseQualifiedTableName() was using
ParseTableNameWithIndex and thus was overly generous in the syntax it
accepted. Worse than that, it would even silently drop the index part,
so one could e.g. compute `nextval('someseq@invalidindex')` without
error.

This patch corrects this oversight by ensuring the method only parses
table names.

Release note (bug fix): various primitives that expect table names as
argument now properly reject invalid table names.
@m-schneider
Copy link
Contributor

pkg/sql/parser/parse.go, line 105 at r1 (raw file):

ALTER TABLE %s RENAME TO x
Slightly confused abut this, it's renaming the table passed in to x?


Comments from Reviewable

@knz
Copy link
Contributor Author

knz commented Feb 12, 2018

Review status: 0 of 3 files reviewed at latest revision, 1 unresolved discussion, all commit checks successful.


pkg/sql/parser/parse.go, line 105 at r1 (raw file):

Previously, m-schneider (Masha Schneider) wrote…

ALTER TABLE %s RENAME TO x
Slightly confused abut this, it's renaming the table passed in to x?

The idea is that we're merely parsing that statement. since the SQL language (and thus its grammar) do not support using a table name at the top level, we need a well-known grammar rule that accepts table name in its syntax, and then after parsing extract that part.

See ParseTableNameWithIndex above which does the same thing but for an index name.

Does this clarify?


Comments from Reviewable

@m-schneider
Copy link
Contributor

pkg/sql/parser/parse.go, line 105 at r1 (raw file):

Previously, knz (kena) wrote…

The idea is that we're merely parsing that statement. since the SQL language (and thus its grammar) do not support using a table name at the top level, we need a well-known grammar rule that accepts table name in its syntax, and then after parsing extract that part.

See ParseTableNameWithIndex above which does the same thing but for an index name.

Does this clarify?

Yep makes sense!


Comments from Reviewable

@m-schneider
Copy link
Contributor

:lgtm:


Review status: 0 of 3 files reviewed at latest revision, 1 unresolved discussion, some commit checks pending.


Comments from Reviewable

@knz
Copy link
Contributor Author

knz commented Feb 12, 2018

Thanks!

@knz knz merged commit 6656918 into cockroachdb:master Feb 12, 2018
@knz knz deleted the 20180211-parser-parser branch February 12, 2018 17:00
@andreimatei
Copy link
Contributor

Review status: 0 of 3 files reviewed at latest revision, 1 unresolved discussion, some commit checks failed.


pkg/sql/parser/parse.go, line 105 at r1 (raw file):

Previously, m-schneider (Masha Schneider) wrote…

Yep makes sense!

I know you've copied this from somewhere, but this obviously needed a comment :)
Do you reckon there's some different way to use the parser generated code to parse a table name more narrowly?


Comments from Reviewable

@knz
Copy link
Contributor Author

knz commented Mar 21, 2018

ALTER TABLE RENAME is the smallest syntax element that contains a table name. Every other rule involving a table name is much more complex to parse. I don't understand your concern?

@andreimatei
Copy link
Contributor

Review status: 0 of 3 files reviewed at latest revision, 1 unresolved discussion, some commit checks failed.


pkg/sql/parser/parse.go, line 105 at r1 (raw file):
Copying your answer here. Please don't reply to a code comment with a top-level comment; the discussion threads make no sense :)

ALTER TABLE RENAME is the smallest syntax element that contains a table name. Every other rule involving a table name is much more complex to parse. I don't understand your concern?

A qualified name is also a "syntax element"; perhaps not a top-level one. I'm asking if you think there's a way to ask the yacc-generated parser to parse using a smaller grammar - basically to tell it what rule we want it to use.
I don't have a particular "concern", but this code is clearly bizarre.


Comments from Reviewable

@andreimatei
Copy link
Contributor

Review status: 0 of 3 files reviewed at latest revision, 1 unresolved discussion, some commit checks failed.


pkg/sql/parser/parse.go, line 105 at r1 (raw file):

Previously, andreimatei (Andrei Matei) wrote…

Copying your answer here. Please don't reply to a code comment with a top-level comment; the discussion threads make no sense :)

ALTER TABLE RENAME is the smallest syntax element that contains a table name. Every other rule involving a table name is much more complex to parse. I don't understand your concern?

A qualified name is also a "syntax element"; perhaps not a top-level one. I'm asking if you think there's a way to ask the yacc-generated parser to parse using a smaller grammar - basically to tell it what rule we want it to use.
I don't have a particular "concern", but this code is clearly bizarre.

sent #24132 adding a small comment


Comments from Reviewable

@knz
Copy link
Contributor Author

knz commented Mar 21, 2018 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.

4 participants