Repository navigation
Description
Problem
RESTORE TABLE can report success while leaving its target unchanged when another table has a foreign-key reference to that target. This is a silent data-restore failure: a historical read sees the snapshot value, but the successful restore leaves the post-snapshot value in place.
Environment
- Branch:
main - Commit:
a2f89230085a0f6650ec7bb7017ba6b8a97c9efc - Build: local official-main binary at that commit
- Topology: isolated standalone LOG/TN/CN, with a shared temporary data path
Steps to reproduce
DROP SNAPSHOT IF EXISTS repro_fk_control_snapshot;
DROP SNAPSHOT IF EXISTS repro_fk_parent_snapshot;
DROP DATABASE IF EXISTS repro_fk_control;
DROP DATABASE IF EXISTS repro_fk_case;
-- Normal table-restore control.
CREATE DATABASE repro_fk_control;
CREATE TABLE repro_fk_control.t (id INT PRIMARY KEY, v VARCHAR(16));
INSERT INTO repro_fk_control.t VALUES (1, 'before');
CREATE SNAPSHOT repro_fk_control_snapshot FOR TABLE repro_fk_control t;
UPDATE repro_fk_control.t SET v = 'changed';
RESTORE TABLE repro_fk_control.t{snapshot='repro_fk_control_snapshot'};
SELECT 'control_table_restore' AS case_name, v FROM repro_fk_control.t;
CREATE DATABASE repro_fk_case;
CREATE TABLE repro_fk_case.parent_t (id INT PRIMARY KEY, v VARCHAR(16));
CREATE TABLE repro_fk_case.child_t (
cid INT PRIMARY KEY,
pid INT,
CONSTRAINT fk_parent FOREIGN KEY (pid) REFERENCES repro_fk_case.parent_t(id)
);
INSERT INTO repro_fk_case.parent_t VALUES (1, 'before');
INSERT INTO repro_fk_case.child_t VALUES (1, 1);
CREATE SNAPSHOT repro_fk_parent_snapshot FOR TABLE repro_fk_case parent_t;
UPDATE repro_fk_case.parent_t SET v = 'changed';
-- Historical read control.
SELECT 'fk_snapshot_read' AS case_name, v
FROM repro_fk_case.parent_t{snapshot='repro_fk_parent_snapshot'};
RESTORE TABLE repro_fk_case.parent_t{snapshot='repro_fk_parent_snapshot'};
SELECT 'fk_table_restore' AS case_name, v FROM repro_fk_case.parent_t;Expected behavior
The restore should either restore parent_t.v to before, or return an explicit unsupported-operation error. It must not report success while leaving changed in the target table.
Actual behavior
The complete repro ran 3/3 on a2f89230085a0f6650ec7bb7017ba6b8a97c9efc:
control_table_restore before
fk_snapshot_read before
fk_table_restore changed
The ordinary restore and the historical read controls both return before. Only the restore of the referenced table returns successfully but retains changed.
Root-cause hypothesis
pkg/frontend/snapshot.go lines 1632-1636 call checkTableIsMaster; for a referenced table the function logs that it will skip the restore and returns without an error. The caller therefore treats the statement as successful although the table was not recreated from the snapshot.
Duplicate check
Searched open and closed issues, plus open pull requests, for table restore with foreign keys. Existing historical work covers other restore failures and FK refactoring, but no report matches a successful table restore that leaves the referenced target unchanged.
Regression coverage
No test change is included with this report. After fixing, a deterministic snapshot BVT should assert that the restore either produces before or fails explicitly; returning success with changed must be prohibited.
Activity
gouhongshen commentedon Aug 13, 2026
Automated AI triage
This issue requires human involvement and cannot currently be completed independently by the
automated fix loop.
Reason
A maintainer must choose RESTORE TABLE semantics when the target is an FK parent: cascade dependent tables or reject with a documented error. Next action: define the contract and acceptance BVT, then requeue.
Evidence
snapshot.go filters FK dependencies by the requested table, while recreateTable returns success after detecting a master table, matching the reported silent no-op.
Please use this analysis to provide the missing decision, environment, evidence, or ownership
needed before the issue is returned to the AI candidate pool.
gouhongshen commentedon Sep 4, 2026
PR #28126 is trying to fix this issue.
fix(snapshot): reject RESTORE TABLE of referenced tables (#28126)
gouhongshen commentedon Sep 17, 2026
Fixed by PR #28126, merged to main as db39156.
The explicit RESTORE TABLE path now rejects a target referenced by a foreign key with a shared not-supported error before destructive restore work begins. It therefore cannot report success while silently retaining post-snapshot data. Database and account bulk restore keep their existing referenced-master skip behavior.
Verification recorded in the merged PR:
Closing: the reported silent-success behavior is eliminated. Coordinated restoration of dependent tables remains intentionally unsupported and out of scope.
gouhongshen commentedon Sep 24, 2026
PR #28126 has merged and is awaiting manual validation. The issue remains open.
Ariznawlll commentedon Oct 16, 2026
测试版本
main48dbe277b6d20216c1c513d03c5cbd681380a8a216042,运行时git_version()=48dbe277b6原问题验证
PR #28126 修复的 snapshot 显式表恢复分支已按预期拒绝 FK 父表:
但同一条件下,PITR 显式表恢复仍然是原问题的静默成功:
在
hb_restore_pitr_fk_1618、hb_pitr_fk_r2_1622、hb_pitr_fk_r3_1622三个全新数据库中均复现(3/3)。第一组 PITR 时间点为2026-10-16 15:19:51。父子数据和 FK 元数据保持原样,未发生半恢复;但调用者会错误地认为父表已恢复。Happy Path 覆盖
在后两组中,同一有效 PITR 时间点恢复没有 FK 引用的
plain_t,退出码均为 0,v从changed恢复为before。因此不是时间点无效,也不是 PITR 整体失效。另一个独立数据库级 PITR/snapshot 恢复,包含生成列、唯一索引和视图,结果与历史状态一致。Unhappy Path 覆盖
changed,子表仍为(1,1),后续查询正常。白盒验证
本轮做了源码路径对照,没有新增或运行专门 UT。
pkg/frontend/snapshot.go:908,2221-2244在显式表恢复前调用validateRestoreTableTarget并返回明确错误;pkg/frontend/pitr.go:1677-1683检出 FK 父表后直接return成功,显式 PITR 入口没有对应预检。这解释了两个命令的不同结果;checkTableIsMaster的错误处理另有静态疑点,本评论不把它当作已复现问题。回归测试
本轮未新增仓库测试或 PR。后续回归应在同一 FK 父表场景中分别断言 snapshot 与 PITR 显式表恢复:要么按定义协调恢复依赖,要么在修改前明确报不支持;不能成功返回却保留修改后的数据。数据库/账号批量恢复的现有跳过语义应单独测试,不与显式表恢复混同。
测试证据
固定 commit、3 组独立库、同时间点普通表对照及精确输出保存在隔离本机记录
/private/tmp/mo-explore-run-20261016/snapshot_pitr_whitebox_20261016.md。关键读数:parent_t.v=changed,plain_t.v=before,snapshot 显式父表恢复报 20105。此评论中的 SQL 和输出也可直接独立复核。该 PITR 分支与已关闭的 #19377(数据库级恢复 FK 父表时报错)不同。snapshot 显式表恢复修复有效;PITR 同语义入口仍保留原问题,原 issue 的跨入口验收尚未满足。
测试结论
测试不通过。