← Back to Pull requests

parser: support parenthesized temporal interval expressions #70525

Closed
unknown closed this pull request without merging on Aug 18, 2026 15:50 UTC
View on GitHub
unknown unknown commented on Aug 18, 2026 04:13 UTC
Author

<!--

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_unit as a scalar INTERVAL()
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?

  • Give the scalar INTERVAL(value, boundary[, ...]) function dedicated

  • grammar productions that require at least two arguments.
  • Keep a single parenthesized expression available to temporal

  • INTERVAL expression time_unit grammar.
  • Resolve the scalar-function versus anonymous-row comma ambiguity explicitly

  • by assigning the base ExpressionList reduction lower precedence than
    the comma token.
  • Add parser regressions for the reported query, the full quarterly-usage

  • query, temporal addition and subtraction, scalar INTERVAL arithmetic,
    invalid scalar arities, and nested row expressions.

    Check List

    Tests <!-- At least one of them must be included. -->

  • Unit test

  • - 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
  • Integration test

  • Manual test (add detailed scripts or steps below)

  • No need to test

  • > - [ ] I checked and no code files have been changed.
    > <!-- Or your custom "No need to test" reasons -->

    Side effects

  • Performance regression: Consumes more CPU

  • Performance regression: Consumes more Memory

  • Breaking backward compatibility
  • Documentation

  • Affects user behaviors

  • Contains syntax changes

  • Contains variable changes

  • Contains experimental features

  • Changes MySQL compatibility
  • 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-note
    Fix an issue where parenthesized temporal interval expressions such as
    date_value + INTERVAL (expression) QUARTER fail to parse correctly.
    `

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    Summary by CodeRabbit

  • Bug Fixes

  • - Improved SQL parsing for
    INTERVAL expressions in date arithmetic and nested expressions.
    - Resolved ambiguity between scalar interval calls and row or tuple expressions.
    - Added support for valid two-argument and variadic
    INTERVAL function forms.
    - Improved validation of invalid
    INTERVAL` argument counts.
    - Enhanced support for quarterly interval calculations and different operand orders.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 416 lines (+312 / -104) across 5 files Reviewer: kennytm Review duration: 696m
    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
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.0% (MEDIUM) · Higher = larger blast radius
    45.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.4% · Safe to merge
    19.4%
    Repository