Repository navigation
Description
DRAFT ISSUE 35 (候选, 不要提交)
标题候选: [Bug]: internal composite-PK column __mo_cpkey_col is user-visible and writable — INSERT can store the hidden key disassociated from the declared logical key
标签: kind/bug, needs-triage
Relation to #26993 (CLOSED)
#26993 fixed the information_schema.columns metadata leakage of __mo_cpkey_col (through ODBC SQLColumns). That issue's verification only covered the catalog view (SHOW COLUMNS/SELECT * metadata) — it did not cover (and the fix did not remove) direct SQL access to the column, and it did not cover the write path at all. This report files the remaining, more dangerous half: name-addressable read AND write of the internal column through ordinary SQL on composite-PK tables. Reproduced on current main (2026-10-26), well after #26993 closed.
Description
For tables with composite primary keys, MatrixOne materializes the key as an internal hidden column __mo_cpkey_col. Unlike genuinely virtual internals, this column is visible and writable through ordinary user SQL, allowing callers to specify a primary-key value that does not correspond to the row's declared (a,b) contents:
CREATE TABLE cpk3 (a INT, b INT, PRIMARY KEY(a,b));
INSERT INTO cpk3 VALUES (1,10); -- hidden col auto-computed: hex = 3A15013A150A
INSERT INTO cpk3 (__mo_cpkey_col, a, b) VALUES (unhex('0001'), 1, 99);
-- succeeds! the row now has:
-- a=1, b=99, __mo_cpkey_col = 0x0001 (not the encoding of (1,99))
SELECT a, b, hex(__mo_cpkey_col) FROM cpk3 ORDER BY b;
-- 1 10 3A15013A150A ← correct hidden key
-- 1 99 0001 ← caller-injected, inconsistent with (a,b)Interesting nuance found while probing (worth keeping in mind before fixes):
- Single-column-PK tables do not expose
__mo_cpkey_col—SELECT ... FROM cpk2errors withcolumn __mo_cpkey_col does not exist(matching MySQL behavior of rejecting unknown columns). So the exposure is specific to the composite-key implementation. - The logical uniqueness appears to still hold (inserting a duplicate (1,10) correctly failed with 1062 even after the tampering), suggesting the check uses the (a,b) path rather than the stored cpkey — which raises the question of what the stored cpkey is then used for (merge/compaction, repl, index-joins). If any physical-layer dedup or index path relies on cpkey bytes, inconsistent cpkeys can double-count, orphan, or corrupt those rows in ways invisible until a flush/merge.
Reproduction
As above — any two-column composite PK table, one insert naming __mo_cpkey_col explicitly with a small hex literal.
Impact
- Application/ORM accidents: column-list-driven inserts that enumerate information_schema columns (some generic sync tools do) will pick up
__mo_cpkey_colas a real column when reflecting a composite-PK table — turning a well-behaved sync job into one that reproduces stale cpkeys (the value from a previous timestamp of the row), the exact class of bug that breaks replicas silently. - Potential physical-layer integrity: if compaction/index builds use cpkey bytes as identity, caller-mismatched cpkeys can produce index anomalies. Even if today's code paths all derive the key from columns, allowing user writes to an internal column is a standing hazard against future refactors.
- Read exposure alone leaks implementation (encoding format is visible), which is usually tolerable but is distinct from allowing writes.
Expected behavior
Mirror the single-column behavior uniformly:
INSERT INTO t (__mo_cpkey_col, ...)on a composite-PK table should error asunknown column(the column is not part of the declared table's public schema), and- ideally
SELECT __mo_cpkey_coltoo (or at least make it readable-only via a documented system-suffix exception); exposing the system column should be opt-in (e.g.SELECT * INCLUDING SYSTEMstyle or a session flag), not default-visible.
If the composite-key needs a user-visible materialization for debugging, provide a function (e.g. mo_pk(a,b)) or a documented pseudo-column with read-only semantics instead of the writable internal.
Activity
[-][Bug]: composite-PK hidden column __mo_cpkey_col is name-addressable and writable — INSERT can store a cpkey inconsistent with the row's declared key (reopens the write-path half of #26993)[/-][+][Bug]: hidden composite-PK column __mo_cpkey_col is writable via INSERT[/+]fix(plan): reject explicit writes to hidden storage columns (#31321)
XuPeng-SH commentedon Oct 28, 2026
QA handoff for merged #31321 (
00c103b68bd2b39194147508445956f5ece16dda): affected hidden-column INSERT/REPLACE/UPDATE/LOAD SET and internal ALTER COPY tests were not run in this environment. Large planner links and a current-head service were blocked by the existing resource guard; no product failure or full acceptance is inferred. Please verify the original hidden storage-column write contract and unchanged internal authority paths.Ariznawlll commentedon Oct 28, 2026
结论
测试通过。显式写入隐藏存储键被拒绝,失败后数据不变;正常写入和内部 COPY 路径保持可用。
关键证据
main@72d99c85751dc5b9b7775cb50571e7efd6400487,包含已合入修复 fix(plan): reject explicit writes to hidden storage columns #31321;macOS arm64、隔离单进程 LogService / TN / CN,实际二进制git_version()为72d99c8575。INSERT INTO t(__mo_cpkey_col,a,b,v) ...在复合主键表上 3/3 返回未知列,已有(1,10,7)和计算出的内部键保持不变。INSERT ... SELECT、REPLACE、INSERT IGNORE、UPDATE、ODKU 和预编译显式目标均被拒绝;每次拒绝后检查完整行和内部键,3/3。LOAD DATA INLINE目标均被拒绝且原行不变;普通更新、ODKU、插入、二级索引查询及ALTER ... ALGORITHM=COPY保留内部 fake key,3/3。9e29011e7313a57962adc00963baa659d1e81e37,重建并启动对应二进制后,MOTR 该回归补跑 3/3、0 跳过;先前结果保留对应72d99c…的版本信息。待解决点
无。