tidb icon indicating copy to clipboard operation
tidb copied to clipboard

The column value changes unexpectedly after DDL

Open lcwangchao opened this issue 1 year ago • 1 comments

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

TiDB [email protected]:test> create table t1(a int);
Query OK, 0 rows affected
Time: 0.121s
TiDB [email protected]:test> insert into t1 values(1);
Query OK, 1 row affected
Time: 0.021s
TiDB [email protected]:test> set @@sql_mode='';
Query OK, 0 rows affected
Time: 0.001s
TiDB [email protected]:test> alter table t1 add column(b tinyint default '11111111');
Query OK, 0 rows affected
Time: 0.354s
TiDB [email protected]:test> select * from t1;
+---+-----+
| a | b   |
+---+-----+
| 1 | 127 |
+---+-----+
1 row in set
Time: 0.013s
TiDB [email protected]:test> alter table t1 modify column b bigint;
Query OK, 0 rows affected
Time: 0.090s
TiDB [email protected]:test> select * from t1;
+---+----------+
| a | b        |
+---+----------+
| 1 | 11111111 |
+---+----------+
1 row in set
Time: 0.011s

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

We should get the same result before and after DDL.

3. What did you see instead (Required)

They are not same

4. What is your TiDB version? (Required)

lcwangchao avatar Feb 26 '24 08:02 lcwangchao

Case1:

set @@sql_mode='STRICT_TRANS_TABLES';
drop table if exists t1;
create table t1(a int);
insert into t1 values(1);
alter table t1 add column(b tinyint default '11111111');

Case2:

set @@sql_mode='';
drop table if exists t1;
create table t1(a int);
insert into t1 values(1);
alter table t1 add column(b tinyint default '11111111');

Now the TiDB behaviors:

  • When the @@sql_mode is STRICT_TRANS_TABLES(Case1) the result is Invalid default value for 'b'.
  • When the @@sql_mode is ''(Case2) the result is successful.

Now the MySQL(8.0.18 MySQL) behaviors:

  • In Both cases the result is Invalid default value for 'b'.

zimulala avatar Apr 28 '24 10:04 zimulala