From 2e8e7d52c38221389fb89c0c498b4e8459fbefac Mon Sep 17 00:00:00 2001 From: Roman Nozdrin Date: Thu, 5 Mar 2020 03:27:17 +0000 Subject: [PATCH] Renamed datatypes/decimal.* into csdecimal to avoid collision with MDB. --- CMakeLists.txt | 3 +- datatypes/CMakeLists.txt | 2 +- datatypes/csdecimal.cpp | 30 ++++++ datatypes/{decimal.h => csdecimal.h} | 9 +- dbcon/execplan/CMakeLists.txt | 2 +- dbcon/execplan/treenode.h | 98 ++++++++++++++++---- dbcon/mysql/ha_mcs_impl.cpp | 4 +- datatypes/decimal.cpp => tests/csdecimal.cpp | 7 +- utils/common/columnwidth.h | 6 +- 9 files changed, 133 insertions(+), 28 deletions(-) create mode 100644 datatypes/csdecimal.cpp rename datatypes/{decimal.h => csdecimal.h} (84%) rename datatypes/decimal.cpp => tests/csdecimal.cpp (89%) diff --git a/CMakeLists.txt b/CMakeLists.txt index d4fe952ad..abd646c2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -200,12 +200,11 @@ ENDIF() SET (ENGINE_LDFLAGS "-Wl,--no-as-needed -Wl,--add-needed") -SET (ENGINE_COMMON_LIBS messageqcpp loggingcpp configcpp idbboot ${Boost_LIBRARIES} xml2 pthread rt libmysql_client) +SET (ENGINE_COMMON_LIBS messageqcpp loggingcpp configcpp idbboot ${Boost_LIBRARIES} xml2 pthread rt libmysql_client datatypes) SET (ENGINE_OAM_LIBS oamcpp alarmmanager) SET (ENGINE_BRM_LIBS brm idbdatafile cacheutils rwlock ${ENGINE_OAM_LIBS} ${ENGINE_COMMON_LIBS}) SET (ENGINE_EXEC_LIBS joblist execplan windowfunction joiner rowgroup funcexp udfsdk regr dataconvert common compress querystats querytele thrift threadpool ${ENGINE_BRM_LIBS}) SET (ENGINE_WRITE_LIBS ddlpackageproc ddlpackage dmlpackageproc dmlpackage writeengine writeengineclient idbdatafile cacheutils ${ENGINE_EXEC_LIBS}) -SET (ENGINE_DATATYPES_LIBS datatypes) SET (ENGINE_COMMON_LDFLAGS "") diff --git a/datatypes/CMakeLists.txt b/datatypes/CMakeLists.txt index 433cefa5c..c9616b1e6 100644 --- a/datatypes/CMakeLists.txt +++ b/datatypes/CMakeLists.txt @@ -1,7 +1,7 @@ include_directories( ${ENGINE_COMMON_INCLUDES} ) set(datatypes_LIB_SRCS - decimal.cpp) + csdecimal.cpp) add_library(datatypes SHARED ${datatypes_LIB_SRCS}) diff --git a/datatypes/csdecimal.cpp b/datatypes/csdecimal.cpp new file mode 100644 index 000000000..7f961f4ce --- /dev/null +++ b/datatypes/csdecimal.cpp @@ -0,0 +1,30 @@ +/* Copyright (C) 2020 MariaDB Corporation + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; version 2 of + the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. */ + +#include "csdecimal.h" + +const datatypes::Decimal someDecimal; + +namespace datatypes +{ + + int Decimal::compare(const execplan::IDB_Decimal& l, const execplan::IDB_Decimal& r) + { + return 0; + } + +} // end of namespace diff --git a/datatypes/decimal.h b/datatypes/csdecimal.h similarity index 84% rename from datatypes/decimal.h rename to datatypes/csdecimal.h index 104c4db5c..a567ce252 100644 --- a/datatypes/decimal.h +++ b/datatypes/csdecimal.h @@ -18,14 +18,21 @@ #ifndef H_DECIMALDATATYPE #define H_DECIMALDATATYPE +#include + +namespace execplan +{ + struct IDB_Decimal; +} + namespace datatypes { - class Decimal { public: Decimal() { }; ~Decimal() { }; + static int compare(const execplan::IDB_Decimal& l, const execplan::IDB_Decimal& r); }; } //end of namespace diff --git a/dbcon/execplan/CMakeLists.txt b/dbcon/execplan/CMakeLists.txt index 8b7911838..2a1c759a2 100755 --- a/dbcon/execplan/CMakeLists.txt +++ b/dbcon/execplan/CMakeLists.txt @@ -1,5 +1,5 @@ -include_directories( ${ENGINE_COMMON_INCLUDES} ${ENGINE_UTILS_UDFSDK_INCLUDE} ) +include_directories( ${ENGINE_COMMON_INCLUDES} ${ENGINE_UTILS_UDFSDK_INCLUDE} ${ENGINE_DATATYPES_INCLUDE}) ########### next target ############### diff --git a/dbcon/execplan/treenode.h b/dbcon/execplan/treenode.h index 6448d12e2..1c2f6b05a 100644 --- a/dbcon/execplan/treenode.h +++ b/dbcon/execplan/treenode.h @@ -35,6 +35,8 @@ #include "calpontsystemcatalog.h" #include "exceptclasses.h" #include "dataconvert.h" +#include "columnwidth.h" +#include "csdecimal.h" using int128_t = __int128; @@ -116,45 +118,105 @@ struct IDB_Decimal bool operator==(const IDB_Decimal& rhs) const { - if (scale == rhs.scale) - return value == rhs.value; + if (utils::widthByPrecision(precision) == 16) + { + if (scale == rhs.scale) + return s128Value == rhs.s128Value; + else + return (datatypes::Decimal::compare(*this, rhs) == 0); + } else - return (decimalComp(rhs) == 0); + { + if (scale == rhs.scale) + return value == rhs.value; + else + return (decimalComp(rhs) == 0); + } } bool operator>(const IDB_Decimal& rhs) const { - if (scale == rhs.scale) - return value > rhs.value; + if (utils::widthByPrecision(precision) == 16) + { + if (scale == rhs.scale) + return s128Value > rhs.s128Value; + else + return (datatypes::Decimal::compare(*this, rhs) > 0); + } else - return (decimalComp(rhs) > 0); + { + if (scale == rhs.scale) + return value > rhs.value; + else + return (decimalComp(rhs) > 0); + } } bool operator<(const IDB_Decimal& rhs) const { - if (scale == rhs.scale) - return value < rhs.value; + if (utils::widthByPrecision(precision) == 16) + { + if (scale == rhs.scale) + return s128Value < rhs.s128Value; + else + return (datatypes::Decimal::compare(*this, rhs) < 0); + } else - return (decimalComp(rhs) < 0); + { + if (scale == rhs.scale) + return value < rhs.value; + else + return (decimalComp(rhs) < 0); + } } bool operator>=(const IDB_Decimal& rhs) const { - if (scale == rhs.scale) - return value >= rhs.value; + if (utils::widthByPrecision(precision) == 16) + { + if (scale == rhs.scale) + return s128Value >= rhs.s128Value; + else + return (datatypes::Decimal::compare(*this, rhs) >= 0); + } else - return (decimalComp(rhs) >= 0); + { + if (scale == rhs.scale) + return value >= rhs.value; + else + return (decimalComp(rhs) >= 0); + } } bool operator<=(const IDB_Decimal& rhs) const { - if (scale == rhs.scale) - return value <= rhs.value; + if (utils::widthByPrecision(precision) == 16) + { + if (scale == rhs.scale) + return s128Value <= rhs.s128Value; + else + return (datatypes::Decimal::compare(*this, rhs) <= 0); + } else - return (decimalComp(rhs) <= 0); + { + if (scale == rhs.scale) + return value <= rhs.value; + else + return (decimalComp(rhs) <= 0); + } } bool operator!=(const IDB_Decimal& rhs) const { - if (scale == rhs.scale) - return value != rhs.value; + if (utils::widthByPrecision(precision) == 16) + { + if (scale == rhs.scale) + return s128Value != rhs.s128Value; + else + return (datatypes::Decimal::compare(*this, rhs) != 0); + } else - return (decimalComp(rhs) != 0); + { + if (scale == rhs.scale) + return value != rhs.value; + else + return (decimalComp(rhs) != 0); + } } int128_t s128Value; diff --git a/dbcon/mysql/ha_mcs_impl.cpp b/dbcon/mysql/ha_mcs_impl.cpp index fa2c4a77d..e798ead3f 100644 --- a/dbcon/mysql/ha_mcs_impl.cpp +++ b/dbcon/mysql/ha_mcs_impl.cpp @@ -143,10 +143,10 @@ namespace cal_impl_if extern bool nonConstFunc(Item_func* ifp); } +using int128_t = __int128; + namespace { - using int128_t = __int128; - using uint128_t = unsigned __int128; // Calpont vtable non-support error message const string infinidb_autoswitch_warning = "The query includes syntax that is not supported by MariaDB Columnstore distributed mode. The execution was switched to standard mode with downgraded performance."; diff --git a/datatypes/decimal.cpp b/tests/csdecimal.cpp similarity index 89% rename from datatypes/decimal.cpp rename to tests/csdecimal.cpp index e5c44d395..91bddcd42 100644 --- a/datatypes/decimal.cpp +++ b/tests/csdecimal.cpp @@ -15,6 +15,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "decimal.h" +#include "gtest/gtest.h" -const datatypes::Decimal someDecimal; +TEST(DataConvertTest, Strtoll128) +{ + EXPECT_TRUE(true); +} diff --git a/utils/common/columnwidth.h b/utils/common/columnwidth.h index 7d5865514..9d02a7312 100644 --- a/utils/common/columnwidth.h +++ b/utils/common/columnwidth.h @@ -18,6 +18,7 @@ #ifndef UTILS_COLWIDTH_H #define UTILS_COLWIDTH_H +#include "branchpred.h" namespace utils { @@ -34,10 +35,12 @@ namespace utils return width <= MAXLEGACYWIDTH; } - // WIP MCOL-641 Replace with template /** @brief Map a DECIMAL precision to data width in bytes */ inline uint8_t widthByPrecision(unsigned p) { + if (LIKELY(p > 18 && p < 39)) + return 16; + switch (p) { case 1: @@ -70,6 +73,7 @@ namespace utils return 16; } } + inline uint8_t precisionByWidth(unsigned w) { switch(w)