Repository navigation
fix: close interval and week compatibility gaps - #24302
Merged
mergify[bot] merged 3 commits intoMay 7, 2026
Merged
Conversation
- 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]>
LeftHandCold
requested review from
aunjgr,
iamlinjunhong and
ouyuanning
as code owners
May 7, 2026 07:34
ⓘ 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. |
There was a problem hiding this comment.
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_formatat 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) UNIToperands (including nested parentheses) acrossDATE_ADD/DATE_SUBanddate +/- 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]>
iamlinjunhong
approved these changes
May 7, 2026
ouyuanning
approved these changes
May 7, 2026
ghost
approved these changes
May 7, 2026
XuPeng-SH
approved these changes
May 7, 2026
XuPeng-SH
left a comment
Contributor
There was a problem hiding this comment.
LGTM. Clean fix for three related temporal compatibility gaps.
- WEEK(date) reading @@default_week_format at execution time via
getDefaultWeekFormatModeis correct, andrealTimeRelated: trueproperly prevents constant-folding during Prepare. - The lexer normalization generalization (
shouldNormalizeIntervalParenthesizedOperand) correctly handles bothINTERVAL (expr) DAYandINTERVAL (expr) % n DAYwhile leavinginterval(ts, 10, minute)time-series syntax untouched. getIntervalExprArgsconsolidation + 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.
aunjgr
approved these changes
May 7, 2026
Contributor
Merge Queue Status
This pull request spent 39 seconds in the queue, including 3 seconds running CI. Required conditions to merge
|
This was referenced May 7, 2026
Closed
1 task done
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
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/INTERVALfixes on3.0-dev.WEEK(date)/WEEK(datetime)read@@default_week_formatat execution time, while keeping one-argumentYEARWEEK(...)on MySQL\x27s fixed mode-0 behavior.WEEK(...)overloads as session-sensitive so they are not constant-folded with the wrong session default.INTERVAL (expr) DAYworks forDATE_ADD/DATE_SUBanddate +/- INTERVAL ...forms, including nested-parenthesized expressions.WEEKdefault-mode behavior, parenthesizedINTERVALoperands, malformed interval arg safety, and the existinginterval(ts, 10, minute) sliding(...)syntax so the lexer change does not overreach.Validation
GOFLAGS=-mod=mod go test ./pkg/sql/parsers/dialect/mysql -count=1GOFLAGS=-mod=mod go test ./pkg/sql/plan -run 'TestParenthesizedIntervalExpressionsBuild|TestResetDateFunctionArgsRejectsMalformedIntervalExpr' -count=1GOFLAGS=-mod=mod go test ./pkg/sql/plan/function -run 'Test(DateToWeek|DateTimeToWeek|DatetimeToWeek|WeekRegisteredOverloads|YearWeek.*)' -count=1