pingcap / pingcap/tidb

ddl: BDR primary role rejects ADD COLUMN with explicit NULL DEFAULT NULL

Open
#67,185 3 comments 0 reactions 0 assignees View on GitHub
component/ddl contribution severity/moderate type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

1. Minimal reproduce step (Required)

Set up a BDR cluster with primary role, then run:

-- This succeeds:
ALTER TABLE t ADD COLUMN c1 INT NULL;

-- This fails with "the DDL not allowed when cluster bdr role is primary":
ALTER TABLE t ADD COLUMN c2 INT NULL DEFAULT NULL;

The two statements are semantically identical — NULL DEFAULT NULL on a nullable column is a no-op compared to just NULL.

Full matrix:

```
┌────────────────────────────────────┬────────┐
│ Statement │ Result │
├────────────────────────────────────┼────────┤
│ ADD COLUMN col NULL │ OK │
├────────────────────────────────────┼────────┤
│ ADD COLUMN col NULL DEFAULT NULL │ FAIL │
├────────────────────────────────────┼────────┤
│ ADD COLUMN col NOT NULL DEFAULT '' │ OK │
├────────────────────────────────────┼────────┤
│ ADD COLUMN col (no constraint) │ OK │
├────────────────────────────────────┼────────┤
│ ADD INDEX / CREATE INDEX │ OK │
└────────────────────────────────────┴────────┘
```

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

ALTER TABLE t ADD COLUMN c2 INT NULL DEFAULT NULL should succeed on a BDR primary cluster, since it is semantically equivalent to ADD COLUMN c2 INT NULL.

3. What did you see instead (Required)

Error: the DDL not allowed when cluster bdr role is primary.

Root cause: deniedByBDRWhenAddColumn in pkg/ddl/bdr.go checks allowed option combinations but misses the case where both ColumnOptionNull and ColumnOptionDefaultValue are present (tpLen=2, nullable + defaultValue). It only allows tpLen=2 for notNull + defaultValue.

4. What is your TiDB version? (Required)

8.5.5

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.