Skip to content

[Compatibility]: EXTRACT(WEEK) uses a different week mode from MySQL and WEEK(,0) #28573

Closed

Description

@Ariznawlll

现象

MatrixOne main(ac660ae56ecd37bab3dd8c61193617a323377029)的 EXTRACT(WEEK FROM temporal) 使用 ISO 风格的周编号,而 MySQL 8.0.46 的该表达式与 WEEK(temporal, 0) 一致。

SELECT EXTRACT(WEEK FROM CAST('2000-01-01' AS DATE)),
       WEEK(CAST('2000-01-01' AS DATE), 0);
SELECT EXTRACT(WEEK FROM CAST('2024-02-29' AS DATE)),
       WEEK(CAST('2024-02-29' AS DATE), 0);
SELECT EXTRACT(WEEK FROM CAST('2024-12-31' AS DATE)),
       WEEK(CAST('2024-12-31' AS DATE), 0);
date         MatrixOne EXTRACT/WEEK(,0)   MySQL EXTRACT/WEEK(,0)
2000-01-01   52 / 0                       0 / 0
2024-02-29    9 / 8                       8 / 8
2024-12-31    1 / 52                     52 / 52

同样的值差异出现在 DATETIME 和 TIMESTAMP 列;2005-01-01、2024-01-01、2025-01-01 等年界日期也稳定复现。

期望

EXTRACT(WEEK FROM value) 应与 MySQL 一致采用默认 week mode 0,并与同一引擎中的 WEEK(value, 0) 返回相同周号。

代码定位

pkg/sql/plan/function/func_binary.go 中 DATE 重载 ExtractFromDate 和 DATETIME/TIMESTAMP 辅助路径都调用 WeekOfYear2();而 WEEK(value,0) 使用 Date.Week(0)。两条路径采用不同算法,导致 EXTRACT(WEEK) 在年界和普通日期均偏离默认周模式。

复现信息

  • MatrixOne main:ac660ae56ecd37bab3dd8c61193617a323377029
  • MySQL:8.0.46
  • DATE、DATETIME、TIMESTAMP 三类输入和 6 个边界日期重复执行 3 次,结果一致

Activity

  1. added this to the MO-202609 milestone on Sep 10, 2026
  2. added theissue type on Sep 10, 2026
  3. 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-T5 — EXTRACT semantics (#28572 + #28573): align numeric result types and the EXTRACT(WEEK) default mode with MySQL. They are the same EXTRACT family contract and should share type/semantic regression coverage.
    • Keep #28574/#28596 separate: those concern row-dependent WEEK/YEARWEEK mode evaluation and session default_week_format, not EXTRACT result typing.

    Suggested priority: P1 for #28572 due wrong type and downstream arithmetic/order behavior; P2 for #28573.

  4. 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: C16, C25 in the merged temporal design. Newly bound EXTRACT(WEEK FROM x) is signed BIGINT and equals WEEK(x, 0), regardless of default_week_format.

    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. Verify the original year-boundary dates, alternate session defaults, and text plus real prepared metadata.

    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

  5. Ariznawlll commented on Oct 2, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

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

    原问题验证

    按 issue 原始语义在上述 commit 重新执行并重复 3 次。EXTRACT(WEEK FROM d) 与 WEEK(d,0) 对测试日期集合一致。

    Happy Path 覆盖

    覆盖年初/年末、周日/周一边界和闰年日期。

    Unhappy Path 覆盖

    覆盖 zero/invalid/NULL 日期;返回受控值或 NULL,无模式漂移。

    白盒验证

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

    回归测试

    测试证据

    • 精确测试版本:d50a2d475a406829f67127fef7b2ad4abc1c1d3d
    • 当前结果:EXTRACT(WEEK FROM d) 与 WEEK(d,0) 对测试日期集合一致。
    • 回归代码与 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

area/compatibilitykind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions