Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues, including open and closed issues.
This behavior was previously reported in #24293 and fixed by #24302, but the fix is no longer present on current main. Because #24293 is closed, this report tracks the current regression rather than reopening it.
Branch Name
main
Commit ID
Other Environment Information
- MatrixOne: locally built from the commit above (
8.0.30-MatrixOne-v1.3.0) - MySQL baseline: 8.0.46
- Verification date: 2026-09-10
Actual Behavior
WEEK(date) and WEEK(datetime) ignore every nonzero @@session.default_week_format value and always calculate using mode 0.
The variable accepts values 0 through 7 and reads them back correctly, and the explicit two-argument WEEK(value, mode) form produces the correct result for all eight modes. Only the one-argument form fails to consume session state.
For example:
SET SESSION default_week_format=1;
SELECT @@session.default_week_format;
-- 1
SELECT WEEK(DATE '2026-05-07'), WEEK(DATE '2026-05-07',1);
-- MatrixOne: 18, 19
-- MySQL: 19, 19
SET SESSION default_week_format=7;
SELECT WEEK(DATE '2026-01-01'), WEEK(DATE '2026-01-01',7);
-- MatrixOne: 0, 52
-- MySQL: 52, 52The same result occurs for DATE columns, DATETIME columns, literal/string input, and a prepared statement executed after changing the session variable. A prepared one-argument WEEK statement continues to return mode-0 results under modes 1, 3, and 7.
WEEKOFYEAR(date) remains equivalent to explicit mode 3 and YEARWEEK(date) retains its fixed default-mode behavior; those controls are not affected.
Expected Behavior
Per MySQL's WEEK() contract, when the mode argument is omitted, the function should use the current session's default_week_format value. Direct and prepared execution should match WEEK(value, @@session.default_week_format) for all modes 0 through 7.
Steps to Reproduce
DROP DATABASE IF EXISTS week_default_regression;
CREATE DATABASE week_default_regression;
USE week_default_regression;
CREATE TABLE t(d DATE, dt DATETIME);
INSERT INTO t VALUES
('2026-01-01','2026-01-01 12:34:56'),
('2026-05-07','2026-05-07 12:34:56');
PREPARE s FROM
'SELECT d,WEEK(d),WEEK(dt) FROM t ORDER BY d';
SET SESSION default_week_format=1;
SELECT @@session.default_week_format;
SELECT d,WEEK(d),WEEK(dt),WEEK(d,1),WEEK(dt,1)
FROM t ORDER BY d;
EXECUTE s;
SET SESSION default_week_format=3;
SELECT d,WEEK(d),WEEK(dt),WEEK(d,3),WEEK(dt,3)
FROM t ORDER BY d;
EXECUTE s;
SET SESSION default_week_format=7;
SELECT d,WEEK(d),WEEK(dt),WEEK(d,7),WEEK(dt,7)
FROM t ORDER BY d;
EXECUTE s;
DEALLOCATE PREPARE s;Additional information
The original fix in #24302 added a getDefaultWeekFormatMode(proc) lookup through Process.GetResolveVariableFunc() and marked the one-argument overload as session-sensitive. Current pkg/sql/plan/function/func_unary.go no longer contains that lookup: DateToWeek and DatetimeToWeek initialize mode := 0 and change it only when a second argument exists. The current WEEK overload registration also has no session-sensitive flag.
Modes 0 through 7, five year/week boundary dates, DATE/DATETIME/literal paths, explicit-mode controls, WEEKOFYEAR/YEARWEEK controls, and prepared execution after session changes were reproduced three times on the same latest-main build. MySQL 8.0.46 changes the one-argument result with every applicable default_week_format mode.
Activity
XuPeng-SH commentedon Sep 10, 2026
Triage routing: assigned to @jiangxinmeng1. Labels normalized to
kind/bug+needs-triage(existing compatibility labels, when present, are retained).Recommended PR decomposition:
#28574 + #28596): fix per-row mode handling and sessiondefault_week_formatpropagation forWEEK/YEARWEEK. They share the WEEK executor/configuration path.#28572/#28573separate because EXTRACT has a different return-type and mode contract.Suggested priority: P1 for
#28574because a batch can return wrong values for most rows; P2 for#28596.fix: align date compatibility semantics (#28851)
XuPeng-SH commentedon Sep 27, 2026
QA handoff after merged PR #28851 (merge
a99db843c7b4630a86883addc9424433d93fc2d2). This issue was a non-closing related report; the merge and shared BVT counts are not an independent PASS for this reproducer.Latest MatrixOne contract: C25, C38 in the merged temporal design. One-argument WEEK must read default_week_format at each EXECUTE, including a reused prepared handle; explicit WEEK(date, mode) stays independent of the session default. YEARWEEK(date) uses mode 0.
Please rerun the original reproducer on
mainat or after the merge and record the exact SHA, deployment, SQL mode/time zone, client path, observed rows/types/NULLs and active warnings or errors. Switch the session value between executions, compare explicit modes, and verify year-boundary dates.Keep the issue open until the issue-specific acceptance is demonstrated with happy and unhappy controls. If any part still fails, post the exact observed-versus-expected result and return it to development; if it passes, record evidence and close the issue. @Ariznawlll
Ariznawlll commentedon Oct 2, 2026
测试版本
maind50a2d475a406829f67127fef7b2ad4abc1c1d3dmo-service,独立数据目录;MySQL 文本协议与 server-side PREPARE原问题验证
按 issue 原始语义在上述 commit 重新执行并重复 3 次。default_week_format=1/3/7 在 direct 与 prepared WEEK 调用中均生效。
Happy Path 覆盖
覆盖三个 session mode、显式 mode 与默认 mode 的对照。
Unhappy Path 覆盖
覆盖切换 session 变量后的 statement 重用、NULL 日期;无旧配置残留。
白盒验证
关联修复 #28851、#29076 已进入当前
main。同时将本 issue 的可公开观察契约固化为独立回归,避免只依赖实现细节或共享测试间接判断。回归测试
suites/14_issue_regression/t/issue_recent_temporal_contracts.test714/714条语句通过。测试证据
d50a2d475a406829f67127fef7b2ad4abc1c1d3d14_issue_regression中观察到的旧 GOROOT/历史 golden/并发锁冲突属于既有无关失败,以上新增用例单独重跑均稳定通过。测试结论
测试通过。
fix(frontend): retain DATETIME fractional width in text rows (#29076)