From f7a0fd847b7ea7916699673ccec3f3a3d1a18e10 Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Tue, 17 May 2022 19:53:14 +0800 Subject: [PATCH 1/9] add a try catch statement for convert Poco::Dynamic::Var to Int64 Signed-off-by: Lloyd-Pottiger --- dbms/src/Storages/Transaction/TiDB.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/dbms/src/Storages/Transaction/TiDB.cpp b/dbms/src/Storages/Transaction/TiDB.cpp index 763dcac39fc..275df3f50dd 100644 --- a/dbms/src/Storages/Transaction/TiDB.cpp +++ b/dbms/src/Storages/Transaction/TiDB.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -110,14 +111,19 @@ Field ColumnInfo::defaultValueToField() const } switch (tp) { - // TODO: Consider unsigned? // Integer Type. case TypeTiny: case TypeShort: case TypeLong: case TypeLongLong: case TypeInt24: - return value.convert(); + { + try { + return value.convert(); + } catch (...) { + return static_cast(std::stoull(value.convert())); + } + } case TypeBit: { // TODO: We shall use something like `orig_default_bit`, which will never change once created, From 6f0c1f198e4140e6a2cf83268f83263a8df75437 Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Tue, 17 May 2022 19:55:27 +0800 Subject: [PATCH 2/9] remove useless include Signed-off-by: Lloyd-Pottiger --- dbms/src/Storages/Transaction/TiDB.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/dbms/src/Storages/Transaction/TiDB.cpp b/dbms/src/Storages/Transaction/TiDB.cpp index 275df3f50dd..10e5b8b5680 100644 --- a/dbms/src/Storages/Transaction/TiDB.cpp +++ b/dbms/src/Storages/Transaction/TiDB.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include From bd35f5f32c7d79678fefd534e848ee3bed742a47 Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Tue, 17 May 2022 19:56:49 +0800 Subject: [PATCH 3/9] fix remove mistakenly Signed-off-by: Lloyd-Pottiger --- dbms/src/Storages/Transaction/TiDB.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbms/src/Storages/Transaction/TiDB.cpp b/dbms/src/Storages/Transaction/TiDB.cpp index 10e5b8b5680..c22d8a11187 100644 --- a/dbms/src/Storages/Transaction/TiDB.cpp +++ b/dbms/src/Storages/Transaction/TiDB.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include From 279ee2e170fd58b61b793a0df8e4adef81093568 Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Wed, 18 May 2022 15:08:13 +0800 Subject: [PATCH 4/9] format --- dbms/src/Storages/Transaction/TiDB.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dbms/src/Storages/Transaction/TiDB.cpp b/dbms/src/Storages/Transaction/TiDB.cpp index c22d8a11187..7cf87240e61 100644 --- a/dbms/src/Storages/Transaction/TiDB.cpp +++ b/dbms/src/Storages/Transaction/TiDB.cpp @@ -117,9 +117,12 @@ Field ColumnInfo::defaultValueToField() const case TypeLongLong: case TypeInt24: { - try { + try + { return value.convert(); - } catch (...) { + } + catch (...) + { return static_cast(std::stoull(value.convert())); } } From 334a0487cc9f5e331d7afb4bcac3fb79b1442b27 Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Fri, 27 May 2022 12:33:04 +0800 Subject: [PATCH 5/9] fix Signed-off-by: Lloyd-Pottiger --- dbms/src/Storages/Transaction/TiDB.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dbms/src/Storages/Transaction/TiDB.cpp b/dbms/src/Storages/Transaction/TiDB.cpp index 7cf87240e61..2115fbb0c7c 100644 --- a/dbms/src/Storages/Transaction/TiDB.cpp +++ b/dbms/src/Storages/Transaction/TiDB.cpp @@ -25,6 +25,7 @@ #include #include #include +#include namespace DB { @@ -108,8 +109,10 @@ Field ColumnInfo::defaultValueToField() const return DB::GenDefaultField(*this); return Field(); } + // switch (tp) { + // TODO: Consider unsigned? // Integer Type. case TypeTiny: case TypeShort: @@ -123,7 +126,9 @@ Field ColumnInfo::defaultValueToField() const } catch (...) { - return static_cast(std::stoull(value.convert())); + // 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: From d8b3baf5de456b8c91534b23ffe548e214dd8098 Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Fri, 27 May 2022 12:34:30 +0800 Subject: [PATCH 6/9] remove useless comment Signed-off-by: Lloyd-Pottiger --- dbms/src/Storages/Transaction/TiDB.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/dbms/src/Storages/Transaction/TiDB.cpp b/dbms/src/Storages/Transaction/TiDB.cpp index 2115fbb0c7c..d32bc37df77 100644 --- a/dbms/src/Storages/Transaction/TiDB.cpp +++ b/dbms/src/Storages/Transaction/TiDB.cpp @@ -109,7 +109,6 @@ Field ColumnInfo::defaultValueToField() const return DB::GenDefaultField(*this); return Field(); } - // switch (tp) { // TODO: Consider unsigned? From e239ead3e196dbdb8d3b40c1f4c27ca0f8fe5716 Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Fri, 27 May 2022 14:37:27 +0800 Subject: [PATCH 7/9] add comments for unsigned Signed-off-by: Lloyd-Pottiger --- dbms/src/Storages/Transaction/TiDB.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dbms/src/Storages/Transaction/TiDB.cpp b/dbms/src/Storages/Transaction/TiDB.cpp index d32bc37df77..c83c7b5826e 100644 --- a/dbms/src/Storages/Transaction/TiDB.cpp +++ b/dbms/src/Storages/Transaction/TiDB.cpp @@ -111,7 +111,6 @@ Field ColumnInfo::defaultValueToField() const } switch (tp) { - // TODO: Consider unsigned? // Integer Type. case TypeTiny: case TypeShort: @@ -119,6 +118,10 @@ Field ColumnInfo::defaultValueToField() const 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(); From 9dbac99d80de823b98559146d559ae3c20f988e2 Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Fri, 27 May 2022 16:40:14 +0800 Subject: [PATCH 8/9] format --- dbms/src/Storages/Transaction/TiDB.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/dbms/src/Storages/Transaction/TiDB.cpp b/dbms/src/Storages/Transaction/TiDB.cpp index c83c7b5826e..e869bec606f 100644 --- a/dbms/src/Storages/Transaction/TiDB.cpp +++ b/dbms/src/Storages/Transaction/TiDB.cpp @@ -25,6 +25,7 @@ #include #include #include + #include namespace DB From ee0b1430f01cabc6f4e06cf44bd2e93fd1c266dc Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Fri, 27 May 2022 17:55:53 +0800 Subject: [PATCH 9/9] clear tidy --- dbms/src/Storages/Transaction/TiDB.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/dbms/src/Storages/Transaction/TiDB.cpp b/dbms/src/Storages/Transaction/TiDB.cpp index e869bec606f..3810e25372f 100644 --- a/dbms/src/Storages/Transaction/TiDB.cpp +++ b/dbms/src/Storages/Transaction/TiDB.cpp @@ -631,6 +631,8 @@ catch (const Poco::Exception & e) /////////////////////// IndexColumnInfo::IndexColumnInfo(Poco::JSON::Object::Ptr json) + : offset() + , length() { deserialize(json); } @@ -680,6 +682,13 @@ catch (const Poco::Exception & e) /////////////////////// IndexInfo::IndexInfo(Poco::JSON::Object::Ptr json) + : id() + , state() + , index_type() + , is_unique() + , is_primary() + , is_invisible() + , is_global() { deserialize(json); }