sql,ccl: improve the implementation of the TENANT clauses in sql syntax#77218
sql,ccl: improve the implementation of the TENANT clauses in sql syntax#77218craig[bot] merged 4 commits intocockroachdb:masterfrom
Conversation
|
I'm not super well-versed in the backup code, but it looks to me that making this support more complex expressions is actually not too hard. Might be more elegant! |
rafiss
left a comment
There was a problem hiding this comment.
i think this change is still an improvement, so i vote to merge this
does it need to change to account for the cluster setting syntax that just merged?
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @ajstorm, @knz, and @stevendanna)
pkg/sql/sem/tree/tenant.go, line 28 at r1 (raw file):
// the case when the value was anonymized. In other places, the // value used for anonymized integer literals is 0, but we can't use // 0 for TenantID as this is refused during parsing, nor can we use
do we have a good reason for rejecting 0 at the parsing step rather than rejecting it during semantic analysis?
knz
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @ajstorm, @rafiss, and @stevendanna)
pkg/sql/sem/tree/tenant.go, line 28 at r1 (raw file):
Previously, rafiss (Rafi Shamim) wrote…
do we have a good reason for rejecting 0 at the parsing step rather than rejecting it during semantic analysis?
IMHO, no, but as long as the tree object embeds a roachpb.TenantID, it's going to be checked in roachpb.MakeTenantID.
My preference would be for this to use an Expr, and have the translation Expr -> TenantID done at planning time (with expr eval).
This ensures that the tenant ID is subject to formatting flags. This commit is sadly much larger than it deserves to be, due to a unique combination of factors: - the TENANT clause is one of the extremely few other clauses that specify anonymizable integer literals, and do not (currently) support arbitrary expressions. (The other clauses are the SEQUENCE caching options.) Due to this special case, we cannot rely on the existing machinery in `fmtHideConstants()` and need to handle the anonymization in the TenantID's Format method directly. - the TENANT clause is the only clause where the default value is not parseable: the value 0 causes a syntax error at parse-time, not at plan-time like other clauses that accept numeric arguments. This makes it impossible to use the value 0 as anonymized value. Due to this special case, we need to add a new parsing rule for the anonymized value of the TENANT clause alongside the main rule. This complexity would not be needed if the value 0 could be parsed and the validation delayed to plan-time. We could also remove it if the TENANT clause properly accepted expressions. Release justification: bug fix Release note: None
knz
left a comment
There was a problem hiding this comment.
does it need to change to account for the cluster setting syntax that just merged?
Oh good catch. That's a different situation though. This can be made to support expressions right away. Actually, the way this syntax was implemented... 🤦♂️ Good time to clean it up. Done.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @ajstorm, @rafiss, and @stevendanna)
|
bors r=rafiss |
|
Build failed: |
|
Just noticed SHOW CLUSTER SETTING FOR TENANT was affected too. Fixing that as well. |
e703cd6 to
478021e
Compare
|
bors r=rafiss |
|
Build failed: |
4489163 to
9888484
Compare
Release justification: low risk, high benefit changes to existing functionality Release note: None
Release justification: low risk, high benefit changes to existing functionality Release note: None
|
bors r=rafiss |
|
Build failed: |
|
This is failing in CI in the backupccl package, seemingly for unrelated reasons? Unsure. Will need to look next week. |
Release justification: non-production code changes Release note: None
|
added a skip bors r=rafiss |
|
Build succeeded: |
|
I noticed this changed the syntax to I guess it's not a big deal, but |
|
yes I changed this to avoid a syntax ambiguity (
AFAIK |
|
The alternative was |
|
Can't we use a lookahead, like we do for cockroach/pkg/sql/parser/lexer.go Lines 123 to 131 in fc7b49f I bring this up since the syntax was discussed at length in the RFC discussion, so I'd prefer to have this match where the consensus landed. |
|
I was not aware of this lookahead technique (or, I had forgotten it) |
|
(regardless of the RFC, SQL is meant to be "readable english", and I find "TENANT ALL" less grammatical and less readable than "ALL TENANTS") |
|
Sure, I don't mind making that PR. Just wanted to understand the context before I did. |
This ensures that the tenant ID is subject to formatting flags.
Release justification: bug fix
Release note: None