Skip to content

Commit

Permalink
bug: add_timestamp_column Query result is incorrect #1327
Browse files Browse the repository at this point in the history
  • Loading branch information
wisehead authored and mergify[bot] committed Mar 6, 2023
1 parent 43fcede commit cf31f0a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
16 changes: 16 additions & 0 deletions mysql-test/suite/tianmu/r/alter_column.result
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,20 @@ SELECT * FROM ttb1;
id name age
1 AAA
2 BBB
create table stu(id int primary key, name char(20))engine=tianmu;
insert into stu(id, name) values(1, 'zhang fei');
insert into stu(id, name) values(2, 'zhao yun');
insert into stu(id, name) values(3, 'zhen ji');
insert into stu(id, name) values(4, 'zhou yu');
insert into stu(id, name) values(5, 'zhu ge liang');
insert into stu(id, name) values(6, 'ma chao');
alter table stu add column ctm2 timestamp default current_timestamp();
select id,name,length(ctm2) from stu;
id name length(ctm2)
1 zhang fei 19
2 zhao yun 19
3 zhen ji 19
4 zhou yu 19
5 zhu ge liang 19
6 ma chao 19
DROP DATABASE alter_colunm;
16 changes: 16 additions & 0 deletions mysql-test/suite/tianmu/t/alter_column.test
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,22 @@ SHOW CREATE TABLE ttb1;

SELECT * FROM ttb1;

#################
# ADD timestamp COLUMN with default current_timestam
#################
create table stu(id int primary key, name char(20))engine=tianmu;

insert into stu(id, name) values(1, 'zhang fei');
insert into stu(id, name) values(2, 'zhao yun');
insert into stu(id, name) values(3, 'zhen ji');
insert into stu(id, name) values(4, 'zhou yu');
insert into stu(id, name) values(5, 'zhu ge liang');
insert into stu(id, name) values(6, 'ma chao');

alter table stu add column ctm2 timestamp default current_timestamp();
select id,name,length(ctm2) from stu;


#################
# CLEAR UP
#################
Expand Down
2 changes: 1 addition & 1 deletion storage/tianmu/handler/ha_tianmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1628,7 +1628,7 @@ bool ha_tianmu::check_if_notnull_of_added_column(TABLE *altered_table) {
if (j < old_cols.size()) // column exists
continue;

if ((*new_cols[i]).null_bit == 0)
if ((*new_cols[i]).null_bit == 0 || (*new_cols[i]).has_insert_default_function())
return true;
}

Expand Down

0 comments on commit cf31f0a

Please sign in to comment.