sysvar: add tidb_enable_strict_not_null_check#21600
Open
xhebox wants to merge 1 commit intopingcap:masterfrom
Open
sysvar: add tidb_enable_strict_not_null_check#21600xhebox wants to merge 1 commit intopingcap:masterfrom
xhebox wants to merge 1 commit intopingcap:masterfrom
Conversation
Signed-off-by: xhe <xw897002528@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Frank945946
reviewed
Apr 30, 2026
Comment on lines
+2489
to
+2490
| - 这个变量用来控制是否可以插入 `null` 到非空列,关闭时允许此类插入。该设置的目的是提供一个从 TiDB 早期版本升级的方法,因为早期版本在验证类型方面不太严格。 | ||
| - 该变量的默认值 `ON` 与 MySQL 兼容。 |
Collaborator
There was a problem hiding this comment.
Suggested change
| - 这个变量用来控制是否可以插入 `null` 到非空列,关闭时允许此类插入。该设置的目的是提供一个从 TiDB 早期版本升级的方法,因为早期版本在验证类型方面不太严格。 | |
| - 该变量的默认值 `ON` 与 MySQL 兼容。 | |
| 该变量用于控制在向定义为 NOT NULL 的列插入 NULL 值时的校验行为。其设计初衷是为不同来源的集群迁移及版本升级提供兼容性支撑: | |
| MySQL 兼容性: | |
| ON (默认值):与 MySQL 8.0 的标准行为保持一致。对于 NOT NULL 约束执行严格校验,插入 NULL 值将直接触发错误。 | |
| OFF:模拟 MySQL 5.7 及其早期版本在非严格模式下的行为。允许向非空列插入 NULL,此时系统不会报错,而是自动赋予该列对应数据类型的隐式默认值(例如数字类型填充 0,字符串类型填充空字符串 "")。 | |
| 升级兼容性: | |
| TiDB 在早期版本中对非空约束的校验相对宽松。当从低版本 TiDB(如 v6.x、v7.x 等)升级至 v8.5 或更高版本时,如果存量业务逻辑依赖于这种“隐式赋默认值”的行为,开启此变量可能会导致原有 SQL 报错。 | |
| 使用建议 | |
| 对于新创建的集群,建议保持默认值 ON,以确保数据的严谨性并符合现代数据库标准。 | |
| 如果是从 MySQL 5.7 迁移至 TiDB,或从 TiDB 早期版本平滑升级至高版本且无法立即修改业务逻辑,可将此变量设置为 OFF 以维持业务连续性。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First-time contributors' checklist
What is changed, added or deleted? (Required)
Which TiDB version(s) do your changes apply to? (Required)
Tips for choosing the affected version(s):
By default, CHOOSE MASTER ONLY so your changes will be applied to the next TiDB major or minor releases. If your PR involves a product feature behavior change or a compatibility change, CHOOSE THE AFFECTED RELEASE BRANCH(ES) AND MASTER.
For details, see tips for choosing the affected versions (in Chinese).
What is the related PR or file link(s)?
Do your changes match any of the following descriptions?