sql: hint joins after the JOIN keyword, not before#35354
Conversation
This commit changes the syntax `a MERGE JOIN b` to `a JOIN @merge b`. The reason for this is that the general syntax `a b JOIN c` is also standard SQL shorthand for `a AS b JOIN c`. So a user can mistakenly enter `a MERGE JOIN b`, expecting to specify a join hint, and instead without noticing be requesting `a AS "merge" JOIN b` instead. (The observant eye may notice that the grammar did not allow a naked MERGE directly after an identifier, and instead required it to follow one of the other JOIN keywords: INNER, LEFT, RIGHT etc. However, this is a red herring: because these other JOIN keywords are optional, a user can legitimately expect them to also be optional when a hint is specified.) Release note: None
|
This PR is merely my strawman counter-proposal that both solves #35347 and also enables us to extend the syntax further with additional join flags, e.g. via the syntax (The PR is not yet complete -- I'd need to extend the logic tests -- but I'll do that after we've settled on an approach.) |
|
IMO the consistency with index hints is not a plus - |
|
Maybe What about |
|
Don't know what to say. |
|
Forgot to add: I will defer to @awoods187 if he has a strong opinion. |
|
One other piece of data: SQLS uses the |
|
ok I'd agree with supporting the MSSQL syntax for convenience but for the purpose of regularity we must document syntax that has predictable behavior, and the mssql approach does not pass that criterion. |
|
(i.e. I suggest we can implement both but only document the one that's |
|
Another datapoint - Spanner SQL uses similar syntax ( Edit: the former syntax only supports |
|
My vote is to do what spanner does. |
Note that we'd have to reserve the HASH et al keywords to support both these variants. |
|
No I disagree. Supporting both variants comes back to the initial issue -- we'd need to inform users that |
|
Ok, so when you say "do what spanner does", what exactly do you mean? Spanner supports both |
If my reading is right, then I recommend doing these 3 things and not support |
|
Oh I just see you edited that comment. I'll take my support of Spanner back then. |
|
Sorry, should have posted a separate comment. I'm not convinced that we should keep multiple variants. If we implement and plan to document only the extended one, I think we should remove the short one and avoid this potential point of confusion. |
|
My vote is to do what Spanner does and support both (eventually, since I don't think we should do anything more for this release). I think the |
|
We also know of another type of hint that Oracle and MySQL use that is a variant of C-style comment syntax: specify a hint using /* + ... */ I think we should proceed with the |
|
As discussed offline: we're keeping the current syntax. Will need documentation effort to clarify the possible ambiguity. |
Fixes #35347.
This commit changes the syntax
a MERGE JOIN btoa JOIN @MERGE b.The reason for this is that the general syntax
a b JOIN cis alsostandard SQL shorthand for
a AS b JOIN c. So a user can mistakenlyenter
a MERGE JOIN b, expecting to specify a join hint, and insteadwithout noticing be requesting
a AS "merge" JOIN binstead.(The observant eye may notice that the grammar did not allow a naked
MERGE directly after an identifier, and instead required it to follow
one of the other JOIN keywords: INNER, LEFT, RIGHT etc. However, this
is a red herring: because these other JOIN keywords are optional, a
user can legitimately expect them to also be optional when a hint is
specified.)
Release note: None