Skip to content

[Bug]: Temporary-table DELETE enters persistent lifecycle admission and fails behind unrelated SNAPSHOT readers #30089

Closed

Description

@LeftHandCold

Confirmed behavior

An unfiltered DELETE against a session temporary table fails with error 20706 when another transaction holds the shared SNAPSHOT lifecycle gate. A row-scoped DELETE should not enter persistent-table replacement/branch-lineage admission merely because it deletes every row.

This is distinct from #28255 (temporary CREATE/DROP rollback semantics) and #29814 (public persistent-table TRUNCATE). Do not weaken the general retained-lock FastFail protection to address this case.

Versions and evidence

  • Exact Main nightly MO cd8d5abf9665a97d13e50b04840fb74b877fd339, image digest sha256:d554cbb460dc128049b329fb0e1d5e2e9c35d9a559cb2986d732b37e3a970b04.
  • Main nightly, MOTR issue_28255_temp_ddl_rollback.test: the first failure is delete from create_rollback, not CREATE and not snapshot restore.
  • Loki namespace mo-main-family-38268423576-1, pod nightly-regression-dis-tp-cn-nvqjf, 2026-10-12 20:33:45.649 UTC: transaction 74150f0a772e8ef818ddd22a558484d9, table 272477, Exclusive-Row-FastFail, error lock options conflict, wait policy is fast fail.
  • Independently reproduced on Shanghai50 with the exact immutable image, fresh single-CN/TN/LogService, 4 CPU / 8 GiB. No concurrent workload is needed other than the explicit gate holder below. The no-holder control succeeds and rollback restores row 2.
  • Current Main 175a645a85994f2c95992d3aa8d6dacb6d9e167f still has the same relevant planning/admission code; this is source verification, not yet a second binary test.

Deterministic minimal reproduction

Use a disposable instance. Connection A:

CREATE DATABASE temp_delete_probe;
USE temp_delete_probe;
CREATE TEMPORARY TABLE t(id INT PRIMARY KEY);
INSERT INTO t VALUES(2);
BEGIN;
UPDATE t SET id=4;

Connection B (hold open after the SELECT returns):

BEGIN;
SELECT feature_code FROM mo_catalog.mo_feature_registry
WHERE feature_code='SNAPSHOT' FOR SHARE;

Then A:

DELETE FROM t; -- actual: ERROR 20706, FastFail
ROLLBACK;
SELECT * FROM t; -- row 2 survives

Rollback B and remove the probe database. Holding this catalog row is only a deterministic test substitute for another admitted lifecycle operation; this is not a proposed customer workaround.

Root cause

Both modern and legacy DELETE planning still permit temporary tables to use the truncate implementation. The legacy makeOneDeletePlan puts TableDef.Name (the physical temporary relation name) into TruncateTable.Table. Runtime Scope.TruncateTable identifies temporary tables through the session's logical alias lookup. That lookup misses the physical name; the statement enters persistent-table broad lifecycle admission and tries to acquire an exclusive global SNAPSHOT gate after the earlier UPDATE retained data locks. Admission intentionally FastFails rather than creating a reverse-order wait.

The safety check is doing its job; the incorrect input path is temporary DML being lowered to persistent lifecycle replacement. A scoped fix should keep temporary DELETE as transactional row DML, including its index maintenance, and leave public TRUNCATE and permanent-table optimization unchanged.

Required validation

  • Temporary unfiltered DELETE succeeds while the unrelated shared gate is held, without waiting for its release; rollback and commit produce independently expected rows.
  • Binary/text parameter handling is irrelevant to the reproduction.
  • Temporary tables with a secondary index and a same-name permanent table remain isolated; deletion updates only the temp table/index and preserves rollback.
  • Both planner paths reject temporary truncate lowering; permanent-table truncate eligibility is unchanged.
  • No claim of permanent data loss is made by this report.

