parser: support parenthesized temporal interval expressions #70525
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.45) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 416 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.361
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #70525"
general
weight: 0.35
kennytm
<!--
Thank you for contributing to TiDB!
PR Title Format:
1. pkg [, pkg2, pkg3]: what's changed
2. *: what's changed
-->
What problem does this PR solve?
<!--
Please create an issue first to describe the problem.
There MUST be one line starting with "Issue Number: " and
linking the relevant issues via the "close" or "ref".
For more info, check https://pingcap.github.io/tidb-dev-guide/contribute-to-tidb/contribute-code.html#referring-to-an-issue.
-->
Issue Number: close #46476
Problem Summary:
TiDB can interpret the parenthesized expression in
date_value + INTERVAL (expression) time_unitas a scalarINTERVAL()call. The time unit can then be treated as an implicit alias, causing an
explicit alias to fail with a syntax error and allowing aliasless statements
to produce the wrong AST.
What changed and how does it work?
INTERVAL(value, boundary[, ...])function dedicatedgrammar productions that require at least two arguments.
INTERVAL expression time_unitgrammar.by assigning the base
ExpressionListreduction lower precedence thanthe comma token.
query, temporal addition and subtraction, scalar
INTERVALarithmetic,invalid scalar arities, and nested row expressions.
Check List
Tests <!-- At least one of them must be included. -->
-
make parser-
make parser_yacc-
make parser_fmt-
make parser_unit_test-
./tools/check/failpoint-go-test.sh pkg/parser -run '^TestBuiltin$' -count=1-
make lint> - [ ] I checked and no code files have been changed.
> <!-- Or your custom "No need to test" reasons -->
Side effects
Documentation
Release note
<!-- compatibility change, improvement, bugfix, and new feature need a release note -->
Please refer to Release Notes Language Style Guide to write a quality release note.
``
release-notedate_value + INTERVAL (expression) QUARTERFix an issue where parenthesized temporal interval expressions such as
fail to parse correctly.
`<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
Summary by CodeRabbit
- Improved SQL parsing for INTERVAL
expressions in date arithmetic and nested expressions.INTERVAL- Resolved ambiguity between scalar interval calls and row or tuple expressions.
- Added support for valid two-argument and variadic
function forms.INTERVAL` argument counts.- Improved validation of invalid
- Enhanced support for quarterly interval calculations and different operand orders.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->