Skip to content

Commit cf31f0a

Browse files
wiseheadmergify[bot]
authored andcommitted
bug: add_timestamp_column Query result is incorrect #1327
1 parent 43fcede commit cf31f0a

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

mysql-test/suite/tianmu/r/alter_column.result

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,20 @@ SELECT * FROM ttb1;
9898
id name age
9999
1 AAA
100100
2 BBB
101+
create table stu(id int primary key, name char(20))engine=tianmu;
102+
insert into stu(id, name) values(1, 'zhang fei');
103+
insert into stu(id, name) values(2, 'zhao yun');
104+
insert into stu(id, name) values(3, 'zhen ji');
105+
insert into stu(id, name) values(4, 'zhou yu');
106+
insert into stu(id, name) values(5, 'zhu ge liang');
107+
insert into stu(id, name) values(6, 'ma chao');
108+
alter table stu add column ctm2 timestamp default current_timestamp();
109+
select id,name,length(ctm2) from stu;
110+
id name length(ctm2)
111+
1 zhang fei 19
112+
2 zhao yun 19
113+
3 zhen ji 19
114+
4 zhou yu 19
115+
5 zhu ge liang 19
116+
6 ma chao 19
101117
DROP DATABASE alter_colunm;

mysql-test/suite/tianmu/t/alter_column.test

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,22 @@ SHOW CREATE TABLE ttb1;
111111

112112
SELECT * FROM ttb1;
113113

114+
#################
115+
# ADD timestamp COLUMN with default current_timestam
116+
#################
117+
create table stu(id int primary key, name char(20))engine=tianmu;
118+
119+
insert into stu(id, name) values(1, 'zhang fei');
120+
insert into stu(id, name) values(2, 'zhao yun');
121+
insert into stu(id, name) values(3, 'zhen ji');
122+
insert into stu(id, name) values(4, 'zhou yu');
123+
insert into stu(id, name) values(5, 'zhu ge liang');
124+
insert into stu(id, name) values(6, 'ma chao');
125+
126+
alter table stu add column ctm2 timestamp default current_timestamp();
127+
select id,name,length(ctm2) from stu;
128+
129+
114130
#################
115131
# CLEAR UP
116132
#################

storage/tianmu/handler/ha_tianmu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1628,7 +1628,7 @@ bool ha_tianmu::check_if_notnull_of_added_column(TABLE *altered_table) {
16281628
if (j < old_cols.size()) // column exists
16291629
continue;
16301630

1631-
if ((*new_cols[i]).null_bit == 0)
1631+
if ((*new_cols[i]).null_bit == 0 || (*new_cols[i]).has_insert_default_function())
16321632
return true;
16331633
}
16341634

0 commit comments

Comments
 (0)