matrixone icon indicating copy to clipboard operation
matrixone copied to clipboard

[Bug]: Alter table ADD COLUMN NOT NULL with default value does not set null flag correctly.

Open fengttt opened this issue 9 months ago • 0 comments

Is there an existing issue for the same bug?

  • [X] I have checked the existing issues.

Branch Name

main

Commit ID

62bc77f5f

Other Environment Information

- Hardware parameters:
- OS type:
- Others:

Actual Behavior

mysql> alter table t add column yy text not null default 'foo';
Query OK, 0 rows affected (0.01 sec)

mysql> desc t
    -> ;
+-------+---------------+------+------+---------+-------+---------+
| Field | Type          | Null | Key  | Default | Extra | Comment |
+-------+---------------+------+------+---------+-------+---------+
| id    | INT(32)       | NO   | PRI  | NULL    |       |         |
| i     | INT(32)       | YES  |      | NULL    |       |         |
| j     | INT(32)       | YES  |      | NULL    |       |         |
| t     | TEXT(0)       | YES  |      | NULL    |       |         |
| e     | ENUM('Y','N') | YES  |      | 'Y'     |       |         |
| x     | INT(32)       | NO   |      | NULL    |       |         |
| y     | TEXT(0)       | NO   |      | NULL    |       |         |
| yy    | TEXT(0)       | YES  |      | 'foo'   |       |         |
+-------+---------------+------+------+---------+-------+---------+
8 rows in set (0.01 sec)

Expected Behavior

Note that column yy should be NOT NULL, that is, Null column should be NO.

Aslo I checked that I can insert a value into t with yy as null.

alter table modify column does not work either.

Query OK, 1 row affected (0.01 sec)

mysql> select * from t;
+------+------+------+------+------+------+------+------+
| id   | i    | j    | t    | e    | x    | y    | yy   |
+------+------+------+------+------+------+------+------+
|    3 |    3 |    3 | foo  | NULL |    2 | bar  | NULL |
|    1 |    1 |    1 | foo  | NULL |    0 |      | foo  |
+------+------+------+------+------+------+------+------+
2 rows in set (0.01 sec)

mysql>

Steps to Reproduce

create table t (id int not null primary key, i int, j int, t text);

alter table t add column e enum('Y', 'N') not null default 'Y';

desc t;

Additional information

No response

fengttt avatar May 13 '24 16:05 fengttt