Skip to content

Cannot drop CHECK CONSTRAINT if tidb_enable_check_constraint is OFF. #64891

@YangKeao

Description

@YangKeao

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

set global tidb_enable_check_constraint = 'ON';
CREATE TABLE t1 (CHECK (c1 <> c2), c1 INT CHECK (c1 > 10), c2 INT CONSTRAINT c2_positive_for_t1 CHECK (c2 > 0));
set global tidb_enable_check_constraint = 'OFF';
alter table t1 drop check c2_positive_for_t1;

It'll return a warning and don't actually drop the check constraint.

To avoid X-Y problem, let me describe why we might need to drop without enabling tidb_enable_check_constraint:

If a cluster creates constraints with the same name in a single database before #48062 is introduced, and upgrade to a newer version with #48062, it will fail to backup/restore. The restore will produce an error: Duplicate check constraint name ....

I have two proposal / options for this issue:

  1. Modify the DDL to allow drop check even when tidb_enable_check_constraint is off.
  2. Modify the BR to automatically clean up the check constraints when tidb_enable_check_constraint is off. It sounds weird but the behavior is the same with CREATE TABLE DDL SQL.

I personally prefer the first one, but not sure.

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

The constraint is dropped.

3. What did you see instead (Required)

It's not dropped and a warning is returned.

4. What is your TiDB version? (Required)

Metadata

Metadata

Assignees

No one assigned

    Labels

    affects-8.5This bug affects the 8.5.x(LTS) versions.component/ddlThis issue is related to DDL of TiDB.severity/majortype/bugThe issue is confirmed as a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions