You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: CHECK constraints are parsed but not enforced #25099
Others: Reproduced via cross-language ORM compatibility testing (PHP / Python / Java / Node.js) over the MySQL 8.0.30 wire protocol. The minimal repro below uses raw SQL so it is driver-independent.
Actual Behavior
CHECK is accepted at DDL time but never enforced on writes, so a row that violates it is accepted.
INSERT INTO t VALUES (-5); -- MatrixOne: accepted
Expected Behavior
The violating row is rejected:
INSERT INTO t VALUES (-5); -- MySQL 8.0.16+: rejected (ERROR 3819 Check constraint violated)
Steps to Reproduce
CREATETABLEt (age INTCHECK (age >=0));
INSERT INTO t VALUES (-5); -- MySQL 8.0.16+: rejected MatrixOne: acceptedSELECT*FROM t; -- MatrixOne: returns the -5 row
Additional information
Application invariants relying on CHECK become silent no-ops.
changed the title [-][correctness] `CHECK` constraints are parsed but not enforced[/-][+][Bug]: CHECK constraints are parsed but not enforced[/+]on Jun 23, 2026
Additional Model 11 DDL coverage on latest main 51656deb6 also confirms both named and column-level CHECK constraints are accepted but not enforced, and CREATE TABLE LIKE does not preserve the CHECK metadata.
dropdatabase if exists mysql_compat_model11b;
createdatabasemysql_compat_model11b;
use mysql_compat_model11b;
createtablet_base (
id intprimary key,
c_nn intnot null default 5,
constraint chk_c_nn check (c_nn >0)
);
insert into t_base values (1, -1); -- MySQL rejects; MO acceptscreatetablet_likelike t_base;
show create table t_like; -- MySQL includes a CHECK constraint; MO does notinsert into t_like values (2, -1); -- MySQL rejects; MO accepts
So the issue is not limited to anonymous column-level checks; the DML enforcement and LIKE metadata path are both affected.
在最新 main 60d28f8ecb93ae512da6af4a2915b204a373bd42(2026-08-06,本地双 CN)复验后,当前问题范围可收敛为:CHECK 已在 INSERT 与 INSERT ... ON DUPLICATE KEY UPDATE 中生效,但普通 UPDATE 仍绕过校验并会写入非法数据。
复现 SQL:
createtablet (
id intprimary key,
v intnot null,
constraint ck_v check (v between 0and10)
);
insert into t values (1, 10);
-- 正确:均返回 ERROR 3819,且不写入非法值insert into t values (2, 11);
insert into t values (1, 11)
on duplicate key update v =values(v);
-- 错误:返回成功,随后读到非法值update t set v =11where id =1;
select id, v from t;
-- 1 | 11
Activity
[-][correctness] `CHECK` constraints are parsed but not enforced[/-][+][Bug]: CHECK constraints are parsed but not enforced[/+]Ariznawlll commentedon Jul 2, 2026
Additional Model 11 DDL coverage on latest main
51656deb6also confirms both named and column-level CHECK constraints are accepted but not enforced, andCREATE TABLE LIKEdoes not preserve the CHECK metadata.So the issue is not limited to anonymous column-level checks; the DML enforcement and LIKE metadata path are both affected.
Ariznawlll commentedon Aug 6, 2026
在最新 main
60d28f8ecb93ae512da6af4a2915b204a373bd42(2026-08-06,本地双 CN)复验后,当前问题范围可收敛为:CHECK已在INSERT与INSERT ... ON DUPLICATE KEY UPDATE中生效,但普通UPDATE仍绕过校验并会写入非法数据。复现 SQL:
在 CN1 → CN2 → CN1 连续 3 轮中结果一致:前两条写入均被
ERROR 3819 ... Check constraint 'ck_v' is violated拒绝;普通UPDATE均返回成功并保存v = 11。将该非法值提交后重启集群,两个 CN 均读到1 | 11,说明错误数据已持久化。执行计划也能直接区分两条路径:
EXPLAIN INSERT含Filter Cond: _check_constraint_assert(...);EXPLAIN UPDATE只有Multi Update -> Lock -> Project -> Table Scan,没有该断言。代码侧对应地,
pkg/sql/plan/bind_update.go在更新行像构造完成后只追加了外键检查(约 434 行),没有调用appendCheckConstraintPlan;该 helper 当前只被 INSERT/REPLACE 相关路径调用。因此建议保留本 issue,并将验收覆盖普通单表 UPDATE、UPDATE ... FROM/多表 UPDATE、带生成列的 UPDATE,以及失败时原行不变。