-
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/parser: Make ROLE
a non-reserved keyword
#24489
Comments
The problem is caused by the rules:
These are problematic rules because they're ambiguous. Therefore, it's impossible for the grammar to distinguish the syntax:
between parsing as the first rule and parsing as the second. That's why This all being said, we need to figure out a way to move Some options are:
|
Grammatically, I think I'd keep FWIW, we also reserve STORED, VIEW, LATERAL, NOTHING, and INDEX, while these are not reserved in postgres. |
@mberhault do you have any thoughts on this issue? |
👍 on using Regarding the other keywords, I'd propose trying to un-reserve them if possible. I recently came to the understanding that the move to reserve new keywords by default was cargo-culting previous grammar changes, not done principally, and I suspect several of the new keywords do not need to be reserved. |
May I also suggest using this discussion as renewed motive to lock down grammar changes behind an additional level of scrutiny. Last time I suggested to do so, my proposal was shot down (for some good reasons, but one bad: I was also saying we'd run into this class of problems, and nobody believed me. Now there's proof) but I'd be willing to champion such an initiative again. |
The problem with Now, we have a couple of options:
In this specific case, |
Dissenting opinion: there was no good reason to use |
WORK
a non-reserved keywordROLE
a non-reserved keyword
Then the syntax is even weirder than usual At some point, we either move the target logic into code (to determine if it's a db or table or role), we don't do role memberships, we keep role reserved, or we make |
Or we could do something like These contortions may be awkward, but they're worthwhile. Adding new reserved words breaks applications, so we should be very cautious about doing this. |
The real question IMHO is what sense does it make to call "show grants" the statement that tests "which user has which role" -- there's no idea of grant in there. (Incidentally, I think it was a mistake to treat roles as permissions and "grant" them as permissions. They are really groups and we have role membership and group-level permissions. I'm not advocating changing the other statements accordingly, but it would be good to keep this reality in mind when evaluating syntax proposals.) To me the following make sense:
|
The reason for this is that 1) roles are granted just like privileges ( That said, |
|
FWIW @benesch just explained to me an alternate idea which would un-break the code for the 2.0 release without require a change in docs. I'll try to expand his idea. |
24561: sql: introduce the LATERAL keyword and mark it as unimplemented r=knz a=knz CockroachDB aims to implement lateral joins. Until then, recognize the syntax and link the error message to the appropriate support issue. This incidentally motivates keeping the keyword "reserved" in the grammar. Release note: None Informs #24489. Refers to #24560. cc @petermattis
Folk the problem is really much worse than we thought: not only does this issue prevent new apps from working that want to use the reserved keywords as tables. It also breaks existing databases -- any existing views that refer to tables named after new reserved keywords will now generate errors.
... including verification that the addition of any new reserved keyword is accompanied by a db migration that rewrites all views. |
The idea (if I understand correctly) is to disambiguate in the action part ({...}). Both nikhil and I have separately started to work on a PoC. Stay tuned.
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
|
I'm curious to see how that will work. |
Use scanner lookahead to allow `SHOW GRANTS ON ROLE` despite `ROLE` not being a reserved keyword. The user will have to type `SHOW GRANTS ON "role"` in order to show the grants for a database named `role`. TODO: `SHOW GRANTS ON "role"` does not round-trip properly and is output as `SHOW GRANTS ON role`. Fixes cockroachdb#24489 Release note (sql change): permit ROLE to be used as an unrestricted name again.
Use scanner lookahead to allow `SHOW GRANTS ON ROLE` despite `ROLE` not being a reserved keyword. The user will have to type `SHOW GRANTS ON "role"` in order to show the grants for a database named `role`. Fixes cockroachdb#24489 Release note (sql change): permit ROLE to be used as an unrestricted name again.
Use scanner lookahead to allow `SHOW GRANTS ON ROLE` despite `ROLE` not being a reserved keyword. The user will have to type `SHOW GRANTS ON "role"` in order to show the grants for a database named `role`. Fixes cockroachdb#24489 Release note (sql change): permit ROLE to be used as an unrestricted name again.
Update: both Peter and I have a PR out to unreserve the keyword without changing the syntax (except for the very special case of SHOW GRANTS ON with a table named "role", where the table name now needs to be quoted). We might pick one of these approaches to go to 2.0.1 (to unbreak apps immediately), but then I'd like to also immediately start the process to migrate/evolve the syntax to something different, for example using the FOR keyword instead, so as to remove the code and complexity that either of our PRs is adding and reduce tech debt. |
24629: sql: make ROLE a non-reserved keyword r=knz a=knz Fixes #24489. Alternative to #24581. When support for role-based access control was added, the ROLE identifier became a reserved keyword. This breaks existing apps and databases which use the word "role" to name databases, tables or columns, which as experience shows seems to be a pretty common occurence. This change un-breaks the existing apps and databases by making the keyword non-reserved again. This change avoids redefinition of the syntax of the SHOW GRANTS ON ROLE statement, at the cost of a non-trivial, poorly maintainable and gross hack to the SQL grammar. Release note (sql change, bug fix): the word "ROLE" is not a reserved keyword any more, which (re-)enables database and apps using that name for databases, tables and columns. Co-authored-by: Raphael 'kena' Poss <knz@cockroachlabs.com>
WORK
became a reserved keyword in #20274, but it doesn't look like this is necessary. We should move it to the unreserved list to minimize disruption to applications that may have tables or columns with this name.VIRTUAL
andROLE
were also made reserved in 2.0, and we should see if we can move them too.The text was updated successfully, but these errors were encountered: