Skip to content

[Bug]: WEEK(date) single-argument form ignores @@default_week_format, always uses mode=1 #24293

Closed

Description

@Ariznawlll

Branch Name

main

Commit ID

59fe939(latest main)

Other Environment Information

Actual Behavior

WEEK(date) without the mode argument always returns the result corresponding to mode=1 (week starts on Monday), regardless of the value of @@default_week_format.

mysql> SELECT @@default_week_format;
-- 0

mysql> SELECT WEEK('2026-05-07');
-- MO returns: 19 (this is the mode=1 result)

mysql> SELECT WEEK('2026-05-07', 0);
-- MO returns: 18 (correct)

mysql> SELECT WEEK('2026-05-07', 1);
-- MO returns: 19 (correct)

Additionally, WEEK(date) and YEARWEEK(date) are inconsistent with each other:

mysql> SELECT WEEK('2026-05-07'), YEARWEEK('2026-05-07');
-- MO: 19, 202618
-- WEEK uses mode=1, YEARWEEK uses mode=0 — these should use the same default

Expected Behavior

Per MySQL documentation: "If the mode argument is omitted, the value of the default_week_format system variable is used."

Reference: https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_week

When @@default_week_format = 0:

SELECT WEEK('2026-05-07');
-- Should return: 18 (same as WEEK('2026-05-07', 0))

MySQL reference:

mysql> SELECT @@default_week_format;
-- 0
mysql> SELECT WEEK('2026-05-07');
-- 18

Steps to Reproduce

SELECT @@default_week_format;
-- Returns 0

SELECT WEEK('2026-05-07');
-- Returns 19 (wrong, should be 18)

SELECT WEEK('2026-05-07', 0);
-- Returns 18 (correct)

Additional information

This was discovered while verifying the fix for #24236 (WEEK two-argument form). The two-argument form is now correct for all modes 0-7. Only the single-argument form has this default mode issue.

Related: #24236, #24234

Activity

  1. added
    severity/s0
    on May 7, 2026
  2. added theissue type on May 7, 2026
  3. modified the milestones: MO-2506, MO-202605 on May 7, 2026
  4. Ariznawlll commented on May 7, 2026

    @Ariznawlll
    CollaboratorAuthor

    验证结果:已修复 ✅

    在最新代码上验证,WEEK(date) 单参数形式已正确使用 @@default_week_format:

    mysql> SELECT @@default_week_format;
    +-----------------------+
    | @@default_week_format |
    +-----------------------+
    | 0                     |
    +-----------------------+
    
    mysql> SELECT WEEK('2026-05-07');
    +--------------------+
    | week(2026-05-07)   |
    +--------------------+
    |                 18 |
    +--------------------+
    
    mysql> SELECT WEEK('2026-05-07', 0);
    +-----------------------+
    | week(2026-05-07, 0)   |
    +-----------------------+
    |                    18 |
    +-----------------------+

    WEEK('2026-05-07') 返回 18,与 WEEK('2026-05-07', 0) 一致,说明已正确使用 mode=0(default_week_format 默认值),与 MySQL 行为对齐。

  5. Ariznawlll commented on May 7, 2026

    @Ariznawlll
    CollaboratorAuthor

    验证分支/commit: 3.0-dev @ f9f1981 (fix: close interval and week compatibility gaps #24302)

    版本信息: 8.0.30-MatrixOne-v3.0

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

Metadata

Metadata

Assignees

Labels

severity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions