Skip to content

[Bug]: user variable assigned from a TIMESTAMP scalar subquery disappears in the same session #27054

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

eee0ae0

Other Environment Information

  • Deployment: GitHub Actions regression environment
  • Client: MOTR/PyMySQL, one persistent connection for the complete test case
  • Test date: 2026-08-12

Actual Behavior

A user-defined variable assigned from a TIMESTAMP scalar subquery disappears before a later statement on the same connection.

The assignment itself succeeds, but both later reads fail:

ERROR 20101: internal error: the user variable ts0 does not exist

The MOTR case reported stmts=101 ok=99 fail=2. The only failed statements were the two later reads of @ts0; the preceding SET @ts0 = (...) was counted as successful.

Expected Behavior

After a successful SET @ts0 = (...), @ts0 must remain available for subsequent statements on the same session until it is overwritten, explicitly cleared, or the connection is closed.

The equality check should return 1, and the later update check should return 99, 1.

Steps to Reproduce

drop database if exists repro_user_var_timestamp;
create database repro_user_var_timestamp;
use repro_user_var_timestamp;

create table r9(
  id int primary key,
  v int,
  updated_at timestamp default current_timestamp on update current_timestamp
);

insert into r9(id, v) values (1, 10);
set @ts0 = (select updated_at from r9 where id = 1);

-- Wait two seconds on the client without reconnecting.

insert into r9(id, v) values (1, 10)
  on duplicate key update v = v;
select updated_at = @ts0 as ts_unchanged from r9 where id = 1;

insert into r9(id, v) values (1, 99)
  on duplicate key update v = values(v);
select v, updated_at > @ts0 as ts_advanced from r9 where id = 1;

Additional information

Stability and control

  • Bad commit eee0ae09ede93072615315a6fe24469550b5be9a: the case failed with 99/101 statements passing.
  • Control commit fe62a8fd83d29b829070f9bf8ea21b2332e8a35a: the exact case passed with 101/101 statements.
  • MOTR commits fa50a88c70e7d4cc592552a8e5d127b7e90f1537 and 25ef8a4c96ce517113ec22cf12d863f1f13ded3f have identical trees.
  • Both runs used main and the same MOTR command.
  • MOTR's --sleep 2 only sleeps and does not reconnect. Its NamedConn reuses the same PyMySQL connection for all statements in this case.

Evidence

Related

Activity

  1. added this to the MO-202608 milestone on Aug 12, 2026
  2. added
    kind/bug
    on Aug 12, 2026
  3. added theissue type on Aug 12, 2026
  4. VioletQwQ-0 commented on Aug 14, 2026

    @VioletQwQ-0
    Collaborator

    Triage result: severity/s1. A deterministic current-main regression now confirms that connection migration does not export evaluated user-defined variables. The defect is topology-dependent (multi-CN through Proxy) and can produce stable session-state loss, while isolated single-CN controls pass. There is currently no evidence of persistent data corruption, cross-tenant impact, or a broad customer/POC outage, so s0 is not justified. Escalate if such evidence appears.

  5. added
    severity/s1
    and removed on Aug 14, 2026
  6. VioletQwQ-0 commented on Aug 19, 2026

    @VioletQwQ-0
    Collaborator

    PR #27180 已合并,关联 issue 仍需 QA 验证,暂不关闭。

    • PR exact head:a012f5d6973dcc58e73ac445871814b43353fe78
    • merge commit / 当前 main:6f42b19508f31ef04ae2857172893f13d48afddf
    • 自动化证据:前端、代理及 query protobuf 包测试通过;UT、SCA、coverage、Compose Proxy BVT、Standalone 多 CN PESSIMISTIC BVT 和 shared build 通过。TKE 测试环境 setup 仍是 pending,不作为 QA PASS。
    • BVT:N/A。普通 BVT 无法确定性触发 Proxy 后端迁移;本次生产入口和回归覆盖了 typed user-variable snapshot/restore、TIMESTAMP scalar-subquery 状态保持、PREPARE/事务隔离生命周期及迁移失败闭环。

    请在当前 main@6f42b19508f31ef04ae2857172893f13d48afddf 上验证 2+ CN、双 Proxy、开启 connection cache 和 prepared short connections 的部署,强制触发后端迁移,并执行 issue 的串行/并行 MOTR 场景。重点确认 TIMESTAMP scalar-subquery 产生的用户变量在迁移后仍存在且值一致,同时检查 prepared statements、事务隔离、系统变量和 ROW_COUNT() 状态;还需确认无登录失败、panic/restart、后端/session 泄漏或迁移静默成功但状态丢失。

    请用包含版本、拓扑、准确 SQL/结果及终态计数的证据回复。预期 PASS 是迁移和连接复用成功且上述 session 状态保持一致;任何状态丢失、迁移错误或稳定性异常都应保留 issue OPEN 并标记 test-verification-failed。

    tester 选择依据:issue author.login 为 Ariznawlll,按约定选择 Ariznawlll;当前自动化账号 VioletQwQ-0 将不保留在 assignees 中。

  7. Ariznawlll commented on Aug 24, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:ba8954d543af0bdfb1948a8b89f77f5235ac9259
    • 部署方式:隔离本地单 LOG/TN/CN,使用单一持续 SQL 连接
    • 测试日期:2026-08-24

    原问题验证

    按 Issue 中的原始顺序执行:从 TIMESTAMP 标量子查询给会话变量赋值,等待两秒后执行重复键 no-op 更新,再执行把 v 更新为 99 的重复键语句。连续 3 轮均得到 ts_unchanged=1,随后得到 v=99, ts_advanced=1;会话变量在两次后续语句中均仍可读取。

    Happy Path 覆盖

    1. 标量子查询赋值、重复键 no-op 更新与时间值相等判断均正确。
    2. 重复键更新普通列后,值更新为 99,时间值相对保存值前进。

    Unhappy Path 覆盖

    1. 回归用例额外执行普通重复键写入后的重复主键 INSERT,预期拒绝后仍可读取保存的会话变量和原行;连续 3 轮一致。

    白盒验证

    不适用:该问题可由公开 SQL 在单连接内稳定覆盖,未使用内部注入。

    回归测试

    测试证据

    • 原始复现 3/3:每轮 ts_unchanged=1,v=99, ts_advanced=1。
    • 回归提交:a6a562a1。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

kind/bugphase/testingseverity/s1

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions