From 3751c5b4e91e9559ee45a42856971a0861ee7ce0 Mon Sep 17 00:00:00 2001 From: cbcwestwolf <1004626265@qq.com> Date: Wed, 11 Sep 2024 15:53:16 +0800 Subject: [PATCH 1/3] tidb: add description about `TIDB_CHECK_CONSTRAINTS` --- TOC.md | 1 + .../information-schema-check-constraints.md | 1 + ...formation-schema-tidb-check-constraints.md | 59 +++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 information-schema/information-schema-tidb-check-constraints.md diff --git a/TOC.md b/TOC.md index eaf011f7223e..e31d91ced396 100644 --- a/TOC.md +++ b/TOC.md @@ -1000,6 +1000,7 @@ - [`TABLES`](/information-schema/information-schema-tables.md) - [`TABLE_CONSTRAINTS`](/information-schema/information-schema-table-constraints.md) - [`TABLE_STORAGE_STATS`](/information-schema/information-schema-table-storage-stats.md) + - [`TIDB_CHECK_CONSTRAINTS`](/information-schema/information-schema-tidb-check-constraints.md) - [`TIDB_HOT_REGIONS`](/information-schema/information-schema-tidb-hot-regions.md) - [`TIDB_HOT_REGIONS_HISTORY`](/information-schema/information-schema-tidb-hot-regions-history.md) - [`TIDB_INDEXES`](/information-schema/information-schema-tidb-indexes.md) diff --git a/information-schema/information-schema-check-constraints.md b/information-schema/information-schema-check-constraints.md index 7e40102d0421..daf979d0dd65 100644 --- a/information-schema/information-schema-check-constraints.md +++ b/information-schema/information-schema-check-constraints.md @@ -29,6 +29,7 @@ DESC CHECK_CONSTRAINTS; 下述示例使用 `CREATE TABLE` 语句添加 `CHECK` 约束: ```sql +SET GLOBAL tidb_enable_check_constraint = ON; CREATE TABLE test.t1 (id INT PRIMARY KEY, CHECK (id%2 = 0)); SELECT * FROM CHECK_CONSTRAINTS\G ``` diff --git a/information-schema/information-schema-tidb-check-constraints.md b/information-schema/information-schema-tidb-check-constraints.md new file mode 100644 index 000000000000..3695f502598a --- /dev/null +++ b/information-schema/information-schema-tidb-check-constraints.md @@ -0,0 +1,59 @@ +--- +title: TIDB_CHECK_CONSTRAINTS +summary: 了解 INFORMATION_SCHEMA 表 `TIDB_CHECK_CONSTRAINTS`。 +--- + +# TIDB\_CHECK\_CONSTRAINTS + +`TIDB_CHECK_CONSTRAINTS` 表提供关于表上 [`CHECK` 约束](/constraints.md#check-约束)的信息。除了包含 [`CHECK_CONSTRAINTS`](/information-schema/information-schema-check-constraints.md) 中的信息,`TIDB_CHECK_CONSTRAINTS` 还可获取定义 `CHECK` 约束的表名和表 ID。 + +```sql +USE INFORMATION_SCHEMA; +DESC TIDB_CHECK_CONSTRAINTS; +``` + +命令输出如下: + +```sql ++--------------------+-------------+------+------+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++--------------------+-------------+------+------+---------+-------+ +| CONSTRAINT_CATALOG | varchar(64) | NO | | NULL | | +| CONSTRAINT_SCHEMA | varchar(64) | NO | | NULL | | +| CONSTRAINT_NAME | varchar(64) | NO | | NULL | | +| CHECK_CLAUSE | longtext | NO | | NULL | | +| TABLE_NAME | varchar(64) | YES | | NULL | | +| TABLE_ID | bigint(21) | YES | | NULL | | ++--------------------+-------------+------+------+---------+-------+ +6 rows in set (0.00 sec) +``` + +下述示例使用 `CREATE TABLE` 语句添加 `CHECK` 约束: + +```sql +SET GLOBAL tidb_enable_check_constraint = ON; +CREATE TABLE test.t1 (id INT PRIMARY KEY, CHECK (id%2 = 0)); +SELECT * FROM TIDB_CHECK_CONSTRAINTS\G +``` + +命令输出如下: + +```sql +*************************** 1. row *************************** +CONSTRAINT_CATALOG: def + CONSTRAINT_SCHEMA: test + CONSTRAINT_NAME: t1_chk_1 + CHECK_CLAUSE: (`id` % 2 = 0) + TABLE_NAME: t1 + TABLE_ID: 107 +1 row in set (0.02 sec) +``` + +`TIDB_CHECK_CONSTRAINTS` 表的字段描述如下: + +* `CONSTRAINT_CATALOG`:约束的目录,始终为 `def`。 +* `CONSTRAINT_SCHEMA`:约束的库名。 +* `CONSTRAINT_NAME`:约束的名字。 +* `CHECK_CLAUSE`:检查约束的子句。 +* `TABLE_NAME`:约束所在的表名。 +* `TABLE_ID`:约束所在的表 ID。 From 07c8683bd3d0dd8cb5db149625d537486fa37195 Mon Sep 17 00:00:00 2001 From: xixirangrang Date: Thu, 12 Sep 2024 15:07:55 +0800 Subject: [PATCH 2/3] Update information-schema/information-schema-tidb-check-constraints.md --- information-schema/information-schema-tidb-check-constraints.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/information-schema/information-schema-tidb-check-constraints.md b/information-schema/information-schema-tidb-check-constraints.md index 3695f502598a..e181c322be12 100644 --- a/information-schema/information-schema-tidb-check-constraints.md +++ b/information-schema/information-schema-tidb-check-constraints.md @@ -5,7 +5,7 @@ summary: 了解 INFORMATION_SCHEMA 表 `TIDB_CHECK_CONSTRAINTS`。 # TIDB\_CHECK\_CONSTRAINTS -`TIDB_CHECK_CONSTRAINTS` 表提供关于表上 [`CHECK` 约束](/constraints.md#check-约束)的信息。除了包含 [`CHECK_CONSTRAINTS`](/information-schema/information-schema-check-constraints.md) 中的信息,`TIDB_CHECK_CONSTRAINTS` 还可获取定义 `CHECK` 约束的表名和表 ID。 +`TIDB_CHECK_CONSTRAINTS` 表提供关于表上 [`CHECK` 约束](/constraints.md#check-约束)的信息。除了包含 [`CHECK_CONSTRAINTS`](/information-schema/information-schema-check-constraints.md) 中的信息,`TIDB_CHECK_CONSTRAINTS` 还提供了定义 `CHECK` 约束的表名和表 ID。 ```sql USE INFORMATION_SCHEMA; From 0fe850aa708e511e7088af2ad4d7026e5ef16f99 Mon Sep 17 00:00:00 2001 From: xixirangrang Date: Fri, 20 Sep 2024 16:46:11 +0800 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Lilian Lee --- .../information-schema-tidb-check-constraints.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/information-schema/information-schema-tidb-check-constraints.md b/information-schema/information-schema-tidb-check-constraints.md index e181c322be12..06c061bfb1b6 100644 --- a/information-schema/information-schema-tidb-check-constraints.md +++ b/information-schema/information-schema-tidb-check-constraints.md @@ -5,7 +5,7 @@ summary: 了解 INFORMATION_SCHEMA 表 `TIDB_CHECK_CONSTRAINTS`。 # TIDB\_CHECK\_CONSTRAINTS -`TIDB_CHECK_CONSTRAINTS` 表提供关于表上 [`CHECK` 约束](/constraints.md#check-约束)的信息。除了包含 [`CHECK_CONSTRAINTS`](/information-schema/information-schema-check-constraints.md) 中的信息,`TIDB_CHECK_CONSTRAINTS` 还提供了定义 `CHECK` 约束的表名和表 ID。 +`TIDB_CHECK_CONSTRAINTS` 表提供关于表上 [`CHECK` 约束](/constraints.md#check-约束)的信息。除了包含 [`CHECK_CONSTRAINTS`](/information-schema/information-schema-check-constraints.md) 表中的信息之外,`TIDB_CHECK_CONSTRAINTS` 还提供了定义 `CHECK` 约束的表名和表 ID。 ```sql USE INFORMATION_SCHEMA; @@ -55,5 +55,5 @@ CONSTRAINT_CATALOG: def * `CONSTRAINT_SCHEMA`:约束的库名。 * `CONSTRAINT_NAME`:约束的名字。 * `CHECK_CLAUSE`:检查约束的子句。 -* `TABLE_NAME`:约束所在的表名。 -* `TABLE_ID`:约束所在的表 ID。 +* `TABLE_NAME`:约束所在表的名字。 +* `TABLE_ID`:约束所在表的 ID。