Repository navigation
Description
Problem
The declared object scope of a snapshot is not enforced. A table snapshot can read a different table, and a database snapshot can restore a table from a different database. In both cases, the operation uses the snapshot timestamp and succeeds instead of being rejected.
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_scope_table;
DROP SNAPSHOT IF EXISTS repro_scope_database;
DROP DATABASE IF EXISTS repro_scope_a;
DROP DATABASE IF EXISTS repro_scope_b;
CREATE DATABASE repro_scope_a;
CREATE DATABASE repro_scope_b;
CREATE TABLE repro_scope_a.t (id INT PRIMARY KEY, v VARCHAR(16));
CREATE TABLE repro_scope_b.t (id INT PRIMARY KEY, v VARCHAR(16));
INSERT INTO repro_scope_a.t VALUES (1, 'a_before');
INSERT INTO repro_scope_b.t VALUES (1, 'b_before');
CREATE SNAPSHOT repro_scope_table FOR TABLE repro_scope_a t;
CREATE SNAPSHOT repro_scope_database FOR DATABASE repro_scope_a;
UPDATE repro_scope_a.t SET v = 'a_after';
UPDATE repro_scope_b.t SET v = 'b_after';
-- Control: reads the object that the table snapshot was created for.
SELECT 'control_table_snapshot' AS case_name, v
FROM repro_scope_a.t{snapshot='repro_scope_table'};
-- Expected: reject because repro_scope_b.t is outside this table snapshot.
SELECT 'cross_table_read' AS case_name, v
FROM repro_scope_b.t{snapshot='repro_scope_table'};
-- Expected: reject because repro_scope_b is outside this database snapshot.
RESTORE TABLE repro_scope_b.t{snapshot='repro_scope_database'};
SELECT 'cross_database_restore' AS case_name, v FROM repro_scope_b.t;Expected behavior
Only the object represented by a table snapshot may be read through that snapshot. A database snapshot may restore only tables in its represented database. The two cross-scope operations should return an error and must not read or modify repro_scope_b.t.
Actual behavior
The complete repro ran 3/3 on a2f89230085a0f6650ec7bb7017ba6b8a97c9efc:
control_table_snapshot a_before
cross_table_read b_before
cross_database_restore b_before
The control proves the snapshot timestamp is valid for its actual target. The other two rows show that an unrelated table is read and then restored to its historical value.
Root-cause hypothesis
In pkg/frontend/snapshot.go around lines 900-915, table-restore validation compares the target fields only when the snapshot itself is table-level; the database-snapshot/table-restore combination has no database-name equality check. In pkg/sql/compile/sql_executor_context.go around lines 420-453, relation resolution applies the snapshot timestamp but does not verify the table/database object identity.
Duplicate check
Searched open and closed issues, plus open pull requests, for snapshot scope and cross-table restore behavior. No matching issue or active fix was found.
Regression coverage
No test change is included with this report. After fixing, this should be covered as a deterministic snapshot BVT: both cross-scope statements must fail, while the same-object control remains successful.
Activity
fix: enforce named snapshot object scope (#27134)
gouhongshen commentedon Aug 17, 2026
fixed by #27134
Ariznawlll commentedon Aug 17, 2026
测试版本
原问题验证
按 issue 原始步骤创建两个数据库、同名表、表级 snapshot 和数据库级 snapshot,更新 snapshot 后数据,再执行跨表读取和跨数据库 restore。当前 main 每轮均得到正确的对象范围校验:同表读取返回 `a_before`;跨表/跨库读取或 restore 返回 `ERROR 20101`;失败 restore 后目标表仍为 `b_after`。
Happy Path 覆盖
Unhappy Path 覆盖
白盒验证
不适用:问题可由公开 snapshot SQL 完整触发;本次以服务级黑盒和失败后状态检查为准,未添加内部 fault injection。
回归测试
测试证据
测试结论
测试通过。
fix: enforce named snapshot object scope (matrixorigin#27134)
fix: enforce named snapshot object scope (matrixorigin#27134)
fix: enforce named snapshot object scope (matrixorigin#27134)