Activity

  1. added
    kind/bug
    severity/s0
    on Oct 13, 2026
  2. XuPeng-SH commented on Oct 16, 2026

    @XuPeng-SH
    Contributor

    转测 @Ariznawlll。

    已在 main 提交 0723ae37b1183a03bac9eda16669dfc7e474dfb8 对关联修复 #30091 完成本 issue 对应的定向验证,所测场景通过。

    已运行对应功能回归;本轮测试结果支持进入测试验收。

    测试入口:

    • TestGossipFixtureConfigPortRange
    • TestGossipFixtureStartupConfigurationFailure
    • TestTemporaryDeleteDoesNotRewriteToTruncate
    • TestIssue30089TemporaryDeleteAvoidsPersistentLifecycle

    请在目标验收版本复核后决定关闭;本次转测保留 issue 为 OPEN。

  3. Ariznawlll commented on Oct 19, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:官方 main
    • commit:def799e1260dd547cae2e0e54323ea20ec1b7685
    • 修复:fix(plan): keep temporary DELETE on transactional row path #30091 已 MERGED,merge commit 94da0308ad0c5d4fb1d9912293339218bf26dfa3 经祖先检查确认进入上述 main。
    • 部署方式:隔离本地构建的 1 CN / 1 TN / 1 LogService(MySQL 6001),另以仓库内嵌集群的 2 CN 跨会话测试校验共享锁路径;未使用共享 TKE。
    • 测试日期:2026-10-19(北京时间)。

    原问题验证

    按 issue 的顺序在临时表会话中先 UPDATE 并保持事务,另一会话 SELECT feature_code ... WHERE feature_code='SNAPSHOT' FOR SHARE 持有生命周期共享锁,然后执行无条件 DELETE FROM 临时表。修复后的实际结果是 DELETE 成功,无旧版的 20706 FastFail。MOTR 同 CN 双会话该路径 10/10 轮通过;仓库内嵌双 CN 的 TestIssue30089TemporaryDeleteAvoidsPersistentLifecycle 10/10 轮通过。

    Happy Path 覆盖

    1. 临时表与普通表同名,临时表有主键和唯一二级索引。持锁期间 DELETE 后同事务插入 (5,40) 成功;回滚后查询实际恢复为 (2,20)。
    2. 再次 DELETE 后复用唯一索引值 v=20,查询实际为 (3,20);另一会话同名普通表仍为 (99,99)。
    3. 相邻 MOTR 临时表 TRUNCATE/旧快照场景共 3/3 个 case 通过;本项新增回归单独再跑 3/3,随后时序重复 10/10。

    Unhappy Path 覆盖

    1. 另一会话持续持有 SNAPSHOT 共享锁,原本会造成 FastFail 的冲突路径中临时表 DELETE 成功,不依赖先释放该锁。
    2. 在已 DELETE、已插入之后执行 ROLLBACK,值 (2,20) 和唯一索引可用性恢复;同名普通表未被误删。每轮测试均删除独立数据库,未观察到测试对象残留。
    3. 本问题不涉及无效字面量、NULL 转换或外部故障注入;未将这些无关维度计为已测。

    白盒验证

    pkg/tests/issues/issue_30089_test.go 的真实 SQL 双 CN 测试在上述 main -count=10 通过,-race -count=3 通过;均包含原始共享锁屏障、带/不带索引临时表、回滚和同名普通表隔离。

    回归测试

    • 已向 MOTR PR #247 追加 SQL 场景 和配对的 预期结果。PR head 1b3adcaa6fd2a37981334ea56018c9acc0151854;本地定向 3/3、额外时序 10/10、相邻三用例 3/3。
    • PR 仍 Open;4 项离线检查 SUCCESS。完整 MOTR suite 与集成 CI 本次未执行,合入状态后续跟踪。

    测试证据

    • 代码和确定性 SQL/result 见上述 MOTR PR;原始双 CN 验证入口见 MatrixOne 测试源码。本地记录:MOTR 10 轮 10 pass / 230 条 SQL 无错误;Go 普通 10/10、race 3/3。
    • 本次隔离环境的 test/result golden 初稿仅有 TAB 字符书写错误,修正后 10/10 通过;不是产品缺陷。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions