Skip to content

[Bug]: ORDER BY NULLS FIRST/LAST syntax is accepted but MySQL rejects it #25332

Closed

Description

@Ariznawlll

Branch

main at 200bfa7e0efb.

Summary

MySQL does not accept ORDER BY ... NULLS FIRST/LAST syntax. MatrixOne accepts and executes it. This creates a MySQL compatibility gap for syntax that should be rejected by a MySQL-compatible parser.

Reproduction

drop database if exists mysql_compat_module9_nulls_syntax;
create database mysql_compat_module9_nulls_syntax;
use mysql_compat_module9_nulls_syntax;

create table t(id int, score int);
insert into t values
  (1,20),
  (2,null),
  (3,10),
  (4,30),
  (5,null);

select id, score from t order by score asc nulls last, id;
select id, score from t order by score desc nulls first, id;

MySQL result

ERROR 1064 (42000): You have an error in your SQL syntax ... near 'nulls last, id'
ERROR 1064 (42000): You have an error in your SQL syntax ... near 'nulls first, id'

MatrixOne result

+------+-------+
| id   | score |
+------+-------+
|    3 |    10 |
|    1 |    20 |
|    4 |    30 |
|    2 |  NULL |
|    5 |  NULL |
+------+-------+

+------+-------+
| id   | score |
+------+-------+
|    2 |  NULL |
|    5 |  NULL |
|    4 |    30 |
|    1 |    20 |
|    3 |    10 |
+------+-------+

Expected behavior

For MySQL compatibility, MatrixOne should reject NULLS FIRST/LAST syntax unless this extension is intentionally allowed outside MySQL-compatible mode.

Activity

  1. added
    kind/bug
    severity/s1
    on Jul 1, 2026
  2. added
    severity/s0
    and removed
    severity/s1
    on Jul 2, 2026
  3. added this to the MO-202607 milestone on Jul 2, 2026
  4. added theissue type on Jul 2, 2026
  5. added and removed
    severity/s0
    on Jul 2, 2026
  6. jiangxinmeng1 commented on Jul 29, 2026

    @jiangxinmeng1
    Contributor

    fixed by #25236

  7. added
    ai-easy
    on Jul 29, 2026
  8. Ariznawlll commented on Jul 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main(截至 2026-07-30 16:30,Asia/Shanghai)
    • commit:41332062a6740978f269088a92ee362a888c7bd7
    • 部署方式:从该官方 commit 源码构建;etc/launch-with-proxy/launch.toml(2 CN + 1 TN + Proxy),SQL 入口 127.0.0.1:6001
    • 测试日期:2026-07-30

    原问题验证

    顶层 ORDER BY 的 ASC NULLS LAST、DESC NULLS FIRST 均返回明确的 MySQL syntax not supported 错误;完整黑盒 3/3 通过。

    Happy Path 覆盖

    1. 不带 NULLS FIRST/LAST 的普通 ORDER BY score ASC,id 正常执行,NULL 排序结果稳定。

    Unhappy Path 覆盖

    1. 顶层 ASC NULLS LAST 被拒绝。
    2. 顶层 DESC NULLS FIRST 被拒绝。
    3. window ORDER BY score NULLS LAST 同样被拒绝;错误后会话继续可用。

    白盒验证

    TestOrderByRejectsNullsPosition 连续 3 轮通过。

    回归测试

    修复提交 2477628c4(#26236)已更新 order_by_with_nulls.sql、window BVT 和 parser 测试。

    测试证据

    完整 3 轮 SQL 结果、测试脚本、Proxy 黑盒日志、定向 UT 与 -race 输出:https://gist.github.com/Ariznawlll/b8f1a22642a58fd5264482687534728b

    测试结论

    测试通过。

  9. Ariznawlll commented on Jul 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    motr 黑盒回归已补充

    • PR:matrixorigin/motr#72
    • 用例:suites/14_issue_regression/t/issue_25332_nulls_order_rejection.test
    • 覆盖:普通和窗口 ORDER BY 的 NULLS FIRST/LAST 均按 MySQL 语法拒绝,普通排序正常
    • 本地验证:基于 MatrixOne main@41332062a6740978f269088a92ee362a888c7bd7,该批 14 个用例连续 3 轮为 42/42 成功(504/504 语句);完整 14_issue_regression suite 为 124 成功、0 失败。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-easykind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions