diff --git a/dbms/src/Storages/Transaction/RegionBlockReader.cpp b/dbms/src/Storages/Transaction/RegionBlockReader.cpp index fc9d2606de5..5f173438dd7 100644 --- a/dbms/src/Storages/Transaction/RegionBlockReader.cpp +++ b/dbms/src/Storages/Transaction/RegionBlockReader.cpp @@ -305,9 +305,7 @@ std::tuple 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()); } } diff --git a/dbms/src/Storages/Transaction/TiDB.cpp b/dbms/src/Storages/Transaction/TiDB.cpp index 3dab150619a..d827580bcff 100644 --- a/dbms/src/Storages/Transaction/TiDB.cpp +++ b/dbms/src/Storages/Transaction/TiDB.cpp @@ -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 @@ -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) diff --git a/tests/fullstack-test/ddl/default_value.test b/tests/fullstack-test/ddl/default_value.test new file mode 100644 index 00000000000..4a2dfeb71c0 --- /dev/null +++ b/tests/fullstack-test/ddl/default_value.test @@ -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 | ++------+------+------+