Skip to content

fix: close interval and week compatibility gaps - #24302

Merged
mergify[bot] merged 3 commits into
matrixorigin:3.0-devfrom
LeftHandCold:fix-24293-24298-24299
May 7, 2026
Merged

mergify[bot] merged 3 commits into
matrixorigin:3.0-devfrom
LeftHandCold:fix-24293-24298-24299

Conversation

@LeftHandCold

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

fixes #24293
fixes #24298
fixes #24299

What this PR does / why we need it:

This closes three related temporal compatibility gaps left after the earlier WEEK / YEARWEEK / INTERVAL fixes on 3.0-dev.

  • Make one-argument WEEK(date) / WEEK(datetime) read @@default_week_format at execution time, while keeping one-argument YEARWEEK(...) on MySQL\x27s fixed mode-0 behavior.
  • Mark the one-argument WEEK(...) overloads as session-sensitive so they are not constant-folded with the wrong session default.
  • Extend the MySQL lexer normalization so INTERVAL (expr) DAY works for DATE_ADD / DATE_SUB and date +/- INTERVAL ... forms, including nested-parenthesized expressions.
  • Harden interval binder rewrites so malformed interval arg lists return an explicit error instead of panicking.
  • Add regression coverage for the WEEK default-mode behavior, parenthesized INTERVAL operands, malformed interval arg safety, and the existing interval(ts, 10, minute) sliding(...) syntax so the lexer change does not overreach.

Validation

  • GOFLAGS=-mod=mod go test ./pkg/sql/parsers/dialect/mysql -count=1
  • GOFLAGS=-mod=mod go test ./pkg/sql/plan -run 'TestParenthesizedIntervalExpressionsBuild|TestResetDateFunctionArgsRejectsMalformedIntervalExpr' -count=1
  • GOFLAGS=-mod=mod go test ./pkg/sql/plan/function -run 'Test(DateToWeek|DateTimeToWeek|DatetimeToWeek|WeekRegisteredOverloads|YearWeek.*)' -count=1

- use @@default_week_format for one-arg WEEK at execution time
- parse parenthesized INTERVAL operands in DATE_ADD/DATE_SUB and date +/- interval forms
- reject malformed interval arg lists instead of panicking

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings May 7, 2026 07:34
@qodo-code-review

Copy link
Copy Markdown
ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes several MySQL temporal-compatibility gaps around WEEK(...) default-mode handling and INTERVAL (expr) <unit> parsing/binding behavior, including hardening against binder panics and adding regression tests.

Changes:

  • Make 1-arg WEEK(date|datetime) resolve @@default_week_format at execution time, and mark those overloads as session-sensitive (realTimeRelated) to avoid incorrect constant-folding for prepared statements.
  • Extend MySQL SQL-text normalization to support parenthesized INTERVAL (expr) UNIT operands (including nested parentheses) across DATE_ADD/DATE_SUB and date +/- INTERVAL ... forms.
  • Harden interval binder rewrites to return a user error on malformed interval lists instead of panicking, with regression coverage.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pkg/sql/plan/interval_parenthesized_expr_test.go Adds plan-level regression tests for parenthesized INTERVAL operands and malformed interval list safety.
pkg/sql/plan/function/list_builtIn.go Marks 1-arg WEEK overloads as realTimeRelated to prevent prepared-statement constant folding.
pkg/sql/plan/function/func_unary.go Implements execution-time lookup of default_week_format for 1-arg WEEK and uses mode-aware Date.Week(mode) logic.
pkg/sql/plan/function/func_unary_test.go Updates/extends WEEK unit tests to validate default-week-format behavior and the new overload flags.
pkg/sql/plan/base_binder.go Prevents panics by validating interval list structure before accessing elements; returns an explicit invalid-input error.
pkg/sql/parsers/dialect/mysql/mysql_lexer.go Broadens interval-parenthesized operand normalization from the %-only case to the full (expr) UNIT shape using interval-unit detection.
pkg/sql/parsers/dialect/mysql/interval_issue24235_test.go Extends lexer regression tests to cover INTERVAL (expr) UNIT and ensures time-window interval(ts,...) sliding(...) is unaffected.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- set @@session.default_week_format explicitly in func_datetime_extract
- update expected WEEK results for each session format

Co-authored-by: Copilot <[email protected]>

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Clean fix for three related temporal compatibility gaps.

  • WEEK(date) reading @@default_week_format at execution time via getDefaultWeekFormatMode is correct, and realTimeRelated: true properly prevents constant-folding during Prepare.
  • The lexer normalization generalization (shouldNormalizeIntervalParenthesizedOperand) correctly handles both INTERVAL (expr) DAY and INTERVAL (expr) % n DAY while leaving interval(ts, 10, minute) time-series syntax untouched.
  • getIntervalExprArgs consolidation + nil guard is a good defensive improvement.
  • Test coverage is comprehensive: unit tests for both WEEK modes, parenthesized interval plan binding, malformed interval arg rejection, and the time-series syntax non-regression.

@mergify mergify Bot added the queued label May 7, 2026
@mergify

mergify Bot commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-05-07 09:17 UTC · Rule: release-3.0
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-05-07 09:18 UTC · at 7e2575000fc6d933ad4dc7c26d55f0656cf1624d · squash

This pull request spent 39 seconds in the queue, including 3 seconds running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • branch-protection-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI (3.0) / Coverage
    • check-neutral = Matrixone Utils CI (3.0) / Coverage
    • check-skipped = Matrixone Utils CI (3.0) / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
    • check-neutral = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI (3.0) / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI (3.0) / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI (3.0) / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working kind/test-ci size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants