From 2774dae862e8d5961f3dd816c9d7d6cfb4a0e512 Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger <60744015+Lloyd-Pottiger@users.noreply.github.com> Date: Fri, 27 May 2022 19:24:48 +0800 Subject: [PATCH 1/3] This is an automated cherry-pick of #4916 Signed-off-by: ti-chi-bot --- dbms/src/Storages/Transaction/TiDB.cpp | 61 ++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/dbms/src/Storages/Transaction/TiDB.cpp b/dbms/src/Storages/Transaction/TiDB.cpp index 36b18764fcb..e1da7144981 100644 --- a/dbms/src/Storages/Transaction/TiDB.cpp +++ b/dbms/src/Storages/Transaction/TiDB.cpp @@ -10,6 +10,8 @@ #include #include +#include + namespace DB { extern const UInt8 TYPE_CODE_LITERAL; @@ -45,6 +47,7 @@ Field ColumnInfo::defaultValueToField() const } switch (tp) { +<<<<<<< HEAD // TODO: Consider unsigned? // Integer Type. case TypeTiny: @@ -54,6 +57,41 @@ Field ColumnInfo::defaultValueToField() const case TypeInt24: return value.convert(); case TypeBit: +======= + // Integer Type. + case TypeTiny: + case TypeShort: + case TypeLong: + case TypeLongLong: + case TypeInt24: + { + // In c++, cast a unsigned integer to signed integer will not change the value. + // like 9223372036854775808 which is larger than the maximum value of Int64, + // static_cast(static_cast(9223372036854775808)) == 9223372036854775808 + // so we don't need consider unsigned here. + try + { + return value.convert(); + } + catch (...) + { + // due to https://github.com/pingcap/tidb/issues/34881 + // we do this to avoid exception in older version of TiDB. + return static_cast(std::llround(value.convert())); + } + } + case TypeBit: + { + // TODO: We shall use something like `orig_default_bit`, which will never change once created, + // rather than `default_bit`, which could be altered. + // See https://github.com/pingcap/tidb/issues/17641 and https://github.com/pingcap/tidb/issues/17642 + const auto & bit_value = default_bit_value; + // TODO: There might be cases that `orig_default` is not null but `default_bit` is null, + // i.e. bit column added with an default value but later modified to another. + // For these cases, neither `orig_default` (may get corrupted) nor `default_bit` (modified) is correct. + // This is a bug anyway, we choose to make it simple, i.e. use `default_bit`. + if (bit_value.isEmpty()) +>>>>>>> ca3e1c6be8 (Fix an invalid default value cause bootstrap failed (#4916)) { // TODO: We shall use something like `orig_default_bit`, which will never change once created, // rather than `default_bit`, which could be altered. @@ -531,7 +569,16 @@ catch (const Poco::Exception & e) /// IndexColumnInfo /// /////////////////////// +<<<<<<< HEAD IndexColumnInfo::IndexColumnInfo(Poco::JSON::Object::Ptr json) { deserialize(json); } +======= +IndexColumnInfo::IndexColumnInfo(Poco::JSON::Object::Ptr json) + : offset() + , length() +{ + deserialize(json); +} +>>>>>>> ca3e1c6be8 (Fix an invalid default value cause bootstrap failed (#4916)) Poco::JSON::Object::Ptr IndexColumnInfo::getJSONObject() const try @@ -575,7 +622,21 @@ catch (const Poco::Exception & e) ////// IndexInfo ////// /////////////////////// +<<<<<<< HEAD IndexInfo::IndexInfo(Poco::JSON::Object::Ptr json) { deserialize(json); } +======= +IndexInfo::IndexInfo(Poco::JSON::Object::Ptr json) + : id() + , state() + , index_type() + , is_unique() + , is_primary() + , is_invisible() + , is_global() +{ + deserialize(json); +} +>>>>>>> ca3e1c6be8 (Fix an invalid default value cause bootstrap failed (#4916)) Poco::JSON::Object::Ptr IndexInfo::getJSONObject() const try { From 282a5b42d0cc78bf972209788d850e4bce957ca2 Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Thu, 8 Dec 2022 19:55:38 +0800 Subject: [PATCH 2/3] fix Signed-off-by: Lloyd-Pottiger --- dbms/src/Storages/Transaction/TiDB.cpp | 76 ++++++-------------------- 1 file changed, 16 insertions(+), 60 deletions(-) diff --git a/dbms/src/Storages/Transaction/TiDB.cpp b/dbms/src/Storages/Transaction/TiDB.cpp index ae4ebf2920a..2a05432b92a 100644 --- a/dbms/src/Storages/Transaction/TiDB.cpp +++ b/dbms/src/Storages/Transaction/TiDB.cpp @@ -47,7 +47,6 @@ Field ColumnInfo::defaultValueToField() const } switch (tp) { -<<<<<<< HEAD // TODO: Consider unsigned? // Integer Type. case TypeTiny: @@ -55,43 +54,23 @@ Field ColumnInfo::defaultValueToField() const case TypeLong: case TypeLongLong: case TypeInt24: - return value.convert(); - case TypeBit: -======= - // Integer Type. - case TypeTiny: - case TypeShort: - case TypeLong: - case TypeLongLong: - case TypeInt24: - { - // In c++, cast a unsigned integer to signed integer will not change the value. - // like 9223372036854775808 which is larger than the maximum value of Int64, - // static_cast(static_cast(9223372036854775808)) == 9223372036854775808 - // so we don't need consider unsigned here. - try - { - return value.convert(); - } - catch (...) { - // due to https://github.com/pingcap/tidb/issues/34881 - // we do this to avoid exception in older version of TiDB. - return static_cast(std::llround(value.convert())); + // In c++, cast a unsigned integer to signed integer will not change the value. + // like 9223372036854775808 which is larger than the maximum value of Int64, + // static_cast(static_cast(9223372036854775808)) == 9223372036854775808 + // so we don't need consider unsigned here. + try + { + return value.convert(); + } + catch (...) + { + // due to https://github.com/pingcap/tidb/issues/34881 + // we do this to avoid exception in older version of TiDB. + return static_cast(std::llround(value.convert())); + } } - } - case TypeBit: - { - // TODO: We shall use something like `orig_default_bit`, which will never change once created, - // rather than `default_bit`, which could be altered. - // See https://github.com/pingcap/tidb/issues/17641 and https://github.com/pingcap/tidb/issues/17642 - const auto & bit_value = default_bit_value; - // TODO: There might be cases that `orig_default` is not null but `default_bit` is null, - // i.e. bit column added with an default value but later modified to another. - // For these cases, neither `orig_default` (may get corrupted) nor `default_bit` (modified) is correct. - // This is a bug anyway, we choose to make it simple, i.e. use `default_bit`. - if (bit_value.isEmpty()) ->>>>>>> ca3e1c6be8 (Fix an invalid default value cause bootstrap failed (#4916)) + case TypeBit: { // TODO: We shall use something like `orig_default_bit`, which will never change once created, // rather than `default_bit`, which could be altered. @@ -572,16 +551,7 @@ catch (const Poco::Exception & e) /// IndexColumnInfo /// /////////////////////// -<<<<<<< HEAD IndexColumnInfo::IndexColumnInfo(Poco::JSON::Object::Ptr json) { deserialize(json); } -======= -IndexColumnInfo::IndexColumnInfo(Poco::JSON::Object::Ptr json) - : offset() - , length() -{ - deserialize(json); -} ->>>>>>> ca3e1c6be8 (Fix an invalid default value cause bootstrap failed (#4916)) Poco::JSON::Object::Ptr IndexColumnInfo::getJSONObject() const try @@ -625,21 +595,7 @@ catch (const Poco::Exception & e) ////// IndexInfo ////// /////////////////////// -<<<<<<< HEAD IndexInfo::IndexInfo(Poco::JSON::Object::Ptr json) { deserialize(json); } -======= -IndexInfo::IndexInfo(Poco::JSON::Object::Ptr json) - : id() - , state() - , index_type() - , is_unique() - , is_primary() - , is_invisible() - , is_global() -{ - deserialize(json); -} ->>>>>>> ca3e1c6be8 (Fix an invalid default value cause bootstrap failed (#4916)) Poco::JSON::Object::Ptr IndexInfo::getJSONObject() const try { @@ -1037,4 +993,4 @@ ColumnInfo fieldTypeToColumnInfo(const tipb::FieldType & field_type) return ret; } -} // namespace TiDB +} // namespace TiDB \ No newline at end of file From 771b864b068234f447635c9c3b5e16ae23a4cfac Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Thu, 8 Dec 2022 22:10:38 +0800 Subject: [PATCH 3/3] fix Signed-off-by: Lloyd-Pottiger --- dbms/src/Storages/DeltaMerge/File/DMFilePackFilter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbms/src/Storages/DeltaMerge/File/DMFilePackFilter.h b/dbms/src/Storages/DeltaMerge/File/DMFilePackFilter.h index de2cd5e3bc1..ef793697ab3 100644 --- a/dbms/src/Storages/DeltaMerge/File/DMFilePackFilter.h +++ b/dbms/src/Storages/DeltaMerge/File/DMFilePackFilter.h @@ -164,7 +164,7 @@ class DMFilePackFilter after_filter += u; ProfileEvents::increment(ProfileEvents::DMFileFilterAftRoughSet, after_filter); - Float64 filter_rate = (Float64)(after_read_packs - after_filter) * 100 / after_read_packs; + Float64 filter_rate = static_cast(after_read_packs - after_filter) * 100 / after_read_packs; LOG_DEBUG(log, "RSFilter exclude rate: " << ((after_read_packs == 0) ? "nan" : DB::toString(filter_rate, 2)) << ", after_pk: " << after_pk << ", after_read_packs: " << after_read_packs