Skip to content

Commit

Permalink
[flash-1018]fix bug of datetime default value (#534) (#536)
Browse files Browse the repository at this point in the history
* fix bug of datetime default value

Co-authored-by: Fei Han <[email protected]>
  • Loading branch information
sre-bot and hanfei1991 authored Mar 20, 2020
1 parent 1ab053a commit 45df0d1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
7 changes: 6 additions & 1 deletion dbms/src/Storages/Transaction/SchemaBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ inline void setAlterCommandColumn(Logger * log, AlterCommand & command, const Co
if (!column_info.origin_default_value.isEmpty())
{
LOG_DEBUG(log, "add default value for column: " << column_info.name);
auto arg0 = std::make_shared<ASTLiteral>(column_info.defaultValueToField());
ASTPtr arg0;
// If it's date time types, we should use string literal to generate default value.
if (column_info.tp == TypeDatetime || column_info.tp == TypeTimestamp || column_info.tp == TypeDate)
arg0 = std::make_shared<ASTLiteral>(Field(column_info.origin_default_value.convert<String>()));
else
arg0 = std::make_shared<ASTLiteral>(column_info.defaultValueToField());
auto arg1 = std::make_shared<ASTLiteral>(command.data_type->getName());
auto args = std::make_shared<ASTExpressionList>();
args->children.emplace_back(arg0);
Expand Down
36 changes: 36 additions & 0 deletions tests/fullstack-test/ddl/datetime_default_value.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
mysql> drop table if exists test.t
mysql> create table test.t(a int)
mysql> alter table test.t set tiflash replica 1
mysql> insert into test.t (a) values (1);
mysql> insert into test.t (a) values (1);

SLEEP 15


>> DBGInvoke __try_flush()

mysql> set session tidb_isolation_read_engines='tiflash'; select /*+ read_from_storage(tiflash[t]) */ * from test.t;
+------+
| a |
+------+
| 1 |
| 1 |
+------+

mysql> alter table test.t add column b datetime default '8124-05-31 23:47:33';
mysql> set session tidb_isolation_read_engines='tiflash'; select /*+ read_from_storage(t) */ * from test.t;
+------+---------------------+
| a | b |
+------+---------------------+
| 1 | 8124-05-31 23:47:33 |
| 1 | 8124-05-31 23:47:33 |
+------+---------------------+

mysql> alter table test.t add column c datetime default 19910905;
mysql> set session tidb_isolation_read_engines='tiflash'; select /*+ read_from_storage(t) */ * from test.t;
+------+---------------------+---------------------+
| a | b | c |
+------+---------------------+---------------------+
| 1 | 8124-05-31 23:47:33 | 1991-09-05 00:00:00 |
| 1 | 8124-05-31 23:47:33 | 1991-09-05 00:00:00 |
+------+---------------------+---------------------+

0 comments on commit 45df0d1

Please sign in to comment.