Skip to content

[Bug]: sequence functions cannot access identifiers containing backticks #28245

Closed

Description

@Ariznawlll

问题描述

MatrixOne 可以创建名称中包含反引号的 sequence,但 NEXTVAL 和 SETVAL 无法使用该合法对象。sequence 函数把数据库名和对象名直接插入反引号包围的内部 SQL,没有把标识符中的反引号转义为双反引号,因而内部 SELECT/UPDATE 解析失败。

对象本身存在且 SHOW CREATE TABLE 可正常访问,因此问题不在 sequence DDL 或关系解析,而在 sequence 函数的内部 SQL 构造。

环境

  • MatrixOne latest main
  • commit: e7bb0572235ec4bac81eb098eb0ad8900f0065ab

复现

create database seq_identifier_escape;
use seq_identifier_escape;

create sequence `s``q` increment by 2 start with 7 no cycle;
show create table `s``q`;

select nextval('s`q');
select setval('s`q',21,true);

当前行为

SHOW CREATE TABLE 返回对象 s\q 的完整 sequence 内部定义;NEXTVAL和SETVAL` 均返回内部 SQL 语法错误:

You have an error in your SQL syntax ... near "`"

期望行为

合法创建的 sequence 应能通过 sequence 函数访问。构造内部 SQL 时应使用统一的标识符 quoting helper,至少把对象名和数据库名中的反引号正确转义,不能直接用 fmt.Sprintf("... %s ...") 拼接。

代码线索

pkg/sql/plan/function/seqfunc.go 中 nextval、setSeq、setval 和 setVal 的内部 SELECT/UPDATE 都直接将 db、tblname 放进反引号。

Activity

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

    @XuPeng-SH
    Contributor

    The production fix for the reported sequence-name quoting failure is already present in main through merged PR #28345 (sequenceTableName doubles embedded backticks, and all sequence metadata SELECT/UPDATE paths use it). The existing helper unit test also asserts the encoded form.

    I added PR #28780 as a test-only follow-up: #28780. Its distributed BVT creates a sequence whose legal decoded name contains a backtick, then verifies public NEXTVAL and SETVAL return 7, 21, and 23. No production code changes are included.

    Scope clarification: current frontend validation rejects backticks in database names, and the extra database arguments are internal to view expansion rather than public SQL. Those are not valid user-facing test cases; database-component quoting remains covered by the helper-level unit test.

    Validation: GPT-6 Astra medium final source review passed; formatting/diff and staged SQL/result alignment checks passed. Local distributed BVT was not run because unrelated MatrixOne services are active. At the initial PR status, CI preflight passed, but Matrixone CI execution and UT Coverage execution were skipped; therefore the new BVT has not yet been verified on the submitted head. Please keep this issue open until the exact-head BVT result is available.

  6. added a commit that references this issue on Sep 12, 2026
    6875e42
  7. Ariznawlll commented on Sep 14, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:07b25969bfea9d4b76d3bf05d5b0497e4f36eba0
    • 部署:本地独立 1 CN / 1 TN / 1 LogService;每轮均重新启动服务后执行。
    • 执行:每项 SQL 回归连续 3 轮,输出逐轮一致。

    原问题验证

    • 序列函数可访问包含反引号的标识符。

    Happy Path 覆盖

    • 覆盖带反引号的 sequence NEXTVAL/SETVAL/NEXTVAL,结果为 7/21/23。

    Unhappy Path 覆盖

    • 覆盖包含特殊标识符边界,解析和对象解析均不误拆分。

    白盒验证

    • 以 MOTR 固定 quoted identifier sequence 回归。

    回归测试

    测试证据

    • 以上结果均在该 main commit 的独立环境获得;每轮无 stderr,三轮结果一致。

    测试结论

    测试通过。

  8. added 3 commits that reference this issue on Sep 17, 2026
    dbb6869
    7d8d3d8
    03129c6
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