Skip to content

Commit

Permalink
[flash 1030]fix bug of default value (#546) (#594)
Browse files Browse the repository at this point in the history
* fix problem of default value

* fix hint

* address comments

* fix test

Co-authored-by: Fei Han <[email protected]>
  • Loading branch information
sre-bot and hanfei1991 authored Apr 1, 2020
1 parent 73c9aaf commit 4097ed4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
4 changes: 1 addition & 3 deletions dbms/src/Storages/Transaction/RegionBlockReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,7 @@ std::tuple<Block, bool> readRegionBlock(const TableInfo & table_info,
}

// not null or has no default value, tidb will fill with specific value.
decoded_data.emplace_back(column_info.id,
column_info.hasNoDefaultValueFlag() ? (column_info.hasNotNullFlag() ? GenDefaultField(column_info) : Field())
: column_info.defaultValueToField());
decoded_data.emplace_back(column_info.id, column_info.defaultValueToField());
}
}

Expand Down
4 changes: 4 additions & 0 deletions dbms/src/Storages/Transaction/TiDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace DB
{
extern const UInt8 TYPE_CODE_LITERAL;
extern const UInt8 LITERAL_NIL;
Field GenDefaultField(const TiDB::ColumnInfo & col_info);
} // namespace DB

namespace TiDB
Expand All @@ -22,11 +23,14 @@ using DB::Field;

ColumnInfo::ColumnInfo(Poco::JSON::Object::Ptr json) { deserialize(json); }


Field ColumnInfo::defaultValueToField() const
{
auto & value = origin_default_value;
if (value.isEmpty())
{
if (hasNotNullFlag())
return DB::GenDefaultField(*this);
return Field();
}
switch (tp)
Expand Down
26 changes: 26 additions & 0 deletions tests/fullstack-test/ddl/default_value.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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);
mysql> alter table test.t add column b year not null;

func> wait_table test t

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

mysql> alter table test.t add column c year not null;
mysql> set session tidb_isolation_read_engines='tiflash'; select /*+ read_from_storage(tiflash[t]) */ * from test.t;
+------+------+------+
| a | b | c |
+------+------+------+
| 1 | 2000 | 2000 |
| 1 | 2000 | 2000 |
+------+------+------+

0 comments on commit 4097ed4

Please sign in to comment.