Skip to content

[Bug]: Qualified sequence-backed view resolves NEXTVAL in the session database #27581

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

22b91fe

Other Environment Information

- Topology: local 1 CN / 1 TN / 1 Log
- Protocol: MySQL

Actual Behavior

When the caller's current database differs from the database that owns a sequence-backed view, an unqualified sequence name inside NEXTVAL resolves against the caller session database.

On main 22b91fe, the reproducer failed 3/3 with:

ERROR 1146 (HY000): no such table mysql.seq1

The source database and sequence both exist; the failure occurs only while evaluating the database-qualified view.

Expected Behavior

SELECT * FROM issue27049q.seq_view should resolve NEXTVAL('seq1') to issue27049q.seq1 and return 10, regardless of the caller session's current database.

Steps to Reproduce

1. Execute:

~~~sql
CREATE DATABASE issue27049q;
USE issue27049q;
CREATE SEQUENCE seq1 START WITH 10;
CREATE VIEW seq_view AS SELECT NEXTVAL('seq1') AS n;
USE mysql;
SELECT * FROM issue27049q.seq_view;
~~~

2. Observe ERROR 1146 referring to mysql.seq1.

Additional information

Validation:

This is a derived name-resolution defect, distinct from #27049 clone preservation. The clone repair is ae01f96. No matching open or closed issue was found during duplicate search.

[Hypothesis] View expression evaluation binds an unqualified NEXTVAL name to the session current database instead of the view owner database.

Regression after fixing: add BVT coverage for selecting a sequence-backed qualified view from a different default database, with the ordinary qualified-view control.

Related: #27049.

Activity

  1. added this to the MO-202608 milestone on Aug 25, 2026
  2. added theissue type on Aug 25, 2026
  3. added
    kind/bug
    on Aug 25, 2026
  4. jiangxinmeng1 commented on Sep 9, 2026

    @jiangxinmeng1
    Contributor

    fixed by #28116

  5. Ariznawlll commented on Sep 9, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:cd04bb4c1af5bc595e2147dc645dfa754f4c395b
    • 部署方式:本地单 CN/TN/Log 隔离环境
    • 测试日期:2026-09-09

    原问题验证

    创建 owner/caller 两个数据库,并在两边创建同名 seq1。owner 库 VIEW 使用未限定的 NEXTVAL、CURRVAL、SETVAL;从 caller 库访问时,3/3 均解析到 owner 库 sequence:SETVAL=50、NEXTVAL=50、CURRVAL=50、SETVAL(..., false)=70、后续 NEXTVAL=71。caller 的 sequence 保持独立序列 100/101/102。

    Happy Path 覆盖

    1. 跨库 VIEW 的 NEXTVAL、CURRVAL、两种 SETVAL 均返回预期值。
    2. 跨库普通表 VIEW 对照查询稳定返回 11。
    3. 新增 MOTR 用例连续执行 3 轮均通过(每轮 29 statements)。

    Unhappy Path 覆盖

    1. VIEW 内不存在的 missing_seq 返回 ERROR 1146;错误后 caller sequence 仍返回 102,普通表 VIEW 仍返回 11,会话未受污染。

    白盒验证

    不适用:本 issue 为 SQL 绑定/解析行为,已使用修复前父提交 74668fc075c965c462b30f10ae24a1c19c289cfd 运行新用例验证 red 状态;旧版本错误使用 caller 的同名 sequence(51/72/73),当前 main 已修复。

    回归测试

    • MOTR:PR #152
    • suites/14_issue_regression/t/issue_27581_cross_database_view_sequence.test
    • 单用例 3/3 通过;14_issue_regression 套件中该用例通过。

    测试证据

    测试结论

    测试通过。

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