Skip to content

[Compatibility]: LAST_INSERT_ID(expr) is rejected in ODKU assignments #28163

Closed as not planned

Description

@Ariznawlll

现象

在 MatrixOne main 99ed717b769e261b842c2f17345bd65865fc1470,ODKU 中用于返回/设置自增 ID 的 MySQL 常用写法被拒绝:

INSERT INTO t(uk,v) VALUES (10,9)
ON DUPLICATE KEY UPDATE
  id = LAST_INSERT_ID(id),
  v = DEFAULT;

以及:

INSERT INTO t(uk,v) VALUES (10,99)
ON DUPLICATE KEY UPDATE
  v = LAST_INSERT_ID(v + 1);

均返回 invalid argument function last_insert_id, bad value [BIGINT]。普通 LAST_INSERT_ID() 查询可以执行,但表达式形式不能作为 ODKU assignment 的右值。

期望

支持 LAST_INSERT_ID(expr) 在 ODKU 更新表达式中的使用,以兼容通过一次 upsert 原子获取/递增行 ID 的 MySQL 应用模式。

参考:MySQL LAST_INSERT_ID()

影响

依赖 ODKU 原子返回主键或计数值的应用需要额外查询,无法保持 MySQL 的单语句语义。

复现信息

  • MatrixOne main: 99ed717b769e261b842c2f17345bd65865fc1470
  • 重复执行 3 次,结果一致

Activity

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

    @Ariznawlll
    CollaboratorAuthor

    补充范围:该缺口并不局限于 ODKU assignment。最新 main(e7bb0572235ec4bac81eb098eb0ad8900f0065ab)连独立的一参数形式也会拒绝:

    SELECT LAST_INSERT_ID(4242);
    -- MatrixOne: invalid argument function last_insert_id, bad value [BIGINT]
    
    SELECT LAST_INSERT_ID();
    -- 保持此前值不变

    MySQL 8.3 的第一条返回 4242,同时把当前会话的 LAST_INSERT_ID() 设为 4242。PreparedStatement 和 ODKU 只是这一缺失 overload 的下游使用场景;根本范围是 LAST_INSERT_ID(expr) 整体不可用。

  5. fengttt commented on Sep 13, 2026

    @fengttt
    Contributor

    It is not clear WHY we want to support this. Last_Insert_Id(expr) is an anti-feature that we should simply reject as error/not supported/invalid

  6. VioletQwQ-0 commented on Sep 15, 2026

    @VioletQwQ-0
    Collaborator

    @fengttt Agreed: we should not proceed with adding LAST_INSERT_ID(expr) solely to match MySQL. The compatibility difference is real, but this issue currently provides no concrete customer or framework dependency that justifies the expression's session-state side effects and their execution/retry/protocol maintenance cost.

    I am pausing PR #28531 and keeping it Draft. The proposed product direction is to retain rejection of the one-argument form. The existing zero-argument LAST_INSERT_ID() behavior and its correctness work remain separate.

    We can reconsider if a requirement supplies the actual application/framework and version, generated SQL, and why a transactionally correct alternative is unacceptable. A separate auto-commit UPDATE followed by SELECT is not a generally equivalent replacement for allocating a counter value.

    The implementation is retained for reference; there is no request to resume CI repair or merge preparation while this direction stands. This records a scope decision, not a successful implementation or QA result. The issue remains open pending final disposition of the compatibility requirement; any eventual not-planned closure should describe that explicitly rather than claim the feature was fixed.

  7. added and removed
    kind/bug
    on Sep 15, 2026
  8. VioletQwQ-0 commented on Sep 15, 2026

    @VioletQwQ-0
    Collaborator

    Final disposition: not planned

    Following @fengttt's recommendation, we accept retaining rejection of LAST_INSERT_ID(expr) as an intentional MySQL compatibility limitation. The reported difference is valid, but no concrete customer or framework dependency has been provided to justify the session-state side effects and their execution, retry, and protocol maintenance cost.

    This supersedes the earlier pending-decision note. Issue #28163 and PR #28531 are now closed; the proposed implementation was not merged. Closure records a decision not to add support, not a successful feature implementation or QA result.

    The scope is the one-argument form, including standalone expressions, ODKU assignments, and prepared execution. The supported zero-argument LAST_INSERT_ID() and its correctness work remain separate. No particular error code or wording change is promised by this disposition.

    We can reconsider if a concrete requirement provides the application/framework and version, actual SQL, and why a transactionally correct alternative is unacceptable. Existing implementation history remains available for reference.

  9. dengn commented on Oct 11, 2026

    @dengn
    Contributor

    Application compatibility replay on official v4.2.5

    Branch Name

    Official stable release v4.2.5; current main has not been retested for this report.

    Commit ID

    1a44f3db3056e32975fde86ca0ab69a094996a3f (SELECT git_version() returns 1a44f3d).

    Other Environment Information

    Linux x86_64 standalone official binary, 4 CPUs, ~16 GiB container memory limit. SELECT VERSION() = 8.0.30-MatrixOne-v4.2.5. PyMySQL 1.2.3 client. Only fresh owned test schemas were used for SQL probes; the native Airflow diagnostic is a read-only SELECT against the retained test fixture.

    Actual Behavior

    Native application impact: 归档序列原分配方式失败。

    ERROR 20203: invalid argument function last_insert_id, bad value [BIGINT]
    

    Expected Behavior

    Support LAST_INSERT_ID(expr), including setting and returning the connection-scoped value.

    Steps to Reproduce

    Use a dedicated fresh test schema (create one without DROP DATABASE), then run:

    SELECT LAST_INSERT_ID(1);

    Additional information

    • Native applications: Matomo.
    • This is release v4.2.5 evidence, not a claim that the same failure remains on current main.
    • Observation family MO-OBS-011. App-side workarounds do not constitute an engine fix.
    • All disclosed values are owned synthetic fixtures; no passwords, tokens, application cookies or raw private logs are attached.
  10. dengn commented on Oct 12, 2026

    @dengn
    Contributor

    Runtime recheck on current main

    Built and actually ran upstream main 02a2823c2007d5e4fb4ada148e93743df337551a, with git_version() = 02a2823, Go 1.27.1, Linux amd64, the official make build CPU entrypoint, gcc/g++, and separate fresh main cluster storage. Binary SHA-256: ce8b149f0da8c8a06ec8786c4d311795e6893420bd15be29d6e6b9cab44bb2f5. SQL checks ran 2026-10-12 06:04 UTC; upstream main was re-read before execution and still resolved to this SHA.

    Comparison: official v4.2.5 / 1a44f3db3056e32975fde86ca0ab69a094996a3f (git_version() = 1a44f3d). Both sides used fresh owned schemas and identical regression fixture hashes. This checks the disclosed reproducer; complete native application workflows have not been rerun on main. No issue is being closed automatically.

    SQL-LAST-INSERT-ID-ARG: stable known_failure → main known_failure

    The same expected error signature still reproduces on main.

    Fixture SHA-256: ce2bb1b927c579ff75f6d99643840783c248753d079f483b6cd56f8327ea6e81. A fresh SELECT 1 after the trigger succeeded: True.

    SELECT LAST_INSERT_ID(1);
    20203: invalid argument function last_insert_id, bad value [BIGINT]
    

    Detailed SQL, assertions, source/build identity and JSON evidence (organization regression repository): https://github.com/matrixorigin/matrixone-app-regression/tree/01517d2f73abb5021ca545193c2af38ef653f278/evidence/main-02a2823

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

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions