Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHECK CONSTRAINT loss when ENFORCED again #47567

Closed
shawn0915 opened this issue Oct 12, 2023 · 1 comment · Fixed by #47633
Closed

CHECK CONSTRAINT loss when ENFORCED again #47567

shawn0915 opened this issue Oct 12, 2023 · 1 comment · Fixed by #47633

Comments

@shawn0915
Copy link
Contributor

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

mysql> show create table t\G
*************************** 1. row ***************************
       Table: t
Create Table: CREATE TABLE `t` (
  `a` int(11) DEFAULT NULL,
CONSTRAINT `t_chk_1` CHECK ((1 < `a`)) /*!80016 NOT ENFORCED */,
CONSTRAINT `t_chk_2` CHECK ((1 < `a`)) /*!80016 NOT ENFORCED */,
CONSTRAINT `t_chk_3` CHECK ((1 < `a`)) /*!80016 NOT ENFORCED */,
CONSTRAINT `check_1` CHECK ((1 < `a`)) /*!80016 NOT ENFORCED */,
CONSTRAINT `t_chk_4` CHECK ((1 < `a`)) /*!80016 NOT ENFORCED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin
1 row in set (0.00 sec)

mysql> insert t select 1;
Query OK, 1 row affected (0.00 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> select * from t;
+------+
| a    |
+------+
|    2 |
|    2 |
|    1 |
+------+
3 rows in set (0.01 sec)

mysql> ALTER TABLE t ALTER CONSTRAINT t_chk_1 ENFORCED;
ERROR 3819 (HY000): Check constraint 't_chk_1' is violated.
mysql> select * from t;
+------+
| a    |
+------+
|    2 |
|    2 |
|    1 |
+------+
3 rows in set (0.01 sec)

mysql> show create table t\G
*************************** 1. row ***************************
       Table: t
Create Table: CREATE TABLE `t` (
  `a` int(11) DEFAULT NULL,
CONSTRAINT `t_chk_2` CHECK ((1 < `a`)) /*!80016 NOT ENFORCED */,
CONSTRAINT `t_chk_3` CHECK ((1 < `a`)) /*!80016 NOT ENFORCED */,
CONSTRAINT `check_1` CHECK ((1 < `a`)) /*!80016 NOT ENFORCED */,
CONSTRAINT `t_chk_4` CHECK ((1 < `a`)) /*!80016 NOT ENFORCED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin
1 row in set (0.00 sec)

mysql> select * from information_schema.CHECK_CONSTRAINTS;
+--------------------+-------------------+-----------------+--------------+
| CONSTRAINT_CATALOG | CONSTRAINT_SCHEMA | CONSTRAINT_NAME | CHECK_CLAUSE |
+--------------------+-------------------+-----------------+--------------+
| def                | sbtest            | check_1         | (1 < `a`)    |
| def                | sbtest            | t_chk_2         | (1 < `a`)    |
| def                | sbtest            | t_chk_3         | (1 < `a`)    |
| def                | sbtest            | check_1         | (1 < `a`)    |
| def                | sbtest            | t_chk_4         | (1 < `a`)    |
+--------------------+-------------------+-----------------+--------------+
5 rows in set (0.00 sec)

mysql>

2. What did you expect to see? (Required)

t_chk_1 should be keep NOT ENFORCED, but not loss.

and, in mysql, the logic is right.

mysql> select version();
+-----------+
| version() |
+-----------+
| 8.1.0     |
+-----------+
1 row in set (0.00 sec)

mysql> ALTER TABLE t ALTER CONSTRAINT t_chk_1 ENFORCED;
ERROR 3819 (HY000): Check constraint 't_chk_1' is violated.
mysql> select * from t;
+------+
| a    |
+------+
|    1 |
|    2 |
|    2 |
+------+
3 rows in set (0.00 sec)

mysql> show create table t\G
*************************** 1. row ***************************
       Table: t
Create Table: CREATE TABLE `t` (
  `a` int DEFAULT NULL,
  CONSTRAINT `check_1` CHECK ((1 < `a`)) /*!80016 NOT ENFORCED */,
  CONSTRAINT `t_chk_1` CHECK ((1 < `a`)) /*!80016 NOT ENFORCED */,
  CONSTRAINT `t_chk_2` CHECK ((1 < `a`)) /*!80016 NOT ENFORCED */,
  CONSTRAINT `t_chk_3` CHECK ((1 < `a`)) /*!80016 NOT ENFORCED */,
  CONSTRAINT `t_chk_4` CHECK ((1 < `a`)) /*!80016 NOT ENFORCED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin
1 row in set (0.00 sec)

mysql> select * from information_schema.CHECK_CONSTRAINTS;
+--------------------+-------------------+-----------------+--------------+
| CONSTRAINT_CATALOG | CONSTRAINT_SCHEMA | CONSTRAINT_NAME | CHECK_CLAUSE |
+--------------------+-------------------+-----------------+--------------+
| def                | sbtest            | t_chk_1         | (1 < `a`)    |
| def                | sbtest            | t_chk_2         | (1 < `a`)    |
| def                | sbtest            | t_chk_3         | (1 < `a`)    |
| def                | sbtest            | check_1         | (1 < `a`)    |
| def                | sbtest            | t_chk_4         | (1 < `a`)    |
+--------------------+-------------------+-----------------+--------------+
5 rows in set (0.00 sec)

3. What did you see instead (Required)

4. What is your TiDB version? (Required)

Release Version: v7.5.0-alpha

@shawn0915 shawn0915 added the type/bug The issue is confirmed as a bug. label Oct 12, 2023
@jebter jebter added the component/ddl This issue is related to DDL of TiDB. label Oct 12, 2023
@jiyfhust
Copy link
Contributor

/assign

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

Successfully merging a pull request may close this issue.

5 participants