Skip to content

[Bug]: WEEK and YEARWEEK reuse the first row mode for the entire batch #28574

Closed

Description

@Ariznawlll

现象

MatrixOne main(ac660ae56ecd37bab3dd8c61193617a323377029)的 WEEK(date, mode) 和 YEARWEEK(date, mode) 在 mode 来自列或行相关表达式时,只读取结果批次第一行的 mode,并将该 mode 用于所有行。

CREATE TABLE src(id INT PRIMARY KEY, d DATE, mode_value INT);
INSERT INTO src VALUES
  (1,'2024-01-01',0),
  (2,'2024-01-01',1),
  (3,'2024-01-01',2),
  (4,'2024-01-01',3),
  (5,'2024-12-31',0),
  (6,'2024-12-31',3);

SELECT id, mode_value, WEEK(d,mode_value), YEARWEEK(d,mode_value)
FROM src ORDER BY id;

MatrixOne:

1 0   0  202353
2 1   0  202353
3 2   0  202353
4 3   0  202353
5 0  52  202452
6 3  52  202452

MySQL 8.0.46:

1 0   0  202353
2 1   1  202401
3 2  53  202353
4 3   1  202401
5 0  52  202452
6 3   1  202501

将 mode 改成依赖 id 的 CASE 表达式也会复现;DATE 与 DATETIME 重载均受影响。分别使用常量 mode 0/3 的控制查询在两端一致。

期望

mode 是逐行表达式,应为每行读取和归一化对应值;不能将第一行的 mode 广播到整个结果批次。

代码定位

  • pkg/sql/plan/function/func_unary.go 的 DateToWeek 和 DatetimeToWeek 在循环之前通过 vector.MustFixedColWithTypeCheck[int64](ivecs[1])[0] 读取一次 mode。
  • pkg/sql/plan/function/func_binary.go 的 YearWeekDate、YearWeekDatetime、YearWeekTimestamp、YearWeekString 使用同样的 [0] 读取方式。

这些函数没有要求 mode 必须是常量,因此列向量会被静默当作标量处理。

复现信息

  • MatrixOne main:ac660ae56ecd37bab3dd8c61193617a323377029
  • MySQL:8.0.46
  • 列、CASE、DATE、DATETIME 和常量控制组重复执行 3 次,结果一致

Activity

  1. added this to the MO-202609 milestone on Sep 10, 2026
  2. added
    kind/bug
    on Sep 10, 2026
  3. added theissue type on Sep 10, 2026
  4. XuPeng-SH commented on Sep 10, 2026

    @XuPeng-SH
    Contributor

    Triage routing: assigned to @jiangxinmeng1. Labels normalized to kind/bug + needs-triage (existing compatibility labels, when present, are retained).

    Recommended PR decomposition:

    • PR-T6 — WEEK mode evaluation (#28574 + #28596): fix per-row mode handling and session default_week_format propagation for WEEK/YEARWEEK. They share the WEEK executor/configuration path.
    • Keep #28572/#28573 separate because EXTRACT has a different return-type and mode contract.

    Suggested priority: P1 for #28574 because a batch can return wrong values for most rows; P2 for #28596.

  5. XuPeng-SH commented on Sep 27, 2026

    @XuPeng-SH
    Contributor

    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 in the merged temporal design. WEEK(date, mode) and YEARWEEK(date, mode) must use each row’s mode (normalized modulo 8; NULL mode means 0), not the first row’s mode for the batch.

    Please rerun the original reproducer on main at 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. Run mixed-mode batches in both row orders and compare each row with a literal-mode control.

    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

  6. Ariznawlll commented on Oct 2, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • Commit:d50a2d475a406829f67127fef7b2ad4abc1c1d3d
    • 部署方式:本地全新单 CN mo-service,独立数据目录;MySQL 文本协议与 server-side PREPARE
    • 测试日期:2026-10-02

    原问题验证

    按 issue 原始语义在上述 commit 重新执行并重复 3 次。WEEK/DATE_FORMAT 等 mode 参数按每行求值,不再把第一行 mode 缓存给整批。

    Happy Path 覆盖

    覆盖同一批次多 mode、多日期和 prepared 重绑。

    Unhappy Path 覆盖

    覆盖非法 mode、NULL mode/date;只影响对应行,后续重绑结果正确。

    白盒验证

    关联修复 #28851 已进入当前 main。同时将本 issue 的可公开观察契约固化为独立回归,避免只依赖实现细节或共享测试间接判断。

    回归测试

    测试证据

    • 精确测试版本:d50a2d475a406829f67127fef7b2ad4abc1c1d3d
    • 当前结果:WEEK/DATE_FORMAT 等 mode 参数按每行求值,不再把第一行 mode 缓存给整批。
    • 回归代码与 golden result 已提交到 MOTR #209;本地全量 14_issue_regression 中观察到的旧 GOROOT/历史 golden/并发锁冲突属于既有无关失败,以上新增用例单独重跑均稳定通过。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions