diff --git a/CMakeLists.txt b/CMakeLists.txt index c1b49e0a1..a05c92d5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -283,11 +283,13 @@ SET (ENGINE_WE_CONFIGCPP_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/writeengine/x SET (ENGINE_SERVER_SQL_INCLUDE "${SERVER_SOURCE_ROOT_DIR}/sql") SET (ENGINE_SERVER_INCLUDE_INCLUDE "${SERVER_SOURCE_ROOT_DIR}/include") SET (ENGINE_SERVER_PCRE_INCLUDE "${SERVER_BUILD_INCLUDE_DIR}/../pcre") +SET (ENGINE_SERVER_WSREP_INCLUDE "${SERVER_BUILD_INCLUDE_DIR}/../wsrep-lib/include") +SET (ENGINE_SERVER_WSREP_API_INCLUDE "${SERVER_BUILD_INCLUDE_DIR}/../wsrep-lib/wsrep-API/v26/") SET (ENGINE_UTILS_UDFSDK_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/utils/udfsdk") SET (ENGINE_DEFAULT_INCLUDES ${CMAKE_BINARY_DIR} "." "../" "../../" ${SERVER_BUILD_INCLUDE_DIR}) -SET (ENGINE_COMMON_INCLUDES ${ENGINE_DEFAULT_INCLUDES} ${Boost_INCLUDE_DIR} ${LIBXML2_INCLUDE_DIR} ${ENGINE_UTILS_MESSAGEQCPP_INCLUDE} ${ENGINE_WE_SHARED_INCLUDE} ${ENGINE_UTILS_IDBDATAFILE_INCLUDE} ${ENGINE_UTILS_LOGGINGCPP_INCLUDE} ${ENGINE_UTILS_CONFIGCPP_INCLUDE} ${ENGINE_UTILS_COMPRESS_INCLUDE} ${ENGINE_VERSIONING_BRM_INCLUDE} ${ENGINE_UTILS_ROWGROUP_INCLUDE} ${ENGINE_UTILS_COMMON_INCLUDE} ${ENGINE_UTILS_DATACONVERT_INCLUDE} ${ENGINE_UTILS_RWLOCK_INCLUDE} ${ENGINE_UTILS_FUNCEXP_INCLUDE} ${ENGINE_OAMAPPS_ALARMMANAGER_INCLUDE} ${ENGINE_UTILS_INCLUDE} ${ENGINE_OAM_OAMCPP_INCLUDE} ${ENGINE_DBCON_DDLPKGPROC_INCLUDE} ${ENGINE_DBCON_DDLPKG_INCLUDE} ${ENGINE_DBCON_EXECPLAN_INCLUDE} ${ENGINE_UTILS_STARTUP_INCLUDE} ${ENGINE_DBCON_JOBLIST_INCLUDE} ${ENGINE_WE_WRAPPER_INCLUDE} ${ENGINE_WE_SERVER_INCLUDE} ${ENGINE_DBCON_DMLPKG_INCLUDE} ${ENGINE_WE_CLIENT_INCLUDE} ${ENGINE_DBCON_DMLPKGPROC_INCLUDE} ${ENGINE_UTILS_CACHEUTILS_INCLUDE} ${ENGINE_UTILS_MYSQLCL_INCLUDE} ${ENGINE_UTILS_QUERYTELE_INCLUDE} ${ENGINE_UTILS_THRIFT_INCLUDE} ${ENGINE_UTILS_JOINER_INCLUDE} ${ENGINE_UTILS_THREADPOOL_INCLUDE} ${ENGINE_UTILS_BATCHLDR_INCLUDE} ${ENGINE_UTILS_DDLCLEANUP_INCLUDE} ${ENGINE_UTILS_QUERYSTATS_INCLUDE} ${ENGINE_WE_CONFIGCPP_INCLUDE} ${ENGINE_SERVER_SQL_INCLUDE} ${ENGINE_SERVER_INCLUDE_INCLUDE} ${ENGINE_SERVER_PCRE_INCLUDE} ${ENGINE_UTILS_UDFSDK_INCLUDE} ${ENGINE_UTILS_LIBMYSQL_CL_INCLUDE}) +SET (ENGINE_COMMON_INCLUDES ${ENGINE_DEFAULT_INCLUDES} ${Boost_INCLUDE_DIR} ${LIBXML2_INCLUDE_DIR} ${ENGINE_UTILS_MESSAGEQCPP_INCLUDE} ${ENGINE_WE_SHARED_INCLUDE} ${ENGINE_UTILS_IDBDATAFILE_INCLUDE} ${ENGINE_UTILS_LOGGINGCPP_INCLUDE} ${ENGINE_UTILS_CONFIGCPP_INCLUDE} ${ENGINE_UTILS_COMPRESS_INCLUDE} ${ENGINE_VERSIONING_BRM_INCLUDE} ${ENGINE_UTILS_ROWGROUP_INCLUDE} ${ENGINE_UTILS_COMMON_INCLUDE} ${ENGINE_UTILS_DATACONVERT_INCLUDE} ${ENGINE_UTILS_RWLOCK_INCLUDE} ${ENGINE_UTILS_FUNCEXP_INCLUDE} ${ENGINE_OAMAPPS_ALARMMANAGER_INCLUDE} ${ENGINE_UTILS_INCLUDE} ${ENGINE_OAM_OAMCPP_INCLUDE} ${ENGINE_DBCON_DDLPKGPROC_INCLUDE} ${ENGINE_DBCON_DDLPKG_INCLUDE} ${ENGINE_DBCON_EXECPLAN_INCLUDE} ${ENGINE_UTILS_STARTUP_INCLUDE} ${ENGINE_DBCON_JOBLIST_INCLUDE} ${ENGINE_WE_WRAPPER_INCLUDE} ${ENGINE_WE_SERVER_INCLUDE} ${ENGINE_DBCON_DMLPKG_INCLUDE} ${ENGINE_WE_CLIENT_INCLUDE} ${ENGINE_DBCON_DMLPKGPROC_INCLUDE} ${ENGINE_UTILS_CACHEUTILS_INCLUDE} ${ENGINE_UTILS_MYSQLCL_INCLUDE} ${ENGINE_UTILS_QUERYTELE_INCLUDE} ${ENGINE_UTILS_THRIFT_INCLUDE} ${ENGINE_UTILS_JOINER_INCLUDE} ${ENGINE_UTILS_THREADPOOL_INCLUDE} ${ENGINE_UTILS_BATCHLDR_INCLUDE} ${ENGINE_UTILS_DDLCLEANUP_INCLUDE} ${ENGINE_UTILS_QUERYSTATS_INCLUDE} ${ENGINE_WE_CONFIGCPP_INCLUDE} ${ENGINE_SERVER_SQL_INCLUDE} ${ENGINE_SERVER_INCLUDE_INCLUDE} ${ENGINE_SERVER_PCRE_INCLUDE} ${ENGINE_SERVER_WSREP_API_INCLUDE} ${ENGINE_SERVER_WSREP_INCLUDE} ${ENGINE_UTILS_UDFSDK_INCLUDE} ${ENGINE_UTILS_LIBMYSQL_CL_INCLUDE}) ADD_SUBDIRECTORY(utils) ADD_SUBDIRECTORY(oam/oamcpp) diff --git a/README b/README index bc8efde2c..5163c1d34 100644 --- a/README +++ b/README @@ -1,9 +1,9 @@ -This is MariaDB ColumnStore 1.2 -MariaDB ColumnStore 1.2 is the GA version of MariaDB ColumnStore. -It is built by porting InfiniDB 4.6.7 on MariaDB 10.2 and adding entirely +This is MariaDB ColumnStore 1.4 +MariaDB ColumnStore 1.4 is the GA version of MariaDB ColumnStore. +It is built by porting InfiniDB 4.6.7 on MariaDB and adding entirely new features not found anywhere else. -MariaDB ColumnStore 1.2 is a GA. +MariaDB ColumnStore 1.4 is a Alpha. Additional features will be pushed in future releases. A few things to notice: diff --git a/dbcon/ddlpackage/CMakeLists.txt b/dbcon/ddlpackage/CMakeLists.txt index 084aeeac0..8bdc68b1e 100644 --- a/dbcon/ddlpackage/CMakeLists.txt +++ b/dbcon/ddlpackage/CMakeLists.txt @@ -11,9 +11,6 @@ ADD_CUSTOM_COMMAND( set_source_files_properties(ddl-scan.cpp PROPERTIES COMPILE_FLAGS -Wno-sign-compare) -# Parser puts extra info to stderr. -MY_CHECK_AND_SET_COMPILER_FLAG("-DYYDEBUG=1" DEBUG) - ########### next target ############### ADD_LIBRARY(ddlpackage SHARED diff --git a/dbcon/ddlpackageproc/createtableprocessor.cpp b/dbcon/ddlpackageproc/createtableprocessor.cpp index 1b66c9092..db1e8d088 100644 --- a/dbcon/ddlpackageproc/createtableprocessor.cpp +++ b/dbcon/ddlpackageproc/createtableprocessor.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/dmlpackage/dml.y b/dbcon/dmlpackage/dml.y index b26319c0b..73dcf26ea 100644 --- a/dbcon/dmlpackage/dml.y +++ b/dbcon/dmlpackage/dml.y @@ -566,17 +566,11 @@ assignment_commalist: assignment: column COMPARISON scalar_exp { - $$ = new ColumnAssignment(); - $$->fColumn = $1; - $$->fOperator = $2; - $$->fScalarExpression = $3; + $$ = new ColumnAssignment($1, $2, $3); } | column COMPARISON NULLX { - $$ = new ColumnAssignment(); - $$->fColumn = $1; - $$->fOperator = $2; - $$->fScalarExpression = $3; + $$ = new ColumnAssignment($1, $2, $3); } ; diff --git a/dbcon/dmlpackage/dmlpkg.h b/dbcon/dmlpackage/dmlpkg.h index 477e0f608..f7377f8a3 100644 --- a/dbcon/dmlpackage/dmlpkg.h +++ b/dbcon/dmlpackage/dmlpkg.h @@ -409,6 +409,14 @@ public: class ColumnAssignment { public: + explicit ColumnAssignment( + std::string const& column, + std::string const& op = "=", + std::string const& expr = "") : + fColumn(column), fOperator(op), fScalarExpression(expr), + fFromCol(false), fFuncScale(0), fIsNull(false) + {}; + /** @brief dump to stdout */ std::ostream& put(std::ostream& os) const; @@ -423,6 +431,7 @@ public: std::string fScalarExpression; bool fFromCol; uint32_t fFuncScale; + bool fIsNull; }; /** @brief Stores a value list or a query specification diff --git a/dbcon/dmlpackage/updatedmlpackage.cpp b/dbcon/dmlpackage/updatedmlpackage.cpp index a68e42fba..23b42a8dd 100644 --- a/dbcon/dmlpackage/updatedmlpackage.cpp +++ b/dbcon/dmlpackage/updatedmlpackage.cpp @@ -259,7 +259,8 @@ void UpdateDMLPackage::buildUpdateFromMysqlBuffer(UpdateSqlStatement& updateStm while (iter != updateStmt.fColAssignmentListPtr->end()) { ColumnAssignment* colaPtr = *iter; - DMLColumn* colPtr = new DMLColumn(colaPtr->fColumn, colaPtr->fScalarExpression, colaPtr->fFromCol, colaPtr->fFuncScale); + DMLColumn* colPtr = new DMLColumn(colaPtr->fColumn, colaPtr->fScalarExpression, colaPtr->fFromCol, colaPtr->fFuncScale, + colaPtr->fIsNull); rowPtr->get_ColumnList().push_back(colPtr); ++iter; diff --git a/dbcon/execplan/aggregatecolumn.cpp b/dbcon/execplan/aggregatecolumn.cpp index 8583459da..3d7825dcb 100644 --- a/dbcon/execplan/aggregatecolumn.cpp +++ b/dbcon/execplan/aggregatecolumn.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/execplan/aggregatecolumn.h b/dbcon/execplan/aggregatecolumn.h index 0825f00ff..20b049dad 100644 --- a/dbcon/execplan/aggregatecolumn.h +++ b/dbcon/execplan/aggregatecolumn.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/execplan/arithmeticcolumn.cpp b/dbcon/execplan/arithmeticcolumn.cpp index aab6c9265..2128a47ed 100644 --- a/dbcon/execplan/arithmeticcolumn.cpp +++ b/dbcon/execplan/arithmeticcolumn.cpp @@ -326,7 +326,8 @@ void ArithmeticColumn::serialize(messageqcpp::ByteStream& b) const ObjectReader::writeParseTree(fExpression, b); b << fTableAlias; b << fData; - b << static_cast(fAsc); + const ByteStream::doublebyte tmp = fAsc; + b << tmp; } void ArithmeticColumn::unserialize(messageqcpp::ByteStream& b) @@ -340,7 +341,9 @@ void ArithmeticColumn::unserialize(messageqcpp::ByteStream& b) fExpression = ObjectReader::createParseTree(b); b >> fTableAlias; b >> fData; - b >> reinterpret_cast< ByteStream::doublebyte&>(fAsc); + ByteStream::doublebyte tmp; + b >> tmp; + fAsc = (tmp); fSimpleColumnList.clear(); fExpression->walk(getSimpleCols, &fSimpleColumnList); diff --git a/dbcon/execplan/arithmeticcolumn.h b/dbcon/execplan/arithmeticcolumn.h index d7e895969..2dfed7349 100644 --- a/dbcon/execplan/arithmeticcolumn.h +++ b/dbcon/execplan/arithmeticcolumn.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/execplan/arithmeticoperator.h b/dbcon/execplan/arithmeticoperator.h index cc6cc70da..7277ccd65 100644 --- a/dbcon/execplan/arithmeticoperator.h +++ b/dbcon/execplan/arithmeticoperator.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/execplan/calpontselectexecutionplan.h b/dbcon/execplan/calpontselectexecutionplan.h index 3e4eedcbf..e21cd96bb 100644 --- a/dbcon/execplan/calpontselectexecutionplan.h +++ b/dbcon/execplan/calpontselectexecutionplan.h @@ -548,6 +548,10 @@ public: return fDerivedTbAlias; } + void derivedTbView(const std::string derivedTbView) { fDerivedTbView = derivedTbView; } + const std::string derivedTbView() const { return fDerivedTbView; } + + void limitStart(const uint64_t limitStart) { fLimitStart = limitStart; @@ -870,6 +874,7 @@ private: // for subselect uint64_t fSubType; std::string fDerivedTbAlias; + std::string fDerivedTbView; // for limit uint64_t fLimitStart; diff --git a/dbcon/execplan/calpontsystemcatalog.cpp b/dbcon/execplan/calpontsystemcatalog.cpp index 234fb6235..aa369e005 100644 --- a/dbcon/execplan/calpontsystemcatalog.cpp +++ b/dbcon/execplan/calpontsystemcatalog.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -269,28 +269,28 @@ const CalpontSystemCatalog::TableName make_table(const string& s, const string& return tn; } -const CalpontSystemCatalog::TableAliasName make_aliastable(const string& s, const string& t, const string& a, const bool isInfiniDB) +const CalpontSystemCatalog::TableAliasName make_aliastable(const string& s, const string& t, const string& a, const bool isColumnStore) { CalpontSystemCatalog::TableAliasName tn; tn.schema = s; tn.table = t; tn.alias = a; tn.view = ""; - tn.fIsInfiniDB = isInfiniDB; + tn.fisColumnStore = isColumnStore; transform (tn.schema.begin(), tn.schema.end(), tn.schema.begin(), to_lower()); transform (tn.table.begin(), tn.table.end(), tn.table.begin(), to_lower()); transform (tn.alias.begin(), tn.alias.end(), tn.alias.begin(), to_lower()); return tn; } -const CalpontSystemCatalog::TableAliasName make_aliasview(const string& s, const string& t, const string& a, const string& v, const bool isInfiniDB) +const CalpontSystemCatalog::TableAliasName make_aliasview(const string& s, const string& t, const string& a, const string& v, const bool isColumnStore) { CalpontSystemCatalog::TableAliasName tn; tn.schema = s; tn.table = t; tn.alias = a; tn.view = v; - tn.fIsInfiniDB = isInfiniDB; + tn.fisColumnStore = isColumnStore; transform (tn.schema.begin(), tn.schema.end(), tn.schema.begin(), to_lower()); transform (tn.table.begin(), tn.table.end(), tn.table.begin(), to_lower()); transform (tn.alias.begin(), tn.alias.end(), tn.alias.begin(), to_lower()); @@ -380,7 +380,7 @@ bool CalpontSystemCatalog::TableAliasName::operator<(const TableAliasName& rhs) } else if (view == rhs.view) { - if (fIsInfiniDB < rhs.fIsInfiniDB) + if (fisColumnStore < rhs.fisColumnStore) return true; } } @@ -396,7 +396,7 @@ void CalpontSystemCatalog::TableAliasName::serialize(messageqcpp::ByteStream& b) b << table; b << alias; b << view; - b << static_cast(fIsInfiniDB); + b << static_cast(fisColumnStore); } void CalpontSystemCatalog::TableAliasName::unserialize(messageqcpp::ByteStream& b) @@ -405,7 +405,7 @@ void CalpontSystemCatalog::TableAliasName::unserialize(messageqcpp::ByteStream& b >> table; b >> alias; b >> view; - b >> reinterpret_cast< ByteStream::doublebyte&>(fIsInfiniDB); + b >> reinterpret_cast< ByteStream::doublebyte&>(fisColumnStore); } /*static*/ @@ -5649,7 +5649,7 @@ const string CalpontSystemCatalog::TableName::toString() const ostream& operator<<(ostream& os, const CalpontSystemCatalog::TableAliasName& rhs) { os << rhs.schema << '.' << rhs.table << "(" << rhs.alias << "/" << rhs.view - << ") engineType=" << (rhs.fIsInfiniDB ? "Columnstore" : "ForeignEngine"); + << ") engineType=" << (rhs.fisColumnStore ? "ColumnStore" : "ForeignEngine"); return os; } diff --git a/dbcon/execplan/calpontsystemcatalog.h b/dbcon/execplan/calpontsystemcatalog.h index 188dae4e6..50248eb13 100644 --- a/dbcon/execplan/calpontsystemcatalog.h +++ b/dbcon/execplan/calpontsystemcatalog.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -429,16 +429,16 @@ public: */ struct TableAliasName { - TableAliasName (): fIsInfiniDB (true) {} + TableAliasName (): fisColumnStore (true) {} TableAliasName (std::string sch, std::string tb, std::string al) : - schema (sch), table (tb), alias (al), fIsInfiniDB(true) {} + schema (sch), table (tb), alias (al), fisColumnStore(true) {} TableAliasName (std::string sch, std::string tb, std::string al, std::string v) : - schema (sch), table (tb), alias (al), view(v), fIsInfiniDB(true) {} + schema (sch), table (tb), alias (al), view(v), fisColumnStore(true) {} std::string schema; std::string table; std::string alias; std::string view; - bool fIsInfiniDB; + bool fisColumnStore; void clear(); bool operator<(const TableAliasName& rhs) const; bool operator>=(const TableAliasName& rhs) const @@ -451,7 +451,7 @@ public: table == rhs.table && alias == rhs.alias && view == rhs.view && - fIsInfiniDB == rhs.fIsInfiniDB); + fisColumnStore == rhs.fisColumnStore); } bool operator!=(const TableAliasName& rhs) const { @@ -962,8 +962,8 @@ const CalpontSystemCatalog::TableColName make_tcn(const std::string& s, const st */ const CalpontSystemCatalog::TableName make_table(const std::string& s, const std::string& t); const CalpontSystemCatalog::TableAliasName make_aliastable(const std::string& s, const std::string& t, const std::string& a, - const bool fIsInfiniDB = true); -const CalpontSystemCatalog::TableAliasName make_aliasview(const std::string& s, const std::string& t, const std::string& a, const std::string& v, const bool fIsInfiniDB = true); + const bool fisColumnStore = true); +const CalpontSystemCatalog::TableAliasName make_aliasview(const std::string& s, const std::string& t, const std::string& a, const std::string& v, const bool fisColumnStore = true); /** convenience function to determine if column type is a char * type diff --git a/dbcon/execplan/constantcolumn.cpp b/dbcon/execplan/constantcolumn.cpp index aa2676816..8b7e9fc42 100644 --- a/dbcon/execplan/constantcolumn.cpp +++ b/dbcon/execplan/constantcolumn.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/execplan/constantcolumn.h b/dbcon/execplan/constantcolumn.h index 51b914be0..bdeb1e014 100644 --- a/dbcon/execplan/constantcolumn.h +++ b/dbcon/execplan/constantcolumn.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/execplan/functioncolumn.cpp b/dbcon/execplan/functioncolumn.cpp index c815a3cb2..03ef4ab39 100644 --- a/dbcon/execplan/functioncolumn.cpp +++ b/dbcon/execplan/functioncolumn.cpp @@ -426,6 +426,16 @@ void FunctionColumn::setDerivedTable() break; } } + // MCOL-3239 Block for func column with both + // derived table column and normal table column. + else if (derivedTableAlias == "") + { + if (sc->tableAlias().length()) + { + derivedTableAlias = ""; + break; + } + } } fDerivedTable = derivedTableAlias; diff --git a/dbcon/execplan/functioncolumn.h b/dbcon/execplan/functioncolumn.h index 99e3c9be7..c8274e087 100644 --- a/dbcon/execplan/functioncolumn.h +++ b/dbcon/execplan/functioncolumn.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/execplan/operator.h b/dbcon/execplan/operator.h index b8d2ab18c..a8119fd6e 100644 --- a/dbcon/execplan/operator.h +++ b/dbcon/execplan/operator.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/execplan/parsetree.h b/dbcon/execplan/parsetree.h index 3561d9dc6..f31a2a013 100644 --- a/dbcon/execplan/parsetree.h +++ b/dbcon/execplan/parsetree.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/execplan/predicateoperator.cpp b/dbcon/execplan/predicateoperator.cpp index 501bd8a73..efd748c99 100644 --- a/dbcon/execplan/predicateoperator.cpp +++ b/dbcon/execplan/predicateoperator.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/execplan/predicateoperator.h b/dbcon/execplan/predicateoperator.h index 75cde2051..02a38efe4 100644 --- a/dbcon/execplan/predicateoperator.h +++ b/dbcon/execplan/predicateoperator.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -36,7 +36,6 @@ #endif #include #include -#include #include "expressionparser.h" #include "returnedcolumn.h" @@ -486,20 +485,16 @@ inline bool PredicateOperator::getBoolVal(rowgroup::Row& row, bool& isNull, Retu return !ret; } - // MCOL-1559 - std::string val1 = lop->getStrVal(row, isNull); if (isNull) return false; - std::string val2 = rop->getStrVal(row, isNull); + const std::string& val1 = lop->getStrVal(row, isNull); + if (isNull) return false; - boost::trim_right_if(val1, boost::is_any_of(" ")); - boost::trim_right_if(val2, boost::is_any_of(" ")); - - return strCompare(val1, val2); - } + return strCompare(val1, rop->getStrVal(row, isNull)) && !isNull; + } //FIXME: ??? case execplan::CalpontSystemCatalog::VARBINARY: diff --git a/dbcon/execplan/pseudocolumn.cpp b/dbcon/execplan/pseudocolumn.cpp index e2303fec4..dcf35596b 100644 --- a/dbcon/execplan/pseudocolumn.cpp +++ b/dbcon/execplan/pseudocolumn.cpp @@ -72,10 +72,10 @@ PseudoColumn::PseudoColumn(const string& schemaName, PseudoColumn::PseudoColumn(const string& schemaName, const string& tableName, const string& columnName, - const bool isInfiniDB, + const bool isColumnStore, const uint32_t pseudoType, const uint32_t sessionID): - SimpleColumn(schemaName, tableName, columnName, isInfiniDB, sessionID), + SimpleColumn(schemaName, tableName, columnName, isColumnStore, sessionID), fPseudoType(pseudoType) { adjustResultType(); @@ -122,7 +122,7 @@ PseudoColumn& PseudoColumn::operator=(const PseudoColumn& rhs) fData = rhs.data(); fSequence = rhs.sequence(); fDistinct = rhs.distinct(); - fIsInfiniDB = rhs.isInfiniDB(); + fisColumnStore = rhs.isColumnStore(); fPseudoType = rhs.pseudoType(); } @@ -155,7 +155,7 @@ const string PseudoColumn::toString() const << cardinality() << '/' << joinInfo() << '/' << colSource() << '/' - << (isInfiniDB() ? "InfiniDB" : "ForeignEngine") << endl; + << (isColumnStore() ? "ColumnStore" : "ForeignEngine") << endl; output << "Pseudotype=" << fPseudoType << endl; return output.str(); diff --git a/dbcon/execplan/pseudocolumn.h b/dbcon/execplan/pseudocolumn.h index 6a48a65d4..55419e8cc 100644 --- a/dbcon/execplan/pseudocolumn.h +++ b/dbcon/execplan/pseudocolumn.h @@ -78,7 +78,7 @@ public: PseudoColumn(const std::string& schema, const std::string& table, const std::string& col, - const bool isInfiniDB, + const bool isColumnStore, const uint32_t pseudoType, const uint32_t sessionID = 0); PseudoColumn(const SimpleColumn& rhs, const uint32_t pseudoType, const uint32_t sessionID = 0); diff --git a/dbcon/execplan/simplecolumn.cpp b/dbcon/execplan/simplecolumn.cpp index 68f09ee26..3c98536b6 100644 --- a/dbcon/execplan/simplecolumn.cpp +++ b/dbcon/execplan/simplecolumn.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -139,7 +139,7 @@ ParseTree* replaceRefCol(ParseTree*& n, CalpontSelectExecutionPlan::ReturnedColu SimpleColumn::SimpleColumn(): ReturnedColumn(), fOid (0), - fIsInfiniDB (true) + fisColumnStore (true) { fDistinct = false; } @@ -148,7 +148,7 @@ SimpleColumn::SimpleColumn(const string& token, const uint32_t sessionID): ReturnedColumn(sessionID), fOid (0), fData(token), - fIsInfiniDB (true) + fisColumnStore (true) { parse (token); setOID(); @@ -163,7 +163,7 @@ SimpleColumn::SimpleColumn(const string& schemaName, fSchemaName (schemaName), fTableName (tableName), fColumnName (columnName), - fIsInfiniDB (true) + fisColumnStore (true) { setOID(); fDistinct = false; @@ -172,15 +172,15 @@ SimpleColumn::SimpleColumn(const string& schemaName, SimpleColumn::SimpleColumn(const string& schemaName, const string& tableName, const string& columnName, - const bool isInfiniDB, + const bool isColumnStore, const uint32_t sessionID): ReturnedColumn(sessionID), fSchemaName (schemaName), fTableName (tableName), fColumnName (columnName), - fIsInfiniDB (isInfiniDB) + fisColumnStore (isColumnStore) { - if (isInfiniDB) + if (isColumnStore) setOID(); fDistinct = false; @@ -197,7 +197,7 @@ SimpleColumn::SimpleColumn (const SimpleColumn& rhs, const uint32_t sessionID): fIndexName (rhs.indexName()), fViewName (rhs.viewName()), fTimeZone (rhs.timeZone()), - fIsInfiniDB (rhs.isInfiniDB()) + fisColumnStore (rhs.isColumnStore()) { } @@ -212,9 +212,9 @@ const string SimpleColumn::data() const if (!fData.empty()) return fData; else if (!fTableAlias.empty()) - return string(fSchemaName + '.' + fTableAlias + '.' + fColumnName); + return string("`" + fSchemaName + "`.`" + fTableAlias + "`.`" + fColumnName + "`"); - return string(fSchemaName + '.' + fTableName + '.' + fColumnName); + return string("`" + fSchemaName + "`.`" + fTableName + "`.`" + fColumnName + "`"); } SimpleColumn& SimpleColumn::operator=(const SimpleColumn& rhs) @@ -234,7 +234,7 @@ SimpleColumn& SimpleColumn::operator=(const SimpleColumn& rhs) fData = rhs.data(); fSequence = rhs.sequence(); fDistinct = rhs.distinct(); - fIsInfiniDB = rhs.isInfiniDB(); + fisColumnStore = rhs.isColumnStore(); } return *this; @@ -264,7 +264,7 @@ const string SimpleColumn::toString() const << cardinality() << '/' << joinInfo() << '/' << colSource() << '/' - << (isInfiniDB() ? "InfiniDB" : "ForeignEngine") << '/' + << (isColumnStore() ? "ColumnStore" : "ForeignEngine") << '/' << colPosition() << endl; return output.str(); @@ -352,7 +352,7 @@ void SimpleColumn::serialize(messageqcpp::ByteStream& b) const b << fData; b << fTableAlias; b << (uint32_t) fSequence; - b << static_cast(fIsInfiniDB); + b << static_cast(fisColumnStore); } void SimpleColumn::unserialize(messageqcpp::ByteStream& b) @@ -369,7 +369,7 @@ void SimpleColumn::unserialize(messageqcpp::ByteStream& b) b >> fData; b >> fTableAlias; b >> (uint32_t&) fSequence; - b >> reinterpret_cast< ByteStream::doublebyte&>(fIsInfiniDB); + b >> reinterpret_cast< ByteStream::doublebyte&>(fisColumnStore); } bool SimpleColumn::operator==(const SimpleColumn& t) const @@ -412,7 +412,7 @@ bool SimpleColumn::operator==(const SimpleColumn& t) const if (fReturnAll != t.fReturnAll) return false; - if (fIsInfiniDB != t.fIsInfiniDB) + if (fisColumnStore != t.fisColumnStore) return false; return true; @@ -452,7 +452,7 @@ bool SimpleColumn::sameColumn(const ReturnedColumn* rc) const fColumnName.compare(sc->columnName()) == 0 && fTableAlias.compare(sc->tableAlias()) == 0 && fViewName.compare(sc->viewName()) == 0 && - fIsInfiniDB == sc->isInfiniDB()); + fisColumnStore == sc->isColumnStore()); } void SimpleColumn::setDerivedTable() diff --git a/dbcon/execplan/simplecolumn.h b/dbcon/execplan/simplecolumn.h index cb63e9683..72f633a25 100644 --- a/dbcon/execplan/simplecolumn.h +++ b/dbcon/execplan/simplecolumn.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -70,7 +70,7 @@ public: SimpleColumn(const std::string& schema, const std::string& table, const std::string& col, - const bool isInfiniDB, + const bool isColumnStore, const uint32_t sessionID = 0); SimpleColumn(const SimpleColumn& rhs, const uint32_t sessionID = 0); @@ -160,13 +160,13 @@ public: { fTimeZone = timeZone; } - inline const bool isInfiniDB() const + inline const bool isColumnStore() const { - return fIsInfiniDB; + return fisColumnStore; } - inline void isInfiniDB(const bool isInfiniDB) + inline void isColumnStore(const bool isColumnStore) { - fIsInfiniDB = isInfiniDB; + fisColumnStore = isColumnStore; } /** return a copy of this pointer @@ -261,7 +261,7 @@ protected: // if belong to view, view name is non-empty std::string fViewName; std::string fTimeZone; - bool fIsInfiniDB; + bool fisColumnStore; /** @brief parse SimpleColumn text * diff --git a/dbcon/execplan/simplecolumn_decimal.h b/dbcon/execplan/simplecolumn_decimal.h index 07d451e4b..c49b597c5 100644 --- a/dbcon/execplan/simplecolumn_decimal.h +++ b/dbcon/execplan/simplecolumn_decimal.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -60,7 +60,7 @@ public: SimpleColumn_Decimal(const std::string& schema, const std::string& table, const std::string& col, - const bool isInfiniDB, + const bool isColumnStore, const uint32_t sessionID = 0); SimpleColumn_Decimal(const SimpleColumn& rhs, const uint32_t sessionID = 0); @@ -107,9 +107,9 @@ template SimpleColumn_Decimal::SimpleColumn_Decimal(const std::string& schema, const std::string& table, const std::string& col, - const bool isInfiniDB, + const bool isColumnStore, const uint32_t sessionID) : - SimpleColumn(schema, table, col, isInfiniDB, sessionID) + SimpleColumn(schema, table, col, isColumnStore, sessionID) { setNullVal(); } diff --git a/dbcon/execplan/simplecolumn_int.h b/dbcon/execplan/simplecolumn_int.h index e39ab9953..9454bba86 100644 --- a/dbcon/execplan/simplecolumn_int.h +++ b/dbcon/execplan/simplecolumn_int.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -58,7 +58,7 @@ public: SimpleColumn_INT(const std::string& schema, const std::string& table, const std::string& col, - const bool isInfiniDB, + const bool isColumnStore, const uint32_t sessionID = 0); SimpleColumn_INT(const SimpleColumn& rhs, const uint32_t sessionID = 0); @@ -106,9 +106,9 @@ template SimpleColumn_INT::SimpleColumn_INT(const std::string& schema, const std::string& table, const std::string& col, - const bool isInfiniDB, + const bool isColumnStore, const uint32_t sessionID) : - SimpleColumn(schema, table, col, isInfiniDB, sessionID) + SimpleColumn(schema, table, col, isColumnStore, sessionID) { setNullVal(); } diff --git a/dbcon/execplan/simplecolumn_uint.h b/dbcon/execplan/simplecolumn_uint.h index 7c9169f75..731242809 100644 --- a/dbcon/execplan/simplecolumn_uint.h +++ b/dbcon/execplan/simplecolumn_uint.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -58,7 +58,7 @@ public: SimpleColumn_UINT(const std::string& schema, const std::string& table, const std::string& col, - const bool isInfiniDB, + const bool isColumnStore, const uint32_t sessionID = 0); SimpleColumn_UINT(const SimpleColumn& rhs, const uint32_t sessionID = 0); @@ -106,9 +106,9 @@ template SimpleColumn_UINT::SimpleColumn_UINT(const std::string& schema, const std::string& table, const std::string& col, - const bool isInfiniDB, + const bool isColumnStore, const uint32_t sessionID) : - SimpleColumn(schema, table, col, isInfiniDB, sessionID) + SimpleColumn(schema, table, col, isColumnStore, sessionID) { setNullVal(); } diff --git a/dbcon/execplan/simplefilter.cpp b/dbcon/execplan/simplefilter.cpp index 5a4fd996d..4916a129c 100644 --- a/dbcon/execplan/simplefilter.cpp +++ b/dbcon/execplan/simplefilter.cpp @@ -470,6 +470,27 @@ bool SimpleFilter::operator==(const SimpleFilter& t) const return true; } +bool SimpleFilter::semanticEq(const SimpleFilter& t) const +{ + if (fOp != NULL) + { + if (*fOp != *t.fOp) + return false; + } + if (fLhs != NULL) + { + if (*fLhs != t.fLhs && *fLhs != *t.fRhs) + return false; + } + if (fRhs != NULL) + { + if (*fRhs != t.fRhs && *fRhs != *t.fLhs) + return false; + } + + return true; +} + bool SimpleFilter::operator==(const TreeNode* t) const { const SimpleFilter* o; diff --git a/dbcon/execplan/simplefilter.h b/dbcon/execplan/simplefilter.h index e448aa3ed..f29d505e3 100644 --- a/dbcon/execplan/simplefilter.h +++ b/dbcon/execplan/simplefilter.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -138,28 +138,36 @@ public: /** @brief Do a deep, strict (as opposed to semantic) equivalence test * * Do a deep, strict (as opposed to semantic) equivalence test. - * @return true iff every member of t is a duplicate copy of every member of this; false otherwise + * @return true if every member of t is a duplicate copy of every member of this; false otherwise */ virtual bool operator==(const TreeNode* t) const; /** @brief Do a deep, strict (as opposed to semantic) equivalence test * * Do a deep, strict (as opposed to semantic) equivalence test. - * @return true iff every member of t is a duplicate copy of every member of this; false otherwise + * @return true if every member of t is a duplicate copy of every member of this; false otherwise */ bool operator==(const SimpleFilter& t) const; + /** @brief Do a semantic equivalence test + * + * Do a semantic equivalence test. + * @return true if filter operation are the same and + * the sets of arguments are the same; false otherwise + */ + bool semanticEq(const SimpleFilter& t) const; + /** @brief Do a deep, strict (as opposed to semantic) equivalence test * * Do a deep, strict (as opposed to semantic) equivalence test. - * @return false iff every member of t is a duplicate copy of every member of this; true otherwise + * @return false if every member of t is a duplicate copy of every member of this; true otherwise */ virtual bool operator!=(const TreeNode* t) const; /** @brief Do a deep, strict (as opposed to semantic) equivalence test * * Do a deep, strict (as opposed to semantic) equivalence test. - * @return false iff every member of t is a duplicate copy of every member of this; true otherwise + * @return false if every member of t is a duplicate copy of every member of this; true otherwise */ bool operator!=(const SimpleFilter& t) const; diff --git a/dbcon/execplan/tdriver-sm.cpp b/dbcon/execplan/tdriver-sm.cpp index 860415471..853909eed 100644 --- a/dbcon/execplan/tdriver-sm.cpp +++ b/dbcon/execplan/tdriver-sm.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/execplan/tdriver.cpp b/dbcon/execplan/tdriver.cpp index 5a8675586..080c54ee7 100644 --- a/dbcon/execplan/tdriver.cpp +++ b/dbcon/execplan/tdriver.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/execplan/treenode.h b/dbcon/execplan/treenode.h index 84d2ccfac..606819dcb 100644 --- a/dbcon/execplan/treenode.h +++ b/dbcon/execplan/treenode.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/execplan/windowfunctioncolumn.cpp b/dbcon/execplan/windowfunctioncolumn.cpp index 09ba50ddc..2316cb510 100644 --- a/dbcon/execplan/windowfunctioncolumn.cpp +++ b/dbcon/execplan/windowfunctioncolumn.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/execplan/windowfunctioncolumn.h b/dbcon/execplan/windowfunctioncolumn.h index 8dee14ece..2d06b735e 100644 --- a/dbcon/execplan/windowfunctioncolumn.h +++ b/dbcon/execplan/windowfunctioncolumn.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/joblist/batchprimitiveprocessor-jl.cpp b/dbcon/joblist/batchprimitiveprocessor-jl.cpp index d8aab62b4..5481a6de9 100644 --- a/dbcon/joblist/batchprimitiveprocessor-jl.cpp +++ b/dbcon/joblist/batchprimitiveprocessor-jl.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/joblist/crossenginestep.cpp b/dbcon/joblist/crossenginestep.cpp index 07ab611e7..bf44e1a6e 100644 --- a/dbcon/joblist/crossenginestep.cpp +++ b/dbcon/joblist/crossenginestep.cpp @@ -731,17 +731,17 @@ void CrossEngineStep::setProjectBPP(JobStep* jobStep1, JobStep*) else fSelectClause += "SELECT "; - fSelectClause += jobStep1->name(); + fSelectClause += "`" + jobStep1->name() + "`"; } std::string CrossEngineStep::makeQuery() { ostringstream oss; - oss << fSelectClause << " FROM " << fTable; + oss << fSelectClause << " FROM `" << fTable << "`"; if (fTable.compare(fAlias) != 0) - oss << " " << fAlias; + oss << " `" << fAlias << "`"; if (!fWhereClause.empty()) oss << fWhereClause; diff --git a/dbcon/joblist/expressionstep.cpp b/dbcon/joblist/expressionstep.cpp index 17dc3d68a..f8020a6c9 100644 --- a/dbcon/joblist/expressionstep.cpp +++ b/dbcon/joblist/expressionstep.cpp @@ -387,7 +387,7 @@ void ExpressionStep::populateColumnInfo(SimpleColumn* sc, JobInfo& jobInfo) sc->oid(tblOid + 1 + sc->colPosition()); ct = sc->resultType(); } - else if (sc->isInfiniDB() == false) + else if (sc->isColumnStore() == false) { ct = sc->colType(); } @@ -515,7 +515,7 @@ void ExpressionStep::updateInputIndex(map& indexMap, const J { ct = sc->resultType(); } - else if (sc->isInfiniDB() == false) + else if (sc->isColumnStore() == false) { ct = sc->colType(); } diff --git a/dbcon/joblist/groupconcat.cpp b/dbcon/joblist/groupconcat.cpp index 1433bd012..3479dd015 100644 --- a/dbcon/joblist/groupconcat.cpp +++ b/dbcon/joblist/groupconcat.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/joblist/jlf_common.cpp b/dbcon/joblist/jlf_common.cpp index bdaa18252..576358ea2 100644 --- a/dbcon/joblist/jlf_common.cpp +++ b/dbcon/joblist/jlf_common.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -378,7 +378,7 @@ CalpontSystemCatalog::OID tableOid(const SimpleColumn* sc, boost::shared_ptrschemaName().empty()) return execplan::CNX_VTABLE_ID; - if (sc->isInfiniDB() == false) + if (sc->isColumnStore() == false) return 0; CalpontSystemCatalog::ROPair p = cat->tableRID(make_table(sc->schemaName(), @@ -386,19 +386,59 @@ CalpontSystemCatalog::OID tableOid(const SimpleColumn* sc, boost::shared_ptr(sc); uint32_t pseudoType = (pc) ? pc->pseudoType() : execplan::PSEUDO_UNKNOWN; - return getTupleKey_(jobInfo, sc->oid(), sc->columnName(), extractTableAlias(sc), - sc->schemaName(), sc->viewName(), - ((sc->joinInfo() & execplan::JOIN_CORRELATED) != 0), - pseudoType, (sc->isInfiniDB() ? 0 : 1)); + + if (sc == NULL) + { + return -1; + } + + if (add) + { + // setTupleInfo first if add is true, ok if already set. + if (sc->schemaName().empty()) + { + SimpleColumn tmp(*sc, jobInfo.sessionId); + tmp.oid(tableOid(sc, jobInfo.csc) + 1 + sc->colPosition()); + key = getTupleKey(jobInfo, &tmp); // sub-query should be there + } + else + { + CalpontSystemCatalog::ColType ct = sc->colType(); + string alias(extractTableAlias(sc)); + CalpontSystemCatalog::OID tblOid = tableOid(sc, jobInfo.csc); + TupleInfo ti(setTupleInfo(ct, sc->oid(), jobInfo, tblOid, sc, alias)); + key = ti.key; + + + CalpontSystemCatalog::OID dictOid = isDictCol(ct); + + if (dictOid > 0) + { + ti = setTupleInfo(ct, dictOid, jobInfo, tblOid, sc, alias); + jobInfo.keyInfo->dictKeyMap[key] = ti.key; + key = ti.key; + } + } + } + else + { + // TupleInfo is expected to be set already + return getTupleKey_(jobInfo, sc->oid(), sc->columnName(), extractTableAlias(sc), + sc->schemaName(), sc->viewName(), + ((sc->joinInfo() & execplan::JOIN_CORRELATED) != 0), + pseudoType, (sc->isColumnStore() ? 0 : 1)); + } + + return key; } - - + uint32_t getTupleKey(JobInfo& jobInfo, const SRCP& srcp, bool add) { int key = -1; @@ -503,7 +543,7 @@ uint32_t makeTableKey(JobInfo& jobInfo, const execplan::SimpleColumn* sc) { CalpontSystemCatalog::OID o = tableOid(sc, jobInfo.csc); return uniqTupleKey(jobInfo, o, o, "", "", sc->tableName(), extractTableAlias(sc), - sc->schemaName(), sc->viewName(), 0, (sc->isInfiniDB() ? 0 : 1), + sc->schemaName(), sc->viewName(), 0, (sc->isColumnStore() ? 0 : 1), ((sc->joinInfo() & execplan::JOIN_CORRELATED) != 0)); } @@ -561,7 +601,7 @@ TupleInfo setTupleInfo(const execplan::CalpontSystemCatalog::ColType& ct, return setTupleInfo_(ct, col_oid, jobInfo, tbl_oid, sc->columnName(), sc->alias(), sc->schemaName(), sc->tableName(), alias, sc->viewName(), ((sc->joinInfo() & execplan::JOIN_CORRELATED) != 0), - pseudoType, (sc->isInfiniDB() ? 0 : 1)); + pseudoType, (sc->isColumnStore() ? 0 : 1)); } @@ -608,7 +648,7 @@ uint32_t getExpTupleKey(const JobInfo& jobInfo, uint64_t eid, bool cr) } -void addAggregateColumn(AggregateColumn* agc, int idx, RetColsVector& vec, JobInfo& jobInfo) +void addAggregateColumn(ReturnedColumn* agc, int idx, RetColsVector& vec, JobInfo& jobInfo) { uint32_t eid = agc->expressionId(); setExpTupleInfo(agc->resultType(), eid, agc->alias(), jobInfo); diff --git a/dbcon/joblist/jlf_common.h b/dbcon/joblist/jlf_common.h index 76538eef9..6d8456a4b 100644 --- a/dbcon/joblist/jlf_common.h +++ b/dbcon/joblist/jlf_common.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -402,8 +402,9 @@ execplan::CalpontSystemCatalog::OID tableOid(const execplan::SimpleColumn* sc, /** @brief Returns the unique ID to be used in tupleInfo * */ -uint32_t getTupleKey(const JobInfo& jobInfo, - const execplan::SimpleColumn* sc); +uint32_t getTupleKey(JobInfo& jobInfo, + const execplan::SimpleColumn* sc, + bool add = false); uint32_t getTableKey(const JobInfo& jobInfo, execplan::CalpontSystemCatalog::OID tableOid, const std::string& alias, @@ -465,7 +466,7 @@ TupleInfo setExpTupleInfo(const execplan::ReturnedColumn* rc, JobInfo& jobInfo); /** @brief add an aggregate column info * */ -void addAggregateColumn(execplan::AggregateColumn*, int, RetColsVector&, JobInfo&); +void addAggregateColumn(execplan::ReturnedColumn*, int, RetColsVector&, JobInfo&); void makeJobSteps(execplan::CalpontSelectExecutionPlan* csep, JobInfo& jobInfo, JobStepVector& querySteps, JobStepVector& projectSteps, diff --git a/dbcon/joblist/jlf_execplantojoblist.cpp b/dbcon/joblist/jlf_execplantojoblist.cpp index 54cfaf726..90d70b9b1 100644 --- a/dbcon/joblist/jlf_execplantojoblist.cpp +++ b/dbcon/joblist/jlf_execplantojoblist.cpp @@ -649,10 +649,10 @@ const JobStepVector doColFilter(const SimpleColumn* sc1, const SimpleColumn* sc2 //XXX use this before connector sets colType in sc correctly. // type of pseudo column is set by connector - if (!sc1->schemaName().empty() && sc1->isInfiniDB() && !pc1) + if (!sc1->schemaName().empty() && sc1->isColumnStore() && !pc1) ct1 = jobInfo.csc->colType(sc1->oid()); - if (!sc2->schemaName().empty() && sc2->isInfiniDB() && !pc2) + if (!sc2->schemaName().empty() && sc2->isColumnStore() && !pc2) ct2 = jobInfo.csc->colType(sc2->oid()); //X @@ -1074,10 +1074,10 @@ const JobStepVector doJoin( //XXX use this before connector sets colType in sc correctly. // type of pseudo column is set by connector - if (!sc1->schemaName().empty() && sc1->isInfiniDB() && !pc1) + if (!sc1->schemaName().empty() && sc1->isColumnStore() && !pc1) ct1 = jobInfo.csc->colType(sc1->oid()); - if (!sc2->schemaName().empty() && sc2->isInfiniDB() && !pc2) + if (!sc2->schemaName().empty() && sc2->isColumnStore() && !pc2) ct2 = jobInfo.csc->colType(sc2->oid()); //X @@ -1341,7 +1341,7 @@ const JobStepVector doSemiJoin(const SimpleColumn* sc, const ReturnedColumn* rc, //XXX use this before connector sets colType in sc correctly. // type of pseudo column is set by connector - if (!sc->schemaName().empty() && sc->isInfiniDB() && !pc1) + if (!sc->schemaName().empty() && sc->isColumnStore() && !pc1) ct1 = jobInfo.csc->colType(sc->oid()); //X @@ -1644,13 +1644,14 @@ const JobStepVector doSimpleFilter(SimpleFilter* sf, JobInfo& jobInfo) string constval(cc->constval()); + CalpontSystemCatalog::OID dictOid = 0; CalpontSystemCatalog::ColType ct = sc->colType(); const PseudoColumn* pc = dynamic_cast(sc); //XXX use this before connector sets colType in sc correctly. // type of pseudo column is set by connector - if (!sc->schemaName().empty() && sc->isInfiniDB() && !pc) + if (!sc->schemaName().empty() && sc->isColumnStore() && !pc) ct = jobInfo.csc->colType(sc->oid()); //X @@ -1902,7 +1903,7 @@ const JobStepVector doSimpleFilter(SimpleFilter* sf, JobInfo& jobInfo) else pcs = new PseudoColStep(sc->oid(), tbl_oid, pc->pseudoType(), ct, jobInfo); - if (sc->isInfiniDB()) + if (sc->isColumnStore()) pcs->addFilter(cop, value, rf); pcs->alias(alias); @@ -2339,7 +2340,7 @@ const JobStepVector doOuterJoinOnFilter(OuterJoinOnFilter* oj, JobInfo& jobInfo) // MCOL-1182 if we are doing a join between a cross engine // step and a constant then keep the filter for the cross // engine step instead of deleting it further down. - if (!sc->isInfiniDB()) + if (!sc->isColumnStore()) { keepFilters = true; } @@ -2724,7 +2725,7 @@ const JobStepVector doConstantFilter(const ConstantFilter* cf, JobInfo& jobInfo) //XXX use this before connector sets colType in sc correctly. // type of pseudo column is set by connector - if (!sc->schemaName().empty() && sc->isInfiniDB() && !pc) + if (!sc->schemaName().empty() && sc->isColumnStore() && !pc) ct = jobInfo.csc->colType(sc->oid()); //X @@ -2950,7 +2951,7 @@ const JobStepVector doConstantFilter(const ConstantFilter* cf, JobInfo& jobInfo) pcs->name(sc->columnName()); pcs->schema(sc->schemaName()); - if (sc->isInfiniDB()) + if (sc->isColumnStore()) { if (op) pcs->setBOP(bop2num(op)); @@ -3001,7 +3002,7 @@ const JobStepVector doConstantFilter(const ConstantFilter* cf, JobInfo& jobInfo) //XXX use this before connector sets colType in sc correctly. CalpontSystemCatalog::ColType ct = sc->colType(); - if (!sc->schemaName().empty() && sc->isInfiniDB() && !pc) + if (!sc->schemaName().empty() && sc->isColumnStore() && !pc) ct = jobInfo.csc->colType(sc->oid()); TupleInfo ti(setTupleInfo(ct, sc->oid(), jobInfo, tblOid, sc.get(), alias)); diff --git a/dbcon/joblist/jlf_subquery.cpp b/dbcon/joblist/jlf_subquery.cpp index a7f99d575..d08f700c4 100644 --- a/dbcon/joblist/jlf_subquery.cpp +++ b/dbcon/joblist/jlf_subquery.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -802,7 +802,7 @@ void addOrderByAndLimit(CalpontSelectExecutionPlan* csep, JobInfo& jobInfo) //XXX use this before connector sets colType in sc correctly. // type of pseudo column is set by connector - if (sc->isInfiniDB() && !(dynamic_cast(sc))) + if (sc->isColumnStore() && !(dynamic_cast(sc))) ct = jobInfo.csc->colType(sc->oid()); //X diff --git a/dbcon/joblist/jlf_tuplejoblist.cpp b/dbcon/joblist/jlf_tuplejoblist.cpp index 5337215d2..b18584d6a 100644 --- a/dbcon/joblist/jlf_tuplejoblist.cpp +++ b/dbcon/joblist/jlf_tuplejoblist.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/joblist/joblist.cpp b/dbcon/joblist/joblist.cpp index bb71996c1..8a8a89065 100644 --- a/dbcon/joblist/joblist.cpp +++ b/dbcon/joblist/joblist.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/joblist/joblist.h b/dbcon/joblist/joblist.h index 3c73eff75..4940e038d 100644 --- a/dbcon/joblist/joblist.h +++ b/dbcon/joblist/joblist.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/joblist/joblistfactory.cpp b/dbcon/joblist/joblistfactory.cpp index 9f2ca5e3e..b4cbafee0 100644 --- a/dbcon/joblist/joblistfactory.cpp +++ b/dbcon/joblist/joblistfactory.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -127,7 +127,7 @@ void projectSimpleColumn(const SimpleColumn* sc, JobStepVector& jsv, JobInfo& jo //XXX use this before connector sets colType in sc correctly. // type of pseudo column is set by connector - if (sc->isInfiniDB() && !pc) + if (sc->isColumnStore() && !pc) ct = jobInfo.csc->colType(sc->oid()); //X @@ -275,9 +275,11 @@ const JobStepVector doProject(const RetColsVector& retCols, JobInfo& jobInfo) if (retCols[i]->windowfunctionColumnList().size() > 0) jobInfo.expressionVec.push_back(key); - else if (find(jobInfo.expressionVec.begin(), jobInfo.expressionVec.end(), key) == - jobInfo.expressionVec.end()) + else if (find(jobInfo.expressionVec.begin(), jobInfo.expressionVec.end(), key) + == jobInfo.expressionVec.end()) + { jobInfo.returnedExpressions.push_back(sjstep); + } //put place hold column in projection list jobInfo.pjColList.push_back(ti); @@ -427,7 +429,7 @@ void preProcessFunctionOnAggregation(const vector& scs, } } - // append the aggregate columns in arithmetic/function cloulmn to the projection list + // append the aggregate columns in arithmetic/function column to the projection list for (vector::const_iterator i = aggs.begin(); i != aggs.end(); i++) { addAggregateColumn(*i, -1, jobInfo.projectionCols, jobInfo); @@ -708,7 +710,7 @@ const JobStepVector doAggProject(const CalpontSelectExecutionPlan* csep, JobInfo ct = sc->colType(); //XXX use this before connector sets colType in sc correctly. - if (sc->isInfiniDB() && dynamic_cast(sc) == NULL) + if (sc->isColumnStore() && dynamic_cast(sc) == NULL) ct = jobInfo.csc->colType(sc->oid()); //X @@ -994,7 +996,7 @@ const JobStepVector doAggProject(const CalpontSelectExecutionPlan* csep, JobInfo ct = sc->colType(); //XXX use this before connector sets colType in sc correctly. - if (sc->isInfiniDB() && dynamic_cast(sc) == NULL) + if (sc->isColumnStore() && dynamic_cast(sc) == NULL) ct = jobInfo.csc->colType(sc->oid()); //X @@ -1043,16 +1045,21 @@ const JobStepVector doAggProject(const CalpontSelectExecutionPlan* csep, JobInfo const FunctionColumn* fc = NULL; const WindowFunctionColumn* wc = NULL; bool hasAggCols = false; + bool hasWndCols = false; if ((ac = dynamic_cast(srcp.get())) != NULL) { if (ac->aggColumnList().size() > 0) hasAggCols = true; + if (ac->windowfunctionColumnList().size() > 0) + hasWndCols = true; } else if ((fc = dynamic_cast(srcp.get())) != NULL) { if (fc->aggColumnList().size() > 0) hasAggCols = true; + if (fc->windowfunctionColumnList().size() > 0) + hasWndCols = true; } else if (dynamic_cast(srcp.get()) != NULL) { @@ -1077,7 +1084,7 @@ const JobStepVector doAggProject(const CalpontSelectExecutionPlan* csep, JobInfo TupleInfo ti(setExpTupleInfo(ct, eid, srcp.get()->alias(), jobInfo)); tupleKey = ti.key; - if (hasAggCols) + if (hasAggCols && !hasWndCols) jobInfo.expressionVec.push_back(tupleKey); } @@ -1142,7 +1149,7 @@ const JobStepVector doAggProject(const CalpontSelectExecutionPlan* csep, JobInfo ct = sc->colType(); //XXX use this before connector sets colType in sc correctly. - if (sc->isInfiniDB() && dynamic_cast(sc) == NULL) + if (sc->isColumnStore() && dynamic_cast(sc) == NULL) ct = jobInfo.csc->colType(sc->oid()); //X @@ -1191,16 +1198,21 @@ const JobStepVector doAggProject(const CalpontSelectExecutionPlan* csep, JobInfo const FunctionColumn* fc = NULL; const WindowFunctionColumn* wc = NULL; bool hasAggCols = false; + bool hasWndCols = false; if ((ac = dynamic_cast(srcp.get())) != NULL) { if (ac->aggColumnList().size() > 0) hasAggCols = true; + if (ac->windowfunctionColumnList().size() > 0) + hasWndCols = true; } else if ((fc = dynamic_cast(srcp.get())) != NULL) { if (fc->aggColumnList().size() > 0) hasAggCols = true; + if (fc->windowfunctionColumnList().size() > 0) + hasWndCols = true; } else if (dynamic_cast(srcp.get()) != NULL) { @@ -1225,7 +1237,7 @@ const JobStepVector doAggProject(const CalpontSelectExecutionPlan* csep, JobInfo TupleInfo ti(setExpTupleInfo(ct, eid, srcp.get()->alias(), jobInfo)); tupleKey = ti.key; - if (hasAggCols) + if (hasAggCols && !hasWndCols) jobInfo.expressionVec.push_back(tupleKey); } @@ -1623,7 +1635,7 @@ void parseExecutionPlan(CalpontSelectExecutionPlan* csep, JobInfo& jobInfo, CalpontSystemCatalog::ColType ct = sc->colType(); //XXX use this before connector sets colType in sc correctly. - if (sc->isInfiniDB() && dynamic_cast(sc) == NULL) + if (sc->isColumnStore() && dynamic_cast(sc) == NULL) ct = jobInfo.csc->colType(sc->oid()); //X @@ -1759,7 +1771,7 @@ void makeJobSteps(CalpontSelectExecutionPlan* csep, JobInfo& jobInfo, if (it->schema.empty()) oid = doFromSubquery(fromSubquery[i++].get(), it->alias, it->view, jobInfo); - else if (it->fIsInfiniDB) + else if (it->fisColumnStore) oid = jobInfo.csc->tableRID(*it).objnum; else oid = 0; diff --git a/dbcon/joblist/joblisttypes.h b/dbcon/joblist/joblisttypes.h index c40c949c1..6d5664c57 100644 --- a/dbcon/joblist/joblisttypes.h +++ b/dbcon/joblist/joblisttypes.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/joblist/largehashjoin.cpp b/dbcon/joblist/largehashjoin.cpp index 4cf911405..9627a50db 100644 --- a/dbcon/joblist/largehashjoin.cpp +++ b/dbcon/joblist/largehashjoin.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/joblist/lbidlist.cpp b/dbcon/joblist/lbidlist.cpp index 9ef9c8a11..631e9a597 100644 --- a/dbcon/joblist/lbidlist.cpp +++ b/dbcon/joblist/lbidlist.cpp @@ -750,7 +750,6 @@ bool LBIDList::CasualPartitionPredicate(const int64_t Min, int64_t tMax = Max; dataconvert::DataConvert::trimWhitespace(tMin); dataconvert::DataConvert::trimWhitespace(tMax); - dataconvert::DataConvert::trimWhitespace(value); scan = compareVal(order_swap(tMin), order_swap(tMax), order_swap(value), op, lcf); diff --git a/dbcon/joblist/primitivestep.h b/dbcon/joblist/primitivestep.h index 588dd49bb..c6e9134ff 100644 --- a/dbcon/joblist/primitivestep.h +++ b/dbcon/joblist/primitivestep.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/joblist/subquerytransformer.cpp b/dbcon/joblist/subquerytransformer.cpp index 1118e92e8..b66bcb310 100644 --- a/dbcon/joblist/subquerytransformer.cpp +++ b/dbcon/joblist/subquerytransformer.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/joblist/tdriver-agg.cpp b/dbcon/joblist/tdriver-agg.cpp index f54831ab4..636d0c86a 100644 --- a/dbcon/joblist/tdriver-agg.cpp +++ b/dbcon/joblist/tdriver-agg.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/joblist/tupleaggregatestep.cpp b/dbcon/joblist/tupleaggregatestep.cpp index 990a694b1..81d190644 100644 --- a/dbcon/joblist/tupleaggregatestep.cpp +++ b/dbcon/joblist/tupleaggregatestep.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -1410,7 +1410,7 @@ void TupleAggregateStep::prep1PhaseAggregate( typeAgg.push_back(CalpontSystemCatalog::LONGDOUBLE); precisionAgg.push_back(-1); widthAgg.push_back(sizeof(long double)); - scaleAgg.push_back(scaleProj[colProj]); + scaleAgg.push_back(0); } break; @@ -1588,8 +1588,8 @@ void TupleAggregateStep::prep1PhaseAggregate( } functionVec[i]->fAuxColumnIndex = lastCol++; - oidsAgg.push_back(oidsAgg[j]); - keysAgg.push_back(keysAgg[j]); + oidsAgg.push_back(oidsProj[j]); + keysAgg.push_back(keysProj[j]); scaleAgg.push_back(0); precisionAgg.push_back(0); precisionAgg.push_back(0); @@ -1604,8 +1604,8 @@ void TupleAggregateStep::prep1PhaseAggregate( functionVec[i]->fAuxColumnIndex = lastCol; // sum(x) - oidsAgg.push_back(oidsAgg[j]); - keysAgg.push_back(keysAgg[j]); + oidsAgg.push_back(oidsProj[j]); + keysAgg.push_back(keysProj[j]); scaleAgg.push_back(0); precisionAgg.push_back(-1); typeAgg.push_back(CalpontSystemCatalog::LONGDOUBLE); @@ -1613,8 +1613,8 @@ void TupleAggregateStep::prep1PhaseAggregate( ++lastCol; // sum(x**2) - oidsAgg.push_back(oidsAgg[j]); - keysAgg.push_back(keysAgg[j]); + oidsAgg.push_back(oidsProj[j]); + keysAgg.push_back(keysProj[j]); scaleAgg.push_back(0); precisionAgg.push_back(-1); typeAgg.push_back(CalpontSystemCatalog::LONGDOUBLE); @@ -1942,7 +1942,7 @@ void TupleAggregateStep::prep1PhaseDistinctAggregate( typeAgg.push_back(CalpontSystemCatalog::LONGDOUBLE); precisionAgg.push_back(-1); widthAgg.push_back(sizeof(long double)); - scaleAgg.push_back(scaleProj[colProj]); + scaleAgg.push_back(0); colAgg++; // has distinct step, put the count column for avg next to the sum @@ -2264,7 +2264,7 @@ void TupleAggregateStep::prep1PhaseDistinctAggregate( typeAggDist.push_back(CalpontSystemCatalog::LONGDOUBLE); precisionAggDist.push_back(-1); widthAggDist.push_back(sizeof(long double)); - scaleAggDist.push_back(scaleProj[colAgg]); + scaleAggDist.push_back(0); } break; @@ -2336,10 +2336,10 @@ void TupleAggregateStep::prep1PhaseDistinctAggregate( { oidsAggDist.push_back(oidsAgg[colAgg]); keysAggDist.push_back(retKey); - scaleAggDist.push_back(scaleAgg[colAgg] >> 8); - precisionAggDist.push_back(precisionAgg[colAgg]); - typeAggDist.push_back(typeAgg[colAgg]); - widthAggDist.push_back(widthAgg[colAgg]); + scaleAggDist.push_back(0); + typeAggDist.push_back(CalpontSystemCatalog::LONGDOUBLE); + precisionAggDist.push_back(-1); + widthAggDist.push_back(sizeof(long double)); } else { @@ -2631,8 +2631,8 @@ void TupleAggregateStep::prep1PhaseDistinctAggregate( functionVec2[i]->fAuxColumnIndex = lastCol; // sum(x) - oidsAggDist.push_back(oidsAggDist[j]); - keysAggDist.push_back(keysAggDist[j]); + oidsAggDist.push_back(oidsAgg[j]); + keysAggDist.push_back(keysAgg[j]); scaleAggDist.push_back(0); precisionAggDist.push_back(0); typeAggDist.push_back(CalpontSystemCatalog::LONGDOUBLE); @@ -2640,8 +2640,8 @@ void TupleAggregateStep::prep1PhaseDistinctAggregate( ++lastCol; // sum(x**2) - oidsAggDist.push_back(oidsAggDist[j]); - keysAggDist.push_back(keysAggDist[j]); + oidsAggDist.push_back(oidsAgg[j]); + keysAggDist.push_back(keysAgg[j]); scaleAggDist.push_back(0); precisionAggDist.push_back(-1); typeAggDist.push_back(CalpontSystemCatalog::LONGDOUBLE); @@ -3188,7 +3188,7 @@ void TupleAggregateStep::prep2PhasesAggregate( oidsAggPm.push_back(oidsProj[colProj]); keysAggPm.push_back(aggKey); typeAggPm.push_back(CalpontSystemCatalog::LONGDOUBLE); - scaleAggPm.push_back(scaleProj[colProj]); + scaleAggPm.push_back(0); precisionAggPm.push_back(-1); widthAggPm.push_back(sizeof(long double)); colAggPm++; @@ -3465,10 +3465,10 @@ void TupleAggregateStep::prep2PhasesAggregate( { oidsAggUm.push_back(oidsAggPm[colPm]); keysAggUm.push_back(retKey); - scaleAggUm.push_back(scaleAggPm[colPm] >> 8); - precisionAggUm.push_back(precisionAggPm[colPm]); - typeAggUm.push_back(typeAggPm[colPm]); - widthAggUm.push_back(widthAggPm[colPm]); + scaleAggUm.push_back(0); + typeAggUm.push_back(CalpontSystemCatalog::LONGDOUBLE); + precisionAggUm.push_back(-1); + widthAggUm.push_back(sizeof(long double)); } else { @@ -3683,8 +3683,8 @@ void TupleAggregateStep::prep2PhasesAggregate( functionVecUm[i]->fAuxColumnIndex = lastCol; // sum(x) - oidsAggUm.push_back(oidsAggUm[j]); - keysAggUm.push_back(keysAggUm[j]); + oidsAggUm.push_back(oidsAggPm[j]); + keysAggUm.push_back(keysAggPm[j]); scaleAggUm.push_back(0); precisionAggUm.push_back(-1); typeAggUm.push_back(CalpontSystemCatalog::LONGDOUBLE); @@ -3692,8 +3692,8 @@ void TupleAggregateStep::prep2PhasesAggregate( ++lastCol; // sum(x**2) - oidsAggUm.push_back(oidsAggUm[j]); - keysAggUm.push_back(keysAggUm[j]); + oidsAggUm.push_back(oidsAggPm[j]); + keysAggUm.push_back(keysAggPm[j]); scaleAggUm.push_back(0); precisionAggUm.push_back(-1); typeAggUm.push_back(CalpontSystemCatalog::LONGDOUBLE); @@ -4046,7 +4046,7 @@ void TupleAggregateStep::prep2PhasesDistinctAggregate( typeAggPm.push_back(CalpontSystemCatalog::LONGDOUBLE); precisionAggPm.push_back(-1); widthAggPm.push_back(sizeof(long double)); - scaleAggPm.push_back(scaleProj[colProj]); + scaleAggPm.push_back(0); colAggPm++; } @@ -4415,7 +4415,7 @@ void TupleAggregateStep::prep2PhasesDistinctAggregate( typeAggDist.push_back(CalpontSystemCatalog::LONGDOUBLE); precisionAggDist.push_back(-1); widthAggDist.push_back(sizeof(long double)); - scaleAggDist.push_back(scaleAggUm[colUm]); + scaleAggDist.push_back(0); } // PM: put the count column for avg next to the sum // let fall through to add a count column for average function @@ -4477,10 +4477,10 @@ void TupleAggregateStep::prep2PhasesDistinctAggregate( { oidsAggDist.push_back(oidsAggUm[colUm]); keysAggDist.push_back(retKey); - scaleAggDist.push_back(scaleAggUm[colUm] >> 8); - precisionAggDist.push_back(precisionAggUm[colUm]); - typeAggDist.push_back(typeAggUm[colUm]); - widthAggDist.push_back(widthAggUm[colUm]); + scaleAggDist.push_back(0); + typeAggDist.push_back(CalpontSystemCatalog::LONGDOUBLE); + precisionAggDist.push_back(-1); + widthAggDist.push_back(sizeof(long double)); } else { @@ -4725,8 +4725,8 @@ void TupleAggregateStep::prep2PhasesDistinctAggregate( functionVecUm[i]->fAuxColumnIndex = lastCol; // sum(x) - oidsAggDist.push_back(oidsAggDist[j]); - keysAggDist.push_back(keysAggDist[j]); + oidsAggDist.push_back(oidsAggPm[j]); + keysAggDist.push_back(keysAggPm[j]); scaleAggDist.push_back(0); precisionAggDist.push_back(-1); typeAggDist.push_back(CalpontSystemCatalog::LONGDOUBLE); @@ -4734,8 +4734,8 @@ void TupleAggregateStep::prep2PhasesDistinctAggregate( ++lastCol; // sum(x**2) - oidsAggDist.push_back(oidsAggDist[j]); - keysAggDist.push_back(keysAggDist[j]); + oidsAggDist.push_back(oidsAggPm[j]); + keysAggDist.push_back(keysAggPm[j]); scaleAggDist.push_back(0); precisionAggDist.push_back(-1); typeAggDist.push_back(CalpontSystemCatalog::LONGDOUBLE); @@ -5038,7 +5038,8 @@ void TupleAggregateStep::prepExpressionOnAggregate(SP_ROWAGG_UM_t& aggUM, JobInf uint64_t eid = -1; if (((ac = dynamic_cast(it->get())) != NULL) && - (ac->aggColumnList().size() > 0)) + (ac->aggColumnList().size() > 0) && + (ac->windowfunctionColumnList().size() == 0)) { const vector& scols = ac->simpleColumnList(); simpleColumns.insert(simpleColumns.end(), scols.begin(), scols.end()); @@ -5047,7 +5048,8 @@ void TupleAggregateStep::prepExpressionOnAggregate(SP_ROWAGG_UM_t& aggUM, JobInf expressionVec.push_back(*it); } else if (((fc = dynamic_cast(it->get())) != NULL) && - (fc->aggColumnList().size() > 0)) + (fc->aggColumnList().size() > 0) && + (fc->windowfunctionColumnList().size() == 0)) { const vector& sCols = fc->simpleColumnList(); simpleColumns.insert(simpleColumns.end(), sCols.begin(), sCols.end()); diff --git a/dbcon/joblist/tupleconstantstep.cpp b/dbcon/joblist/tupleconstantstep.cpp index 02f61eb9c..4ffb811e7 100644 --- a/dbcon/joblist/tupleconstantstep.cpp +++ b/dbcon/joblist/tupleconstantstep.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/joblist/tupleunion.cpp b/dbcon/joblist/tupleunion.cpp index 666b0d514..f3cab8ddf 100644 --- a/dbcon/joblist/tupleunion.cpp +++ b/dbcon/joblist/tupleunion.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/joblist/windowfunctionstep.cpp b/dbcon/joblist/windowfunctionstep.cpp index 610026e33..b145bfa12 100644 --- a/dbcon/joblist/windowfunctionstep.cpp +++ b/dbcon/joblist/windowfunctionstep.cpp @@ -320,6 +320,41 @@ const string WindowFunctionStep::toString() const return oss.str(); } +void WindowFunctionStep::AddSimplColumn(const vector& scs, + JobInfo& jobInfo) +{ + // append the simple columns if not already projected + set scProjected; + + for (RetColsVector::iterator i = jobInfo.projectionCols.begin(); + i != jobInfo.projectionCols.end(); + i++) + { + SimpleColumn* sc = dynamic_cast(i->get()); + + if (sc != NULL) + { + if (sc->schemaName().empty()) + sc->oid(joblist::tableOid(sc, jobInfo.csc) + 1 + sc->colPosition()); + + scProjected.insert(UniqId(sc)); + } + } + + for (vector::const_iterator i = scs.begin(); i != scs.end(); i++) + { + if (scProjected.find(UniqId(*i)) == scProjected.end()) + { + jobInfo.windowDels.push_back(SRCP((*i)->clone())); +// MCOL-3343 Enable this if we decide to allow Window Functions to run with +// aggregates with no group by. MariaDB allows this. Nobody else in the world does. +// There will be more work to get it to function if we try this. +// jobInfo.windowSet.insert(getTupleKey(jobInfo, *i, true)); + scProjected.insert(UniqId(*i)); + } + } +} + void WindowFunctionStep::checkWindowFunction(CalpontSelectExecutionPlan* csep, JobInfo& jobInfo) { // window functions in select clause, selected or in expression @@ -404,6 +439,23 @@ void WindowFunctionStep::checkWindowFunction(CalpontSelectExecutionPlan* csep, J if (jobInfo.windowCols.empty()) return; + // Add in the non-window side of arithmetic columns and functions + for (uint64_t i = 0; i < jobInfo.windowExps.size(); i++) + { + const ArithmeticColumn* ac = + dynamic_cast(jobInfo.windowExps[i].get()); + const FunctionColumn* fc = + dynamic_cast(jobInfo.windowExps[i].get()); + + if (ac != NULL && ac->windowfunctionColumnList().size() > 0) + { + AddSimplColumn(ac->simpleColumnList(), jobInfo); + } + else if (fc != NULL && fc->windowfunctionColumnList().size() > 0) + { + AddSimplColumn(fc->simpleColumnList(), jobInfo); + } + } // reconstruct the delivered column list with auxiliary columns set colSet; jobInfo.deliveredCols.resize(0); @@ -445,7 +497,13 @@ void WindowFunctionStep::checkWindowFunction(CalpontSelectExecutionPlan* csep, J key = getTupleKey(jobInfo, *j, true); if (colSet.find(key) == colSet.end()) + { jobInfo.deliveredCols.push_back(*j); +// MCOL-3343 Enable this if we decide to allow Window Functions to run with +// aggregates with no group by. MariaDB allows this. Nobody else in the world does. +// There will be more work to get it to function if we try this. +// jobInfo.windowSet.insert(getTupleKey(jobInfo, *j, true)); + } colSet.insert(key); } diff --git a/dbcon/joblist/windowfunctionstep.h b/dbcon/joblist/windowfunctionstep.h index b57d06324..eaa020fc3 100644 --- a/dbcon/joblist/windowfunctionstep.h +++ b/dbcon/joblist/windowfunctionstep.h @@ -148,6 +148,8 @@ private: void formatMiniStats(); void printCalTrace(); + static void AddSimplColumn(const std::vector& scs, JobInfo& jobInfo); + class Runner { public: diff --git a/dbcon/mysql/columnstore_info.sql b/dbcon/mysql/columnstore_info.sql index 7655b5f16..b2f5e50d1 100644 --- a/dbcon/mysql/columnstore_info.sql +++ b/dbcon/mysql/columnstore_info.sql @@ -101,7 +101,7 @@ END // create procedure columnstore_upgrade() `columnstore_upgrade`: BEGIN DECLARE done INTEGER DEFAULT 0; - DECLARE schema_table VARCHAR(100) DEFAULT ""; + DECLARE schema_table VARCHAR(100) CHARACTER SET utf8 DEFAULT ""; DECLARE table_list CURSOR FOR select concat('`', table_schema,'`.`',table_name,'`') from information_schema.tables where engine='columnstore'; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; OPEN table_list; @@ -115,6 +115,5 @@ create procedure columnstore_upgrade() DEALLOCATE PREPARE stmt; END LOOP; END // -delimiter ; DELIMITER ; diff --git a/dbcon/mysql/ha_calpont.cpp b/dbcon/mysql/ha_calpont.cpp index 552a895d6..f2136b3ba 100644 --- a/dbcon/mysql/ha_calpont.cpp +++ b/dbcon/mysql/ha_calpont.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -21,6 +21,7 @@ #define NEED_CALPONT_EXTERNS #include "ha_calpont_impl.h" +#include "ha_mcs_pushdown.h" static handler* calpont_create_handler(handlerton* hton, TABLE_SHARE* table, @@ -30,11 +31,19 @@ static int calpont_commit(handlerton* hton, THD* thd, bool all); static int calpont_rollback(handlerton* hton, THD* thd, bool all); static int calpont_close_connection ( handlerton* hton, THD* thd ); -handlerton* calpont_hton; +handlerton* mcs_hton; +// handlers creation function for hton. +// Look into ha_mcs_pushdown.* for more details. static group_by_handler* create_calpont_group_by_handler(THD* thd, Query* query); +static derived_handler* +create_columnstore_derived_handler(THD* thd, TABLE_LIST *derived); + +static select_handler* +create_columnstore_select_handler(THD* thd, SELECT_LEX* sel); + /* Variables for example share methods */ /* @@ -61,13 +70,14 @@ pthread_mutex_t calpont_mutex; Function we use in the creation of our hash to get key. */ -static uchar* calpont_get_key(INFINIDB_SHARE* share, size_t* length, +static uchar* calpont_get_key(COLUMNSTORE_SHARE* share, size_t* length, my_bool not_used __attribute__((unused))) { *length = share->table_name_length; return (uchar*) share->table_name; } +// This one is unused int calpont_discover(handlerton* hton, THD* thd, TABLE_SHARE* share) { DBUG_ENTER("calpont_discover"); @@ -94,6 +104,7 @@ int calpont_discover(handlerton* hton, THD* thd, TABLE_SHARE* share) DBUG_RETURN(my_errno); } +// This f() is also unused int calpont_discover_existence(handlerton* hton, const char* db, const char* table_name) { @@ -107,6 +118,7 @@ static int columnstore_init_func(void* p) struct tm tm; time_t t; + time(&t); localtime_r(&t, &tm); fprintf(stderr, "%02d%02d%02d %2d:%02d:%02d ", @@ -115,54 +127,27 @@ static int columnstore_init_func(void* p) fprintf(stderr, "Columnstore: Started; Version: %s-%s\n", columnstore_version.c_str(), columnstore_release.c_str()); - calpont_hton = (handlerton*)p; + mcs_hton = (handlerton*)p; #ifndef _MSC_VER (void) pthread_mutex_init(&calpont_mutex, MY_MUTEX_INIT_FAST); #endif (void) my_hash_init(&calpont_open_tables, system_charset_info, 32, 0, 0, (my_hash_get_key) calpont_get_key, 0, 0); - calpont_hton->state = SHOW_OPTION_YES; - calpont_hton->create = calpont_create_handler; - calpont_hton->flags = HTON_CAN_RECREATE; -// calpont_hton->discover_table= calpont_discover; -// calpont_hton->discover_table_existence= calpont_discover_existence; - calpont_hton->commit = calpont_commit; - calpont_hton->rollback = calpont_rollback; - calpont_hton->close_connection = calpont_close_connection; - calpont_hton->create_group_by = create_calpont_group_by_handler; + mcs_hton->state = SHOW_OPTION_YES; + mcs_hton->create = calpont_create_handler; + mcs_hton->flags = HTON_CAN_RECREATE; +// mcs_hton->discover_table= calpont_discover; +// mcs_hton->discover_table_existence= calpont_discover_existence; + mcs_hton->commit = calpont_commit; + mcs_hton->rollback = calpont_rollback; + mcs_hton->close_connection = calpont_close_connection; + mcs_hton->create_group_by = create_calpont_group_by_handler; + mcs_hton->create_derived = create_columnstore_derived_handler; + mcs_hton->create_select = create_columnstore_select_handler; DBUG_RETURN(0); } -static int infinidb_init_func(void* p) -{ - DBUG_ENTER("infinidb_init_func"); - - struct tm tm; - time_t t; - - time(&t); - localtime_r(&t, &tm); - fprintf(stderr, "%02d%02d%02d %2d:%02d:%02d ", - tm.tm_year % 100, tm.tm_mon + 1, tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec); - - fprintf(stderr, "Columnstore: Started; Version: %s-%s\n", columnstore_version.c_str(), columnstore_release.c_str()); - - calpont_hton = (handlerton*)p; - - calpont_hton->state = SHOW_OPTION_YES; - calpont_hton->create = calpont_create_handler; - calpont_hton->flags = HTON_CAN_RECREATE; -// calpont_hton->discover_table= calpont_discover; -// calpont_hton->discover_table_existence= calpont_discover_existence; - calpont_hton->commit = calpont_commit; - calpont_hton->rollback = calpont_rollback; - calpont_hton->close_connection = calpont_close_connection; - DBUG_RETURN(0); -} - - static int columnstore_done_func(void* p) { DBUG_ENTER("calpont_done_func"); @@ -174,13 +159,6 @@ static int columnstore_done_func(void* p) DBUG_RETURN(0); } -static int infinidb_done_func(void* p) -{ - DBUG_ENTER("calpont_done_func"); - - DBUG_RETURN(0); -} - static handler* calpont_create_handler(handlerton* hton, TABLE_SHARE* table, MEM_ROOT* mem_root) @@ -264,10 +242,6 @@ int ha_calpont::open(const char* name, int mode, uint32_t test_if_locked) { DBUG_ENTER("ha_calpont::open"); - //if (!(share = get_share(name, table))) - // DBUG_RETURN(1); - //thr_lock_data_init(&share->lock,&lock,NULL); - int rc = ha_calpont_impl_open(name, mode, test_if_locked); DBUG_RETURN(rc); @@ -293,7 +267,6 @@ int ha_calpont::open(const char* name, int mode, uint32_t test_if_locked) int ha_calpont::close(void) { DBUG_ENTER("ha_calpont::close"); - //DBUG_RETURN(free_share(share)); int rc = ha_calpont_impl_close(); @@ -331,7 +304,7 @@ int ha_calpont::close(void) sql_insert.cc, sql_select.cc, sql_table.cc, sql_udf.cc and sql_update.cc */ -int ha_calpont::write_row(uchar* buf) +int ha_calpont::write_row(const uchar* buf) { DBUG_ENTER("ha_calpont::write_row"); int rc = ha_calpont_impl_write_row(buf, table); @@ -511,7 +484,11 @@ int ha_calpont::rnd_init(bool scan) { DBUG_ENTER("ha_calpont::rnd_init"); - int rc = ha_calpont_impl_rnd_init(table); + int rc = 0; + if(scan) + { + rc = ha_calpont_impl_rnd_init(table); + } DBUG_RETURN(rc); } @@ -755,7 +732,7 @@ int ha_calpont::external_lock(THD* thd, int lock_type) //@Bug 2526 Only register the transaction when autocommit is off if ((thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) - trans_register_ha( thd, true, calpont_hton); + trans_register_ha( thd, true, mcs_hton); int rc = ha_calpont_impl_external_lock(thd, table, lock_type); DBUG_RETURN(rc); @@ -926,259 +903,7 @@ const COND* ha_calpont::cond_push(const COND* cond) struct st_mysql_storage_engine columnstore_storage_engine = { MYSQL_HANDLERTON_INTERFACE_VERSION }; -struct st_mysql_storage_engine infinidb_storage_engine = -{ MYSQL_HANDLERTON_INTERFACE_VERSION }; - -/*@brief check_walk - It traverses filter conditions*/ -/************************************************************ - * DESCRIPTION: - * It traverses filter predicates looking for unsupported - * JOIN types: non-equi JOIN, e.g t1.c1 > t2.c2; - * logical OR. - * PARAMETERS: - * thd - THD pointer. - * derived - TABLE_LIST* to work with. - * RETURN: - * derived_handler if possible - * NULL in other case - ***********************************************************/ -void check_walk(const Item* item, void* arg) -{ - bool* unsupported_feature = static_cast(arg); - if ( *unsupported_feature ) - return; - switch (item->type()) - { - case Item::FUNC_ITEM: - { - const Item_func* ifp = static_cast(item); - - if ( ifp->functype() != Item_func::EQ_FUNC ) // NON-equi JOIN - { - if ( ifp->argument_count() == 2 && - ifp->arguments()[0]->type() == Item::FIELD_ITEM && - ifp->arguments()[1]->type() == Item::FIELD_ITEM ) - { - Item_field* left= static_cast(ifp->arguments()[0]); - Item_field* right= static_cast(ifp->arguments()[1]); - - if ( left->field->table != right->field->table ) - { - *unsupported_feature = true; - return; - } - } - else // IN + correlated subquery - { - if ( ifp->functype() == Item_func::NOT_FUNC - && ifp->arguments()[0]->type() == Item::EXPR_CACHE_ITEM ) - { - check_walk(ifp->arguments()[0], arg); - } - } - } - break; - } - - case Item::EXPR_CACHE_ITEM: // IN + correlated subquery - { - const Item_cache_wrapper* icw = static_cast(item); - if ( icw->get_orig_item()->type() == Item::FUNC_ITEM ) - { - const Item_func *ifp = static_cast(icw->get_orig_item()); - if ( ifp->argument_count() == 2 && - ( ifp->arguments()[0]->type() == Item::Item::SUBSELECT_ITEM - || ifp->arguments()[1]->type() == Item::Item::SUBSELECT_ITEM )) - { - *unsupported_feature = true; - return; - } - } - break; - } - - case Item::COND_ITEM: // OR in cods is unsupported yet - { - Item_cond* icp = (Item_cond*)item; - if ( is_cond_or(icp) ) - { - *unsupported_feature = true; - } - break; - } - default: - { - break; - } - } -} - -/*@brief create_calpont_group_by_handler- Creates handler*/ -/*********************************************************** - * DESCRIPTION: - * Creates a group_by pushdown handler if there is no: - * non-equi JOIN, e.g * t1.c1 > t2.c2 - * logical OR in the filter predicates - * Impossible WHERE - * Impossible HAVING - * and there is either GROUP BY or aggregation function - * exists at the top level. - * Valid queries with the last two crashes the server if - * processed. - * Details are in server/sql/group_by_handler.h - * PARAMETERS: - * thd - THD pointer - * query - Query structure LFM in group_by_handler.h - * RETURN: - * group_by_handler if success - * NULL in other case - ***********************************************************/ -static group_by_handler* -create_calpont_group_by_handler(THD* thd, Query* query) -{ - ha_calpont_group_by_handler* handler = NULL; - // same as thd->lex->current_select - SELECT_LEX *select_lex = query->from->select_lex; - - // Create a handler if query is valid. See comments for details. - if ( thd->infinidb_vtable.vtable_state == THD::INFINIDB_DISABLE_VTABLE - && ( thd->variables.infinidb_vtable_mode == 0 - || thd->variables.infinidb_vtable_mode == 2 ) - && ( query->group_by || select_lex->with_sum_func ) ) - { - bool unsupported_feature = false; - // revisit SELECT_LEX for all units - for(TABLE_LIST* tl = query->from; !unsupported_feature && tl; tl = tl->next_global) - { - select_lex = tl->select_lex; - // Correlation subquery. Comming soon so fail on this yet. - unsupported_feature = select_lex->is_correlated; - - // Impossible HAVING or WHERE - if ( ( !unsupported_feature && query->having && select_lex->having_value == Item::COND_FALSE ) - || ( select_lex->cond_count > 0 - && select_lex->cond_value == Item::COND_FALSE ) ) - { - unsupported_feature = true; - } - - // Unsupported JOIN conditions - if ( !unsupported_feature ) - { - JOIN *join = select_lex->join; - Item_cond *icp = 0; - - if (join != 0) - icp = reinterpret_cast(join->conds); - - if ( unsupported_feature == false - && icp ) - { - icp->traverse_cond(check_walk, &unsupported_feature, Item::POSTFIX); - } - - // Optimizer could move some join conditions into where - if (select_lex->where != 0) - icp = reinterpret_cast(select_lex->where); - - if ( unsupported_feature == false - && icp ) - { - icp->traverse_cond(check_walk, &unsupported_feature, Item::POSTFIX); - } - - } - } // unsupported features check ends here - - if ( !unsupported_feature ) - { - handler = new ha_calpont_group_by_handler(thd, query); - - // Notify the server, that CS handles GROUP BY, ORDER BY and HAVING clauses. - query->group_by = NULL; - query->order_by = NULL; - query->having = NULL; - } - } - - return handler; -} - -/*********************************************************** - * DESCRIPTION: - * GROUP BY handler constructor - * PARAMETERS: - * thd - THD pointer. - * query - Query describing structure - ***********************************************************/ -ha_calpont_group_by_handler::ha_calpont_group_by_handler(THD* thd_arg, Query* query) - : group_by_handler(thd_arg, calpont_hton), - select(query->select), - table_list(query->from), - distinct(query->distinct), - where(query->where), - group_by(query->group_by), - order_by(query->order_by), - having(query->having) -{ -} - -/*********************************************************** - * DESCRIPTION: - * GROUP BY destructor - ***********************************************************/ -ha_calpont_group_by_handler::~ha_calpont_group_by_handler() -{ -} - -/*********************************************************** - * DESCRIPTION: - * Makes the plan and prepares the data - * RETURN: - * int rc - ***********************************************************/ -int ha_calpont_group_by_handler::init_scan() -{ - DBUG_ENTER("ha_calpont_group_by_handler::init_scan"); - - // Save vtable_state to restore the after we inited. - THD::infinidb_state oldState = thd->infinidb_vtable.vtable_state; - // MCOL-1052 Should be removed after cleaning the code up. - thd->infinidb_vtable.vtable_state = THD::INFINIDB_CREATE_VTABLE; - int rc = ha_calpont_impl_group_by_init(this, table); - thd->infinidb_vtable.vtable_state = oldState; - - DBUG_RETURN(rc); -} - -/*********************************************************** - * DESCRIPTION: - * Fetches a row and saves it to a temporary table. - * RETURN: - * int rc - ***********************************************************/ -int ha_calpont_group_by_handler::next_row() -{ - DBUG_ENTER("ha_calpont_group_by_handler::next_row"); - int rc = ha_calpont_impl_group_by_next(this, table); - - DBUG_RETURN(rc); -} - -/*********************************************************** - * DESCRIPTION: - * Shuts the scan down. - * RETURN: - * int rc - ***********************************************************/ -int ha_calpont_group_by_handler::end_scan() -{ - DBUG_ENTER("ha_calpont_group_by_handler::end_scan"); - - int rc = ha_calpont_impl_group_by_end(this, table); - - DBUG_RETURN(rc); -} +#include "ha_mcs_pushdown.cpp" mysql_declare_plugin(columnstore) { @@ -1195,21 +920,6 @@ mysql_declare_plugin(columnstore) mcs_system_variables, /* system variables */ NULL, /* reserved */ 0 /* config flags */ -}, -{ - MYSQL_STORAGE_ENGINE_PLUGIN, - &infinidb_storage_engine, - "InfiniDB", - "MariaDB", - "Columnstore storage engine (deprecated: use columnstore)", - PLUGIN_LICENSE_GPL, - infinidb_init_func, /* Plugin Init */ - infinidb_done_func, /* Plugin Deinit */ - 0x0100 /* 1.0 */, - NULL, /* status variables */ - mcs_system_variables, /* system variables */ - NULL, /* reserved */ - 0 /* config flags */ } mysql_declare_plugin_end; maria_declare_plugin(columnstore) @@ -1227,21 +937,6 @@ maria_declare_plugin(columnstore) mcs_system_variables, /* system variables */ "1.0", /* string version */ MariaDB_PLUGIN_MATURITY_STABLE /* maturity */ -}, -{ - MYSQL_STORAGE_ENGINE_PLUGIN, - &infinidb_storage_engine, - "InfiniDB", - "MariaDB", - "Columnstore storage engine (deprecated: use columnstore)", - PLUGIN_LICENSE_GPL, - infinidb_init_func, - infinidb_done_func, - 0x0100, /* 1.0 */ - NULL, /* status variables */ - mcs_system_variables, /* system variables */ - "1.0", /* string version */ - MariaDB_PLUGIN_MATURITY_STABLE /* maturity */ } maria_declare_plugin_end; diff --git a/dbcon/mysql/ha_calpont.h b/dbcon/mysql/ha_calpont.h index bab756851..502e10f70 100644 --- a/dbcon/mysql/ha_calpont.h +++ b/dbcon/mysql/ha_calpont.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -21,10 +21,10 @@ #include "idb_mysql.h" #include "ha_mcs_sysvars.h" -extern handlerton* calpont_hton; +extern handlerton* mcs_hton; /** @brief - This structure will be shared among all open handlers. + COLUMNSTORE_SHARE is a structure that will be shared among all open handlers. This example implements the minimum of what you will probably need. */ typedef struct st_calpont_share @@ -33,7 +33,7 @@ typedef struct st_calpont_share uint32_t table_name_length, use_count; pthread_mutex_t mutex; THR_LOCK lock; -} INFINIDB_SHARE; +} COLUMNSTORE_SHARE; /** @brief Class definition for the storage engine @@ -41,7 +41,7 @@ typedef struct st_calpont_share class ha_calpont: public handler { THR_LOCK_DATA lock; ///< MySQL lock - INFINIDB_SHARE* share; ///< Shared lock info + COLUMNSTORE_SHARE* share; ///< Shared lock info ulonglong int_table_flags; public: @@ -135,7 +135,7 @@ public: We implement this in ha_example.cc. It's not an obligatory method; skip it and and MySQL will treat it as not implemented. */ - int write_row(uchar* buf); + int write_row(const uchar* buf); /** @brief We implement this in ha_example.cc. It's not an obligatory method; @@ -228,51 +228,4 @@ public: } }; - -/*@brief group_by_handler class*/ -/*********************************************************** - * DESCRIPTION: - * Provides server with group_by_handler API methods. - * One should read comments in server/sql/group_by_handler.h - * Attributes: - * select - attribute contains all GROUP BY, HAVING, ORDER items and calls it - * an extended SELECT list according to comments in - * server/sql/group_handler.cc. - * So the temporary table for - * select count(*) from b group by a having a > 3 order by a - * will have 4 columns not 1. - * However server ignores all NULLs used in - * GROUP BY, HAVING, ORDER. - * select_list_descr - contains Item description returned by Item->print() - * that is used in lookup for corresponding columns in - * extended SELECT list. - * table_list - contains all tables involved. Must be CS tables only. - * distinct - looks like a useless thing for now. Couldn't get it set by server. - * where - where items. - * group_by - group by ORDER items. - * order_by - order by ORDER items. - * having - having Item. - * Methods: - * init_scan - get plan and send it to ExeMgr. Get the execution result. - * next_row - get a row back from sm. - * end_scan - finish and clean the things up. - ***********************************************************/ -class ha_calpont_group_by_handler: public group_by_handler -{ -public: - ha_calpont_group_by_handler(THD* thd_arg, Query* query); - ~ha_calpont_group_by_handler(); - int init_scan(); - int next_row(); - int end_scan(); - - List* select; - TABLE_LIST* table_list; - bool distinct; - Item* where; - ORDER* group_by; - ORDER* order_by; - Item* having; -}; #endif //HA_CALPONT_H__ - diff --git a/dbcon/mysql/ha_calpont_ddl.cpp b/dbcon/mysql/ha_calpont_ddl.cpp index 833a0ab38..1fc07be6d 100644 --- a/dbcon/mysql/ha_calpont_ddl.cpp +++ b/dbcon/mysql/ha_calpont_ddl.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -2306,17 +2306,6 @@ int ha_calpont_impl_create_(const char* name, TABLE* table_arg, HA_CREATE_INFO* bool schemaSyncOnly = false; bool isCreate = true; - // relate to bug 1793. Make sure this is not for a select statement because - if (db == "calpontsys" && thd->infinidb_vtable.vtable_state == THD::INFINIDB_INIT - && tbl != "systable" - && tbl != "syscolumn" && tbl != "sysindex" - && tbl != "sysconstraint" && tbl != "sysindexcol" - && tbl != "sysconstraintcol" ) - { - setError(thd, ER_INTERNAL_ERROR, "Cannot create non-system Calpont tables in calpontsys database"); - return 1; - } - regex pat("[[:space:]]*SCHEMA[[:space:]]+SYNC[[:space:]]+ONLY", regex_constants::extended); if (regex_search(tablecomment, pat)) @@ -2336,11 +2325,6 @@ int ha_calpont_impl_create_(const char* name, TABLE* table_arg, HA_CREATE_INFO* #endif return 0; } - - if (thd->infinidb_vtable.vtable_state == THD::INFINIDB_ALTER_VTABLE) //check if it is select - { - return 0; - } } else { diff --git a/dbcon/mysql/ha_calpont_dml.cpp b/dbcon/mysql/ha_calpont_dml.cpp index 20462e2c8..fc3a63eab 100644 --- a/dbcon/mysql/ha_calpont_dml.cpp +++ b/dbcon/mysql/ha_calpont_dml.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -88,109 +88,6 @@ inline uint32_t tid2sid(const uint32_t tid) } //StopWatch timer; -int buildBuffer(uchar* buf, string& buffer, int& columns, TABLE* table) -{ - char attribute_buffer[1024]; - String attribute(attribute_buffer, sizeof(attribute_buffer), - &my_charset_bin); - - std::string cols = " ("; - std::string vals = " values ("; - columns = 0; - - for (Field** field = table->field; *field; field++) - { - const char* ptr; - const char* end_ptr; - - if ((*field)->is_null()) - ptr = end_ptr = 0; - else - { - bitmap_set_bit(table->read_set, (*field)->field_index); - (*field)->val_str(&attribute, &attribute); - ptr = attribute.ptr(); - end_ptr = attribute.length() + ptr; - } - - if (columns > 0) - { - cols.append(","); - vals.append(","); - } - - columns++; - - cols.append((*field)->field_name.str); - - if (ptr == end_ptr) - { - vals.append ("NULL"); - } - else - { - - if ( (*field)->type() == MYSQL_TYPE_VARCHAR || - /*FIXME: (*field)->type() == MYSQL_TYPE_VARBINARY || */ - (*field)->type() == MYSQL_TYPE_VAR_STRING || - (*field)->type() == MYSQL_TYPE_STRING || - (*field)->type() == MYSQL_TYPE_DATE || - (*field)->type() == MYSQL_TYPE_DATETIME || - (*field)->type() == MYSQL_TYPE_DATETIME2 || - (*field)->type() == MYSQL_TYPE_TIMESTAMP || - (*field)->type() == MYSQL_TYPE_TIMESTAMP2 || - (*field)->type() == MYSQL_TYPE_TIME ) - vals.append("'"); - - while (ptr < end_ptr) - { - - if (*ptr == '\r') - { - ptr++; - } - else if (*ptr == '\n') - { - ptr++; - } - else if (*ptr == '\'' ) - { - //@Bug 1820. Replace apostrophe with strange character to pass parser. - vals += '\252'; - ptr++; - } - else - vals += *ptr++; - } - - if ( (*field)->type() == MYSQL_TYPE_VARCHAR || - /*FIXME: (*field)->type() == MYSQL_TYPE_VARBINARY || */ - (*field)->type() == MYSQL_TYPE_VAR_STRING || - (*field)->type() == MYSQL_TYPE_STRING || - (*field)->type() == MYSQL_TYPE_DATE || - (*field)->type() == MYSQL_TYPE_DATETIME || - (*field)->type() == MYSQL_TYPE_DATETIME2 || - (*field)->type() == MYSQL_TYPE_TIMESTAMP || - (*field)->type() == MYSQL_TYPE_TIMESTAMP2 || - (*field)->type() == MYSQL_TYPE_TIME ) - vals.append("'"); - } - } - - if (columns) - { - cols.append(") "); - vals.append(") "); - buffer = "INSERT INTO "; - buffer.append(table->s->table_name.str); - buffer.append(cols); - buffer.append(vals); - } - - return columns; -} - - uint32_t buildValueList (TABLE* table, cal_connection_info& ci ) { char attribute_buffer[1024]; @@ -653,7 +550,7 @@ int ha_calpont_impl_write_last_batch(TABLE* table, cal_connection_info& ci, bool } -int ha_calpont_impl_write_row_(uchar* buf, TABLE* table, cal_connection_info& ci, ha_rows& rowsInserted) +int ha_calpont_impl_write_row_(const uchar* buf, TABLE* table, cal_connection_info& ci, ha_rows& rowsInserted) { int rc = 0; //timer.start( "buildValueList"); @@ -743,13 +640,13 @@ int ha_calpont_impl_write_row_(uchar* buf, TABLE* table, cal_connection_info& ci } } -int ha_calpont_impl_write_batch_row_(uchar* buf, TABLE* table, cal_impl_if::cal_connection_info& ci) +int ha_calpont_impl_write_batch_row_(const uchar* buf, TABLE* table, cal_impl_if::cal_connection_info& ci) { ByteStream rowData; int rc = 0; //std::ostringstream data; bool nullVal = false; - uchar* bufHdr = buf; // bit flag indicating a field is null. Only those fields that are nullable are represented. + const uchar* bufHdr = buf; // bit flag indicating a field is null. Only those fields that are nullable are represented. int32_t headerByte = 0; // Current byte in the bufHdr int32_t headerBit = 0; // current bit in the bufHdr current byte. uint16_t colpos = 0; @@ -815,7 +712,7 @@ int ha_calpont_impl_write_batch_row_(uchar* buf, TABLE* table, cal_impl_if::cal_ } else { - uchar* tmp1 = buf; + const uchar* tmp1 = buf; uint32_t tmp = (tmp1[2] << 16) + (tmp1[1] << 8) + tmp1[0]; int day = tmp & 0x0000001fl; @@ -1043,7 +940,6 @@ int ha_calpont_impl_write_batch_row_(uchar* buf, TABLE* table, cal_impl_if::cal_ dataLength = *(uint16_t*) buf; buf = buf + 2 ; } - escape.assign((char*)buf, dataLength); boost::replace_all(escape, "\\", "\\\\"); fprintf(ci.filePtr, "%c%.*s%c%c", ci.enclosed_by, (int)escape.length(), escape.c_str(), ci.enclosed_by, ci.delimiter); @@ -1061,22 +957,16 @@ int ha_calpont_impl_write_batch_row_(uchar* buf, TABLE* table, cal_impl_if::cal_ buf = buf + 2 ; } - if ( dataLength > ci.columnTypes[colpos].colWidth) - dataLength = ci.columnTypes[colpos].colWidth; - escape.assign((char*)buf, dataLength); boost::replace_all(escape, "\\", "\\\\"); fprintf(ci.filePtr, "%c%.*s%c%c", ci.enclosed_by, (int)escape.length(), escape.c_str(), ci.enclosed_by, ci.delimiter); } } - - //buf += ci.columnTypes[colpos].colWidth; if (ci.utf8) buf += (ci.columnTypes[colpos].colWidth * 3); else buf += ci.columnTypes[colpos].colWidth; - break; } @@ -1498,11 +1388,12 @@ int ha_calpont_impl_write_batch_row_(uchar* buf, TABLE* table, cal_impl_if::cal_ if (ci.columnTypes[colpos].scale == 0) { - uchar* tmpBuf = buf; + const uchar* tmpBuf = buf; //test flag bit for sign bool posNum = tmpBuf[0] & (0x80); - tmpBuf[0] ^= 0x80; //flip the bit - int32_t tmp1 = tmpBuf[0]; + uchar tmpChr = tmpBuf[0]; + tmpChr ^= 0x80; //flip the bit + int32_t tmp1 = tmpChr; if (totalBytes > 4) { @@ -1596,11 +1487,12 @@ int ha_calpont_impl_write_batch_row_(uchar* buf, TABLE* table, cal_impl_if::cal_ } else { - uchar* tmpBuf = buf; + const uchar* tmpBuf = buf; //test flag bit for sign bool posNum = tmpBuf[0] & (0x80); - tmpBuf[0] ^= 0x80; //flip the bit - int32_t tmp1 = tmpBuf[0]; + uchar tmpChr = tmpBuf[0]; + tmpChr ^= 0x80; //flip the bit + int32_t tmp1 = tmpChr; //fetch the digits before decimal point if (bytesBefore == 0) @@ -1812,7 +1704,7 @@ int ha_calpont_impl_write_batch_row_(uchar* buf, TABLE* table, cal_impl_if::cal_ buf = buf + 2 ; } - uchar* tmpBuf = buf; + const uchar* tmpBuf = buf; for (int32_t i = 0; i < dataLength; i++) { @@ -1838,7 +1730,7 @@ int ha_calpont_impl_write_batch_row_(uchar* buf, TABLE* table, cal_impl_if::cal_ if ( dataLength > ci.columnTypes[colpos].colWidth) dataLength = ci.columnTypes[colpos].colWidth; - uchar* tmpBuf = buf; + const uchar* tmpBuf = buf; for (int32_t i = 0; i < dataLength; i++) { @@ -2117,10 +2009,6 @@ int ha_calpont_impl_commit_ (handlerton* hton, THD* thd, bool all, cal_connectio { int rc = 0; - if (thd->infinidb_vtable.vtable_state == THD::INFINIDB_ALTER_VTABLE || - thd->infinidb_vtable.vtable_state == THD::INFINIDB_SELECT_VTABLE ) - return rc; - if (thd->slave_thread && !ci.replicationEnabled) return 0; diff --git a/dbcon/mysql/ha_calpont_execplan.cpp b/dbcon/mysql/ha_calpont_execplan.cpp index d40584109..c536a5950 100644 --- a/dbcon/mysql/ha_calpont_execplan.cpp +++ b/dbcon/mysql/ha_calpont_execplan.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -19,7 +19,7 @@ /* * $Id: ha_calpont_execplan.cpp 9749 2013-08-15 04:00:39Z zzhu $ */ - + /** @file */ //#define DEBUG_WALK_COND #include @@ -192,6 +192,153 @@ bool nonConstFunc(Item_func* ifp) return false; } +/*@brief getColNameFromItem - builds a name from an Item */ +/*********************************************************** + * DESCRIPTION: + * This f() looks for a first proper Item_ident and populate + * ostream with schema, table and column names. + * Used to build db.table.field tuple for debugging output + * in getSelectPlan(). TBD getGroupPlan must use this also. + * PARAMETERS: + * item source Item* + * ostream output stream + * RETURNS + * void + ***********************************************************/ +void getColNameFromItem(std::ostringstream& ostream, Item* item) +{ +// Item_func doesn't have proper db.table.field values +// inherited from Item_ident. TBD what is the valid output. +// !!!dynamic_cast fails compilation + ostream << "'"; + + if (item->type() != Item::FIELD_ITEM) + { + ostream << "unknown db" << '.'; + ostream << "unknown table" << '.'; + ostream << "unknown field"; + } + else + { + Item_ident* iip = reinterpret_cast(item); + + if (iip->db_name) + ostream << iip->db_name << '.'; + else + ostream << "unknown db" << '.'; + + if (iip->table_name) + ostream << iip->table_name << '.'; + else + ostream << "unknown table" << '.'; + + if (iip->field_name.length) + ostream << iip->field_name.str; + else + ostream << "unknown field"; + } + + ostream << "'"; + return; +} + +/*@brf sortItemIsInGroupRec - seeks for an item in grouping*/ +/*********************************************************** + * DESCRIPTION: + * This f() recursively traverses grouping items and looks + * for an FUNC_ITEM, REF_ITEM or FIELD_ITEM. + * f() is used by sortItemIsInGrouping(). + * PARAMETERS: + * sort_item Item* used to build aggregation. + * group_item GROUP BY item. + * RETURNS + * bool + ***********************************************************/ +bool sortItemIsInGroupRec(Item* sort_item, Item* group_item) +{ + bool found = false; + // If ITEM_REF::ref is NULL + if (sort_item == NULL) + { + return found; + } + + Item_func* ifp_sort = reinterpret_cast(sort_item); + + // base cases for Item_field and Item_ref. The second arg is binary cmp switch + found = group_item->eq(sort_item, false); + if (!found && sort_item->type() == Item::REF_ITEM) + { + Item_ref* ifp_sort_ref = reinterpret_cast(sort_item); + found = sortItemIsInGroupRec(*ifp_sort_ref->ref, group_item); + } + else if (!found && sort_item->type() == Item::FIELD_ITEM) + { + return found; + } + + // seeking for a group_item match + for (uint32_t i = 0; !found && i < ifp_sort->argument_count(); i++) + { + Item* ifp_sort_arg = ifp_sort->arguments()[i]; + if (ifp_sort_arg->type() == Item::FUNC_ITEM + || ifp_sort_arg->type() == Item::FIELD_ITEM) + { + Item* ifp_sort_arg = ifp_sort->arguments()[i]; + found = sortItemIsInGroupRec(ifp_sort_arg, group_item); + } + else if (ifp_sort_arg->type() == Item::REF_ITEM) + { + // dereference the Item + Item_ref* ifp_sort_ref = reinterpret_cast(ifp_sort_arg); + found = sortItemIsInGroupRec(*ifp_sort_ref->ref, group_item); + } + } + + return found; +} + +/*@brief sortItemIsInGrouping- seeks for an item in grouping*/ +/*********************************************************** + * DESCRIPTION: + * This f() traverses grouping items and looks for an item. + * only Item_fields, Item_func are considered. However there + * could be Item_ref down the tree. + * f() is used in sorting parsing by getSelectPlan(). + * PARAMETERS: + * sort_item Item* used to build aggregation. + * groupcol GROUP BY items from this unit. + * RETURNS + * bool + ***********************************************************/ +bool sortItemIsInGrouping(Item* sort_item, ORDER* groupcol) +{ + bool found = false; + + if(sort_item->type() == Item::SUM_FUNC_ITEM) + { + found = true; + } + + for (; !found && groupcol; groupcol = groupcol->next) + { + Item* group_item = *(groupcol->item); + found = (group_item->eq(sort_item, false)) ? true : false; + // Detect aggregation functions first then traverse + // if sort field is a Func and group field + // is either Field or Func + // Consider nonConstFunc() check here + if(!found && sort_item->type() == Item::FUNC_ITEM + && (group_item->type() == Item::FUNC_ITEM + || group_item->type() == Item::FIELD_ITEM)) + { + found = sortItemIsInGroupRec(sort_item, group_item); + } + } + + return found; +} + /*@brief buildAggFrmTempField- build aggr func from extSELECT list item*/ /*********************************************************** * DESCRIPTION: @@ -230,7 +377,6 @@ ReturnedColumn* buildAggFrmTempField(Item* item, gp_walk_info& gwi) std::vector::iterator iter = gwi.extSelAggColsItems.begin(); for ( ; iter != gwi.extSelAggColsItems.end(); iter++ ) { - //Item* temp_isfp = *iter; isfp = reinterpret_cast(*iter); if ( isfp->type() == Item::SUM_FUNC_ITEM && @@ -249,6 +395,40 @@ ReturnedColumn* buildAggFrmTempField(Item* item, gp_walk_info& gwi) return result; } +/*@brief isDuplicateSF - search for a duplicate SimpleFilter*/ +/*********************************************************** + * DESCRIPTION: + * As of 1.4 CS potentially has duplicate filter predicates + * in both join->conds and join->cond_equal. This utility f() + * searches for semantically equal SF in the list of already + * applied equi predicates. + * TODO + * We must move find_select_handler to either future or + * later execution phase. + * PARAMETERS: + * gwi main structure + * sf SimpleFilter * to find + * RETURNS + * true if sf has been found in the applied SF list + * false otherwise + * USED + * buildPredicateItem() + ***********************************************************/ +bool isDuplicateSF(gp_walk_info *gwip, execplan::SimpleFilter *sfp) +{ + List_iterator it(gwip->equiCondSFList); + execplan::SimpleFilter *isfp; + while((isfp = it++)) + { + if (sfp->semanticEq(*isfp)) + { + return true; + } + } + + return false; +} + string getViewName(TABLE_LIST* table_ptr) { string viewName = ""; @@ -286,40 +466,61 @@ void debug_walk(const Item* item, void* arg) '.' << ifp->field_name.str << endl; break; } - - case Item::INT_ITEM: + case Item::CONST_ITEM: { - Item_int* iip = (Item_int*)item; - cerr << "INT_ITEM: "; + switch (item->cmp_type()) + { + case INT_RESULT: + { + Item_int* iip = (Item_int*)item; + cerr << "INT_ITEM: "; - if (iip->name.length) cerr << iip->name.str << " (from name string)" << endl; - else cerr << iip->val_int() << endl; + if (iip->name.length) cerr << iip->name.str << " (from name string)" << endl; + else cerr << iip->val_int() << endl; + break; + } + case STRING_RESULT: + { + Item_string* isp = (Item_string*)item; + String val, *str = isp->val_str(&val); + string valStr; + valStr.assign(str->ptr(), str->length()); + cerr << "STRING_ITEM: >" << valStr << '<' << endl; + break; + } + case REAL_RESULT: + { + cerr << "REAL_ITEM" << endl; + break; + } + case DECIMAL_RESULT: + { + cerr << "DECIMAL_ITEM" << endl; + break; + } + case TIME_RESULT: + { + String val, *str = NULL; + Item_temporal_literal* itp = (Item_temporal_literal*)item; + str = itp->val_str(&val); + cerr << "DATE ITEM: "; + + if (str) + cerr << ": (" << str->ptr() << ')' << endl; + else + cerr << ": " << endl; + + break; + } + default: + { + cerr << ": Unknown cmp_type" << endl; + break; + } + } break; } - - case Item::STRING_ITEM: - { - Item_string* isp = (Item_string*)item; - String val, *str = isp->val_str(&val); - string valStr; - valStr.assign(str->ptr(), str->length()); - cerr << "STRING_ITEM: >" << valStr << '<' << endl; - break; - } - - case Item::REAL_ITEM: - { - cerr << "REAL_ITEM" << endl; - break; - } - - case Item::DECIMAL_ITEM: - { - cerr << "DECIMAL_ITEM" << endl; - break; - } - case Item::FUNC_ITEM: { Item_func* ifp = (Item_func*)item; @@ -570,7 +771,8 @@ void debug_walk(const Item* item, void* arg) item_name = const_cast(isp->get_arg(0)->name.str); } else if (!item_name && isp->get_arg_count() - && isp->get_arg(0)->type() == Item::INT_ITEM) + && isp->get_arg(0)->type() == Item::CONST_ITEM + && isp->get_arg(0)->cmp_type() == INT_RESULT) { item_name = (char*)"INT||*"; } @@ -961,21 +1163,6 @@ void debug_walk(const Item* item, void* arg) break; } - case Item::DATE_ITEM: - { - String val, *str = NULL; - Item_temporal_literal* itp = (Item_temporal_literal*)item; - str = itp->val_str(&val); - cerr << "DATE ITEM: "; - - if (str) - cerr << ": (" << str->ptr() << ')' << endl; - else - cerr << ": " << endl; - - break; - } - case Item::WINDOW_FUNC_ITEM: { Item_window_func* ifp = (Item_window_func*)item; @@ -989,6 +1176,12 @@ void debug_walk(const Item* item, void* arg) break; } + case Item::TYPE_HOLDER: + { + cerr << "TYPE_HOLDER item with cmp_type " << item->cmp_type() << endl; + break; + } + default: { cerr << "UNKNOWN_ITEM type " << item->type() << endl; @@ -1161,8 +1354,9 @@ uint32_t buildOuterJoin(gp_walk_info& gwi, SELECT_LEX& select_lex) { if (gwi.thd->derived_tables_processing) { - gwi.thd->infinidb_vtable.isUnion = false; - gwi.thd->infinidb_vtable.isUpdateWithDerive = true; + // MCOL-2178 isUnion member only assigned, never used + //MIGR::infinidb_vtable.isUnion = false; + gwi.cs_vtable_is_update_with_derive = true; return -1; } } @@ -1441,7 +1635,7 @@ bool buildPredicateItem(Item_func* ifp, gp_walk_info* gwip) { // Starting with MariaDB 10.2, LIKE uses a negated flag instead of FUNC_NOT // Further processing is done below as before for LIKE - if (((Item_func_like*)ifp)->negated) + if (((Item_func_like*)ifp)->get_negated()) { sop->reverseOp(); } @@ -1579,7 +1773,7 @@ bool buildPredicateItem(Item_func* ifp, gp_walk_info* gwip) String str; // @bug5811. This filter string is for cross engine to use. // Use real table name. - ifp->print(&str, QT_INFINIDB_DERIVED); + ifp->print(&str, QT_ORDINARY); IDEBUG(cerr << str.ptr() << endl); if (str.ptr()) @@ -1781,34 +1975,35 @@ bool buildPredicateItem(Item_func* ifp, gp_walk_info* gwip) } else if (ifp->functype() == Item_func::MULT_EQUAL_FUNC) { -#if 0 // MYSQL_5.6 - Item_equal* item_eq = (Item_equal*)ifp; - // This code is for mysql 5.6. Need to convert to MariaDB 10.1 - List_iterator_fast it(item_eq->fields); - idbassert(item_eq->fields.elements == 2); - - // @todo handle more than 2 equal fields - Item* item_field = it++; - ReturnedColumn* lhs = buildReturnedColumn(item_field, *gwip, gwip->fatalParseError); - item_field = it++; - ReturnedColumn* rhs = buildReturnedColumn(item_field, *gwip, gwip->fatalParseError); - - if (!rhs || !lhs) + Item_equal *cur_item_eq = (Item_equal*)ifp; + Item *lhs_item, *rhs_item; + // There must be at least two items + Item_equal_fields_iterator lhs_it(*cur_item_eq); + Item_equal_fields_iterator rhs_it(*cur_item_eq); rhs_it++; + while ((lhs_item = lhs_it++) && (rhs_item = rhs_it++)) { - gwip->fatalParseError = true; - gwip->parseErrorText = "Unsupport elements in MULT_EQUAL item"; - delete rhs; - delete lhs; - return false; + ReturnedColumn* lhs = buildReturnedColumn(lhs_item, *gwip, gwip->fatalParseError); + ReturnedColumn* rhs = buildReturnedColumn(rhs_item, *gwip, gwip->fatalParseError); + if (!rhs || !lhs) + { + gwip->fatalParseError = true; + gwip->parseErrorText = "Unsupport elements in MULT_EQUAL item"; + delete rhs; + delete lhs; + return false; + } + PredicateOperator* po = new PredicateOperator("="); + boost::shared_ptr sop(po); + sop->setOpType(lhs->resultType(), rhs->resultType()); + SimpleFilter* sf = new SimpleFilter(sop, lhs, rhs); + // Search in ptWorkStack for duplicates of the SF + // before we push the SF + if (!isDuplicateSF(gwip, sf)) + { + ParseTree* pt = new ParseTree(sf); + gwip->ptWorkStack.push(pt); + } } - - PredicateOperator* po = new PredicateOperator("="); - boost::shared_ptr sop(po); - sop->setOpType(lhs->resultType(), rhs->resultType()); - SimpleFilter* sf = new SimpleFilter(sop, lhs, rhs); - ParseTree* pt = new ParseTree(sf); - gwip->ptWorkStack.push(pt); -#endif } else if (ifp->functype() == Item_func::EQUAL_FUNC) { @@ -2029,6 +2224,11 @@ bool buildPredicateItem(Item_func* ifp, gp_walk_info* gwip) } } + if (ifp->functype() == Item_func::EQ_FUNC) + { + gwip->equiCondSFList.push_back(sf); + } + ParseTree* ptp = new ParseTree(sf); gwip->ptWorkStack.push(ptp); } @@ -2203,13 +2403,20 @@ SimpleColumn* buildSimpleColFromDerivedTable(gp_walk_info& gwi, Item_field* ifp) sc->colPosition(j); string tableAlias(csep->derivedTbAlias()); sc->tableAlias(lower(tableAlias)); - sc->viewName(lower(viewName)); sc->timeZone(gwi.thd->variables.time_zone->get_name()->ptr()); + if (!viewName.empty()) + { + sc->viewName(viewName); + } + else + { + sc->viewName(csep->derivedTbView()); + } sc->resultType(cols[j]->resultType()); sc->hasAggregate(cols[j]->hasAggregate()); if (col) - sc->isInfiniDB(col->isInfiniDB()); + sc->isColumnStore(col->isColumnStore()); // @bug5634, @bug5635. mark used derived col on derived table. // outer join inner table filter can not be moved in @@ -2485,8 +2692,6 @@ void setError(THD* thd, uint32_t errcode, string errmsg) } thd->raise_error_printf(errcode, errmsg.c_str()); - thd->infinidb_vtable.isNewQuery = true; - thd->infinidb_vtable.override_largeside_estimate = false; // reset expressionID if (get_fe_conn_info_ptr() == NULL) @@ -2600,7 +2805,7 @@ uint32_t setAggOp(AggregateColumn* ac, Item_sum* isp) { Item_func_group_concat* gc = (Item_func_group_concat*)isp; ac->aggOp(AggregateColumn::GROUP_CONCAT); - ac->distinct(gc->isDistinct()); + ac->distinct(gc->get_distinct()); return rc; } @@ -2664,14 +2869,14 @@ SimpleColumn* getSmallestColumn(boost::shared_ptr csc, } // check engine type - if (!tan.fIsInfiniDB) + if (!tan.fisColumnStore) { // get the first column to project. @todo optimization to get the smallest one for foreign engine. Field* field = *(table->field); - SimpleColumn* sc = new SimpleColumn(table->s->db.str, table->s->table_name.str, field->field_name.str, tan.fIsInfiniDB, gwi.sessionid); + SimpleColumn* sc = new SimpleColumn(table->s->db.str, table->s->table_name.str, field->field_name.str, tan.fisColumnStore, gwi.sessionid); string alias(table->alias.ptr()); sc->tableAlias(lower(alias)); - sc->isInfiniDB(false); + sc->isColumnStore(false); sc->timeZone(gwi.thd->variables.time_zone->get_name()->ptr()); sc->resultType(fieldType_MysqlToIDB(field)); sc->oid(field->field_index + 1); @@ -2878,7 +3083,7 @@ ReturnedColumn* buildReturnedColumn(Item* item, gp_walk_info& gwi, bool& nonSupp { //if ( ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE ) || ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE_MULTI )) { - if ( !item->fixed) + if ( !item->is_fixed()) { item->fix_fields(gwi.thd, (Item**)&item); } @@ -2892,59 +3097,71 @@ ReturnedColumn* buildReturnedColumn(Item* item, gp_walk_info& gwi, bool& nonSupp Item_field* ifp = (Item_field*)item; return buildSimpleColumn(ifp, gwi); } - - case Item::INT_ITEM: - case Item::VARBIN_ITEM: + case Item::CONST_ITEM: { - String val, *str = item->val_str(&val); - string valStr; - valStr.assign(str->ptr(), str->length()); - - if (item->unsigned_flag) + switch (item->cmp_type()) { - //cc = new ConstantColumn(valStr, (uint64_t)item->val_uint(), ConstantColumn::NUM); - // It seems that str at this point is crap if val_uint() is > MAX_BIGINT. By using - // this constructor, ConstantColumn is built with the proper string. For whatever reason, - // ExeMgr converts the fConstval member to numeric, rather than using the existing numeric - // values available, so it's important to have fConstval correct. - rc = new ConstantColumn((uint64_t)item->val_uint(), ConstantColumn::NUM); + case INT_RESULT: + { + String val, *str = item->val_str(&val); + string valStr; + valStr.assign(str->ptr(), str->length()); + + if (item->unsigned_flag) + { + rc = new ConstantColumn((uint64_t)item->val_uint(), ConstantColumn::NUM); + } + else + { + rc = new ConstantColumn(valStr, (int64_t)item->val_int(), ConstantColumn::NUM); + } + + break; + } + case STRING_RESULT: + { + String val, *str = item->val_str(&val); + string valStr; + valStr.assign(str->ptr(), str->length()); + rc = new ConstantColumn(valStr); + break; + } + case REAL_RESULT: + { + String val, *str = item->val_str(&val); + string valStr; + valStr.assign(str->ptr(), str->length()); + rc = new ConstantColumn(valStr, item->val_real()); + break; + } + case DECIMAL_RESULT: + { + rc = buildDecimalColumn(item, gwi); + break; + } + case TIME_RESULT: + { + String val, *str = item->val_str(&val); + string valStr; + valStr.assign(str->ptr(), str->length()); + rc = new ConstantColumn(valStr); + break; + } + default: + { + gwi.fatalParseError = true; + gwi.parseErrorText = "Unknown item type"; + break; + } } - else + + if (rc && (item->cmp_type() != DECIMAL_RESULT)) { - rc = new ConstantColumn(valStr, (int64_t)item->val_int(), ConstantColumn::NUM); + (dynamic_cast(rc))->timeZone(gwi.thd->variables.time_zone->get_name()->ptr()); } - (dynamic_cast(rc))->timeZone(gwi.thd->variables.time_zone->get_name()->ptr()); - //return cc; break; } - - case Item::STRING_ITEM: - { - String val, *str = item->val_str(&val); - string valStr; - valStr.assign(str->ptr(), str->length()); - rc = new ConstantColumn(valStr); - (dynamic_cast(rc))->timeZone(gwi.thd->variables.time_zone->get_name()->ptr()); - break; - } - - case Item::REAL_ITEM: - { - String val, *str = item->val_str(&val); - string valStr; - valStr.assign(str->ptr(), str->length()); - rc = new ConstantColumn(valStr, item->val_real()); - (dynamic_cast(rc))->timeZone(gwi.thd->variables.time_zone->get_name()->ptr()); - break; - } - - case Item::DECIMAL_ITEM: - { - rc = buildDecimalColumn(item, gwi); - break; - } - case Item::FUNC_ITEM: { Item_func* ifp = (Item_func*)item; @@ -2954,7 +3171,7 @@ ReturnedColumn* buildReturnedColumn(Item* item, gp_walk_info& gwi, bool& nonSupp vector tmpVec; //bool hasAggColumn = false; uint16_t parseInfo = 0; - parse_item(ifp, tmpVec, gwi.fatalParseError, parseInfo); + parse_item(ifp, tmpVec, gwi.fatalParseError, parseInfo, &gwi); if (parseInfo & SUB_BIT) { @@ -3078,16 +3295,6 @@ ReturnedColumn* buildReturnedColumn(Item* item, gp_walk_info& gwi, bool& nonSupp break; } - case Item::DATE_ITEM: - { - String val, *str = item->val_str(&val); - string valStr; - valStr.assign(str->ptr(), str->length()); - rc = new ConstantColumn(valStr); - (dynamic_cast(rc))->timeZone(gwi.thd->variables.time_zone->get_name()->ptr()); - break; - } - case Item::WINDOW_FUNC_ITEM: { return buildWindowFunctionColumn(item, gwi, nonSupport); @@ -3403,7 +3610,7 @@ ReturnedColumn* buildFunctionColumn( return rc; } - // TODO MariaDB 10.1: Until we figure out what to do with this + // Item_equal is supported by buildPredicateItem() if (funcName == "multiple equal") return NULL; @@ -3444,18 +3651,23 @@ ReturnedColumn* buildFunctionColumn( for (uint32_t i = 1; i < ifp->argument_count(); i++) { - if (!(ifp->arguments()[i]->type() == Item::INT_ITEM || - ifp->arguments()[i]->type() == Item::STRING_ITEM || - ifp->arguments()[i]->type() == Item::REAL_ITEM || - ifp->arguments()[i]->type() == Item::DECIMAL_ITEM || - ifp->arguments()[i]->type() == Item::NULL_ITEM)) + if (!(ifp->arguments()[i]->type() == Item::NULL_ITEM || + (ifp->arguments()[i]->type() == Item::CONST_ITEM && + (ifp->arguments()[i]->cmp_type() == INT_RESULT || + ifp->arguments()[i]->cmp_type() == STRING_RESULT || + ifp->arguments()[i]->cmp_type() == REAL_RESULT || + ifp->arguments()[i]->cmp_type() == DECIMAL_RESULT + ) + ) + ) + ) { if (ifp->arguments()[i]->type() == Item::FUNC_ITEM) { // try to identify const F&E. fall to primitive if parms are constant F&E. vector tmpVec; uint16_t parseInfo = 0; - parse_item(ifp->arguments()[i], tmpVec, gwi.fatalParseError, parseInfo); + parse_item(ifp->arguments()[i], tmpVec, gwi.fatalParseError, parseInfo, &gwi); if (!gwi.fatalParseError && !(parseInfo & AF_BIT) && tmpVec.size() == 0) continue; @@ -4016,16 +4228,16 @@ FunctionColumn* buildCaseFunction(Item_func* item, gp_walk_info& gwi, bool& nonS ConstantColumn* buildDecimalColumn(Item* item, gp_walk_info& gwi) { Item_decimal* idp = (Item_decimal*)item; - IDB_Decimal infinidb_decimal; + IDB_Decimal columnstore_decimal; String val, *str = item->val_str(&val); string valStr; valStr.assign(str->ptr(), str->length()); - ostringstream infinidb_decimal_val; + ostringstream columnstore_decimal_val; uint32_t i = 0; if (str->ptr()[0] == '+' || str->ptr()[0] == '-') { - infinidb_decimal_val << str->ptr()[0]; + columnstore_decimal_val << str->ptr()[0]; i = 1; } @@ -4034,22 +4246,22 @@ ConstantColumn* buildDecimalColumn(Item* item, gp_walk_info& gwi) if (str->ptr()[i] == '.') continue; - infinidb_decimal_val << str->ptr()[i]; + columnstore_decimal_val << str->ptr()[i]; } - infinidb_decimal.value = strtoll(infinidb_decimal_val.str().c_str(), 0, 10); + columnstore_decimal.value = strtoll(columnstore_decimal_val.str().c_str(), 0, 10); if (gwi.internalDecimalScale >= 0 && idp->decimals > (uint)gwi.internalDecimalScale) { - infinidb_decimal.scale = gwi.internalDecimalScale; - double val = (double)(infinidb_decimal.value / pow((double)10, idp->decimals - gwi.internalDecimalScale)); - infinidb_decimal.value = (int64_t)(val > 0 ? val + 0.5 : val - 0.5); + columnstore_decimal.scale = gwi.internalDecimalScale; + double val = (double)(columnstore_decimal.value / pow((double)10, idp->decimals - gwi.internalDecimalScale)); + columnstore_decimal.value = (int64_t)(val > 0 ? val + 0.5 : val - 0.5); } else - infinidb_decimal.scale = idp->decimals; + columnstore_decimal.scale = idp->decimals; - infinidb_decimal.precision = idp->max_length - idp->decimals; - ConstantColumn* cc = new ConstantColumn(valStr, infinidb_decimal); + columnstore_decimal.precision = idp->max_length - idp->decimals; + ConstantColumn* cc = new ConstantColumn(valStr, columnstore_decimal); cc->timeZone(gwi.thd->variables.time_zone->get_name()->ptr()); return cc; } @@ -4073,18 +4285,18 @@ SimpleColumn* buildSimpleColumn(Item_field* ifp, gp_walk_info& gwi) return buildSimpleColFromDerivedTable(gwi, ifp); CalpontSystemCatalog::ColType ct; - bool infiniDB = true; + bool columnStore = true; try { // check foreign engine if (ifp->cached_table && ifp->cached_table->table) - infiniDB = isInfiniDB(ifp->cached_table->table); + columnStore = isMCSTable(ifp->cached_table->table); // @bug4509. ifp->cached_table could be null for myisam sometimes else if (ifp->field && ifp->field->table) - infiniDB = isInfiniDB(ifp->field->table); + columnStore = isMCSTable(ifp->field->table); - if (infiniDB) + if (columnStore) { ct = gwi.csc->colType( gwi.csc->lookupOID(make_tcn(ifp->db_name, bestTableName(ifp), ifp->field_name.str))); @@ -4107,10 +4319,10 @@ SimpleColumn* buildSimpleColumn(Item_field* ifp, gp_walk_info& gwi) { case CalpontSystemCatalog::TINYINT: if (ct.scale == 0) - sc = new SimpleColumn_INT<1>(ifp->db_name, bestTableName(ifp), ifp->field_name.str, infiniDB, gwi.sessionid); + sc = new SimpleColumn_INT<1>(ifp->db_name, bestTableName(ifp), ifp->field_name.str, columnStore, gwi.sessionid); else { - sc = new SimpleColumn_Decimal<1>(ifp->db_name, bestTableName(ifp), ifp->field_name.str, infiniDB, gwi.sessionid); + sc = new SimpleColumn_Decimal<1>(ifp->db_name, bestTableName(ifp), ifp->field_name.str, columnStore, gwi.sessionid); ct.colDataType = CalpontSystemCatalog::DECIMAL; } @@ -4118,10 +4330,10 @@ SimpleColumn* buildSimpleColumn(Item_field* ifp, gp_walk_info& gwi) case CalpontSystemCatalog::SMALLINT: if (ct.scale == 0) - sc = new SimpleColumn_INT<2>(ifp->db_name, bestTableName(ifp), ifp->field_name.str, infiniDB, gwi.sessionid); + sc = new SimpleColumn_INT<2>(ifp->db_name, bestTableName(ifp), ifp->field_name.str, columnStore, gwi.sessionid); else { - sc = new SimpleColumn_Decimal<2>(ifp->db_name, bestTableName(ifp), ifp->field_name.str, infiniDB, gwi.sessionid); + sc = new SimpleColumn_Decimal<2>(ifp->db_name, bestTableName(ifp), ifp->field_name.str, columnStore, gwi.sessionid); ct.colDataType = CalpontSystemCatalog::DECIMAL; } @@ -4130,10 +4342,10 @@ SimpleColumn* buildSimpleColumn(Item_field* ifp, gp_walk_info& gwi) case CalpontSystemCatalog::INT: case CalpontSystemCatalog::MEDINT: if (ct.scale == 0) - sc = new SimpleColumn_INT<4>(ifp->db_name, bestTableName(ifp), ifp->field_name.str, infiniDB, gwi.sessionid); + sc = new SimpleColumn_INT<4>(ifp->db_name, bestTableName(ifp), ifp->field_name.str, columnStore, gwi.sessionid); else { - sc = new SimpleColumn_Decimal<4>(ifp->db_name, bestTableName(ifp), ifp->field_name.str, infiniDB, gwi.sessionid); + sc = new SimpleColumn_Decimal<4>(ifp->db_name, bestTableName(ifp), ifp->field_name.str, columnStore, gwi.sessionid); ct.colDataType = CalpontSystemCatalog::DECIMAL; } @@ -4141,34 +4353,34 @@ SimpleColumn* buildSimpleColumn(Item_field* ifp, gp_walk_info& gwi) case CalpontSystemCatalog::BIGINT: if (ct.scale == 0) - sc = new SimpleColumn_INT<8>(ifp->db_name, bestTableName(ifp), ifp->field_name.str, infiniDB, gwi.sessionid); + sc = new SimpleColumn_INT<8>(ifp->db_name, bestTableName(ifp), ifp->field_name.str, columnStore, gwi.sessionid); else { - sc = new SimpleColumn_Decimal<8>(ifp->db_name, bestTableName(ifp), ifp->field_name.str, infiniDB, gwi.sessionid); + sc = new SimpleColumn_Decimal<8>(ifp->db_name, bestTableName(ifp), ifp->field_name.str, columnStore, gwi.sessionid); ct.colDataType = CalpontSystemCatalog::DECIMAL; } break; case CalpontSystemCatalog::UTINYINT: - sc = new SimpleColumn_UINT<1>(ifp->db_name, bestTableName(ifp), ifp->field_name.str, infiniDB, gwi.sessionid); + sc = new SimpleColumn_UINT<1>(ifp->db_name, bestTableName(ifp), ifp->field_name.str, columnStore, gwi.sessionid); break; case CalpontSystemCatalog::USMALLINT: - sc = new SimpleColumn_UINT<2>(ifp->db_name, bestTableName(ifp), ifp->field_name.str, infiniDB, gwi.sessionid); + sc = new SimpleColumn_UINT<2>(ifp->db_name, bestTableName(ifp), ifp->field_name.str, columnStore, gwi.sessionid); break; case CalpontSystemCatalog::UINT: case CalpontSystemCatalog::UMEDINT: - sc = new SimpleColumn_UINT<4>(ifp->db_name, bestTableName(ifp), ifp->field_name.str, infiniDB, gwi.sessionid); + sc = new SimpleColumn_UINT<4>(ifp->db_name, bestTableName(ifp), ifp->field_name.str, columnStore, gwi.sessionid); break; case CalpontSystemCatalog::UBIGINT: - sc = new SimpleColumn_UINT<8>(ifp->db_name, bestTableName(ifp), ifp->field_name.str, infiniDB, gwi.sessionid); + sc = new SimpleColumn_UINT<8>(ifp->db_name, bestTableName(ifp), ifp->field_name.str, columnStore, gwi.sessionid); break; default: - sc = new SimpleColumn(ifp->db_name, bestTableName(ifp), ifp->field_name.str, infiniDB, gwi.sessionid); + sc = new SimpleColumn(ifp->db_name, bestTableName(ifp), ifp->field_name.str, columnStore, gwi.sessionid); } sc->resultType(ct); @@ -4186,10 +4398,10 @@ SimpleColumn* buildSimpleColumn(Item_field* ifp, gp_walk_info& gwi) sc->viewName(lower(getViewName(ifp->cached_table))); sc->alias(ifp->name.str); - sc->isInfiniDB(infiniDB); + sc->isColumnStore(columnStore); sc->timeZone(gwi.thd->variables.time_zone->get_name()->ptr()); - if (!infiniDB && ifp->field) + if (!columnStore && ifp->field) sc->oid(ifp->field->field_index + 1); // ExeMgr requires offset started from 1 if (ifp->depended_from) @@ -4321,7 +4533,7 @@ ReturnedColumn* buildAggregateColumn(Item* item, gp_walk_info& gwi) RowColumn* rowCol = new RowColumn(); vector selCols; - uint32_t select_ctn = gc->count_field(); + uint32_t select_ctn = gc->get_count_field(); ReturnedColumn* rc = NULL; for (uint32_t i = 0; i < select_ctn; i++) @@ -4342,12 +4554,13 @@ ReturnedColumn* buildAggregateColumn(Item* item, gp_walk_info& gwi) ORDER** order_item, **end; for (order_item = gc->get_order(), - end = order_item + gc->order_field(); order_item < end; + end = order_item + gc->get_order_field(); order_item < end; order_item++) { Item* ord_col = *(*order_item)->item; - if (ord_col->type() == Item::INT_ITEM) + if (ord_col->type() == Item::CONST_ITEM + && ord_col->cmp_type() == INT_RESULT) { Item_int* id = (Item_int*)ord_col; @@ -4387,10 +4600,10 @@ ReturnedColumn* buildAggregateColumn(Item* item, gp_walk_info& gwi) parm.reset(rowCol); ac->aggParms().push_back(parm); - if (gc->str_separator()) + if (gc->get_separator()) { string separator; - separator.assign(gc->str_separator()->ptr(), gc->str_separator()->length()); + separator.assign(gc->get_separator()->ptr(), gc->get_separator()->length()); (dynamic_cast(ac))->separator(separator); } } @@ -4417,22 +4630,33 @@ ReturnedColumn* buildAggregateColumn(Item* item, gp_walk_info& gwi) parm.reset(sc); gwi.columnMap.insert(CalpontSelectExecutionPlan::ColumnMap::value_type(string(ifp->field_name.str), parm)); TABLE_LIST* tmp = (ifp->cached_table ? ifp->cached_table : 0); - gwi.tableMap[make_aliastable(sc->schemaName(), sc->tableName(), sc->tableAlias(), sc->isInfiniDB())] = make_pair(1, tmp); + gwi.tableMap[make_aliastable(sc->schemaName(), sc->tableName(), sc->tableAlias(), sc->isColumnStore())] = make_pair(1, tmp); break; } - case Item::INT_ITEM: - case Item::STRING_ITEM: - case Item::REAL_ITEM: - case Item::DECIMAL_ITEM: + case Item::CONST_ITEM: { - // treat as count(*) - if (ac->aggOp() == AggregateColumn::COUNT) - ac->aggOp(AggregateColumn::COUNT_ASTERISK); + switch(sfitemp->cmp_type()) + { + case INT_RESULT: + case STRING_RESULT: + case REAL_RESULT: + case DECIMAL_RESULT: + { + // treat as count(*) + if (ac->aggOp() == AggregateColumn::COUNT) + ac->aggOp(AggregateColumn::COUNT_ASTERISK); - parm.reset(buildReturnedColumn(sfitemp, gwi, gwi.fatalParseError)); - ac->constCol(parm); - bIsConst = true; + parm.reset(buildReturnedColumn(sfitemp, gwi, gwi.fatalParseError)); + ac->constCol(parm); + bIsConst = true; + break; + } + default: + { + gwi.fatalParseError = true; + } + } break; } @@ -4452,7 +4676,7 @@ ReturnedColumn* buildAggregateColumn(Item* item, gp_walk_info& gwi) // check count(1+1) case vector tmpVec; uint16_t parseInfo = 0; - parse_item(ifp, tmpVec, gwi.fatalParseError, parseInfo); + parse_item(ifp, tmpVec, gwi.fatalParseError, parseInfo, &gwi); if (parseInfo & SUB_BIT) { @@ -4516,7 +4740,6 @@ ReturnedColumn* buildAggregateColumn(Item* item, gp_walk_info& gwi) default: { gwi.fatalParseError = true; - //gwi.parseErrorText = "Non-supported Item in Aggregate function"; } } @@ -4779,7 +5002,7 @@ void addIntervalArgs(THD* thd, Item_func* ifp, FunctionParm& functionParms) if (funcName == "date_add_interval") interval_type = ((Item_date_add_interval*)ifp)->int_type; else if (funcName == "timestampdiff") - interval_type = ((Item_func_timestamp_diff*)ifp)->int_type; + interval_type = ((Item_func_timestamp_diff*)ifp)->get_int_type(); else if (funcName == "extract") interval_type = ((Item_extract*)ifp)->int_type; @@ -4816,7 +5039,7 @@ void castCharArgs(THD* thd, Item_func* ifp, FunctionParm& functionParms) Item_char_typecast* idai = (Item_char_typecast*)ifp; SPTP sptp; - sptp.reset(new ParseTree(new ConstantColumn((int64_t)idai->castLength()))); + sptp.reset(new ParseTree(new ConstantColumn((int64_t)idai->get_cast_length()))); (dynamic_cast(sptp->data()))->timeZone(thd->variables.time_zone->get_name()->ptr()); functionParms.push_back(sptp); } @@ -4894,9 +5117,7 @@ void gp_walk(const Item* item, void* arg) string aliasTableName(scp->tableAlias()); scp->tableAlias(lower(aliasTableName)); gwip->rcWorkStack.push(scp->clone()); - //gwip->rcWorkStack.push(scp); boost::shared_ptr scsp(scp); - //boost::shared_ptr scsp(scp->clone()); gwip->scsp = scsp; gwip->funcName.clear(); @@ -4907,7 +5128,7 @@ void gp_walk(const Item* item, void* arg) if (!((scp->joinInfo() & JOIN_CORRELATED) || scp->colType().colDataType == CalpontSystemCatalog::VARBINARY)) { TABLE_LIST* tmp = (ifp->cached_table ? ifp->cached_table : 0); - gwip->tableMap[make_aliastable(scp->schemaName(), scp->tableName(), scp->tableAlias(), scp->isInfiniDB())] = + gwip->tableMap[make_aliastable(scp->schemaName(), scp->tableName(), scp->tableAlias(), scp->isColumnStore())] = make_pair(1, tmp); } } @@ -4915,67 +5136,90 @@ void gp_walk(const Item* item, void* arg) break; } - case Item::INT_ITEM: + case Item::CONST_ITEM: { - Item_int* iip = (Item_int*)item; - gwip->rcWorkStack.push(buildReturnedColumn(iip, *gwip, gwip->fatalParseError)); - break; - } - - case Item::STRING_ITEM: - { - Item_string* isp = (Item_string*)item; - - if (isp) + switch(item->cmp_type()) { - if (isp->result_type() == STRING_RESULT) + case INT_RESULT: { - String val, *str = isp->val_str(&val); - string cval; - - if (str->ptr()) - { - cval.assign(str->ptr(), str->length()); - } - - gwip->rcWorkStack.push(new ConstantColumn(cval)); - (dynamic_cast(gwip->rcWorkStack.top()))->timeZone(gwip->thd->variables.time_zone->get_name()->ptr()); + Item_int* iip = (Item_int*)item; + gwip->rcWorkStack.push(buildReturnedColumn(iip, *gwip, gwip->fatalParseError)); break; } - gwip->rcWorkStack.push(buildReturnedColumn(isp, *gwip, gwip->fatalParseError)); + case STRING_RESULT: + { + Item_string* isp = (Item_string*)item; + + if (isp) + { + if (isp->result_type() == STRING_RESULT) + { + String val, *str = isp->val_str(&val); + string cval; + + if (str->ptr()) + { + cval.assign(str->ptr(), str->length()); + } + + gwip->rcWorkStack.push(new ConstantColumn(cval)); + (dynamic_cast(gwip->rcWorkStack.top()))->timeZone(gwip->thd->variables.time_zone->get_name()->ptr()); + break; + } + + gwip->rcWorkStack.push(buildReturnedColumn(isp, *gwip, gwip->fatalParseError)); + } + break; + } + + case REAL_RESULT: + { + Item_float* ifp = (Item_float*)item; + gwip->rcWorkStack.push(buildReturnedColumn(ifp, *gwip, gwip->fatalParseError)); + break; + } + + case DECIMAL_RESULT: + { + Item_decimal* idp = (Item_decimal*)item; + gwip->rcWorkStack.push(buildReturnedColumn(idp, *gwip, gwip->fatalParseError)); + break; + } + + case TIME_RESULT: + { + Item_temporal_literal* itp = (Item_temporal_literal*)item; + gwip->rcWorkStack.push(buildReturnedColumn(itp, *gwip, gwip->fatalParseError)); + break; + } + default: + { + if (gwip->condPush) + { + // push noop for unhandled item + SimpleColumn* rc = new SimpleColumn("noop"); + rc->timeZone(gwip->thd->variables.time_zone->get_name()->ptr()); + gwip->rcWorkStack.push(rc); + break; + } + + ostringstream oss; + oss << "Unhandled Item type: " << item->type(); + gwip->parseErrorText = oss.str(); + gwip->fatalParseError = true; + break; + } } - break; } - - case Item::REAL_ITEM: - { - Item_float* ifp = (Item_float*)item; - gwip->rcWorkStack.push(buildReturnedColumn(ifp, *gwip, gwip->fatalParseError)); - break; - } - - case Item::DECIMAL_ITEM: - { - Item_decimal* idp = (Item_decimal*)item; - gwip->rcWorkStack.push(buildReturnedColumn(idp, *gwip, gwip->fatalParseError)); - break; - } - - case Item::VARBIN_ITEM: - { - Item_hex_string* hdp = (Item_hex_string*)item; - gwip->rcWorkStack.push(buildReturnedColumn(hdp, *gwip, gwip->fatalParseError)); - break; - } - case Item::NULL_ITEM: { if (gwip->condPush) { // push noop for unhandled item SimpleColumn* rc = new SimpleColumn("noop"); + rc->timeZone(gwip->thd->variables.time_zone->get_name()->ptr()); gwip->rcWorkStack.push(rc); break; } @@ -5037,7 +5281,7 @@ void gp_walk(const Item* item, void* arg) // try to evaluate const F&E vector tmpVec; uint16_t parseInfo = 0; - parse_item(ifp, tmpVec, gwip->fatalParseError, parseInfo); + parse_item(ifp, tmpVec, gwip->fatalParseError, parseInfo, gwip); // table mode takes only one table filter if (gwip->condPush) @@ -5202,7 +5446,7 @@ void gp_walk(const Item* item, void* arg) { vector fieldVec; uint16_t parseInfo = 0; - parse_item(it, fieldVec, gwip->fatalParseError, parseInfo); + parse_item(it, fieldVec, gwip->fatalParseError, parseInfo, gwip); if (parseInfo & CORRELATED) { @@ -5213,10 +5457,13 @@ void gp_walk(const Item* item, void* arg) } if ((it->type() == Item::FIELD_ITEM - || it->type() == Item::INT_ITEM - || it->type() == Item::DECIMAL_ITEM - || it->type() == Item::STRING_ITEM - || it->type() == Item::REAL_ITEM + || ( it->type() == Item::CONST_ITEM + && ( it->cmp_type() == INT_RESULT + || it->cmp_type() == DECIMAL_RESULT + || it->cmp_type() == STRING_RESULT + || it->cmp_type() == REAL_RESULT + ) + ) || it->type() == Item::NULL_ITEM || (it->type() == Item::FUNC_ITEM && !isPredicateFunction(it, gwip))) && !gwip->rcWorkStack.empty() @@ -5413,14 +5660,15 @@ void gp_walk(const Item* item, void* arg) gwip->hasSubSelect = true; gwip->subQuery = existsSub; gwip->ptWorkStack.push(existsSub->transform()); - current_thd->infinidb_vtable.isUnion = true; // only temp. bypass the 2nd phase. + // MCOL-2178 isUnion member only assigned, never used + //MIGR::infinidb_vtable.isUnion = true; // only temp. bypass the 2nd phase. // recover original gwip->subQuery = orig; gwip->lastSub = existsSub; } else if (sub->substype() == Item_subselect::IN_SUBS) { - if (!((Item_in_subselect*)sub)->getOptimizer() && gwip->thd->derived_tables_processing) + if (!((Item_in_subselect*)sub)->optimizer && gwip->thd->derived_tables_processing) { ostringstream oss; oss << "Invalid In_optimizer: " << item->type(); @@ -5459,12 +5707,6 @@ void gp_walk(const Item* item, void* arg) break; } - case Item::DATE_ITEM: - { - Item_temporal_literal* itp = (Item_temporal_literal*)item; - gwip->rcWorkStack.push(buildReturnedColumn(itp, *gwip, gwip->fatalParseError)); - break; - } case Item::WINDOW_FUNC_ITEM: { @@ -5506,10 +5748,6 @@ void gp_walk(const Item* item, void* arg) printf("********** received INSERT_VALUE_ITEM *********\n"); break; - case Item::Item::TYPE_HOLDER: - printf("********** received TYPE_HOLDER *********\n"); - break; - case Item::PARAM_ITEM: printf("********** received PARAM_ITEM *********\n"); break; @@ -5518,24 +5756,16 @@ void gp_walk(const Item* item, void* arg) printf("********** received TRIGGER_FIELD_ITEM *********\n"); break; - case Item::XPATH_NODESET: - printf("********** received XPATH_NODESET *********\n"); + case Item::TYPE_HOLDER: + std::cerr << "********** received TYPE_HOLDER *********" << std::endl; break; - - case Item::XPATH_NODESET_CMP: - printf("********** received XPATH_NODESET_CMP *********\n"); - break; - - case Item::VIEW_FIXER_ITEM: - printf("********** received VIEW_FIXER_ITEM *********\n"); - break; - default: { if (gwip->condPush) { // push noop for unhandled item SimpleColumn* rc = new SimpleColumn("noop"); + rc->timeZone(gwip->thd->variables.time_zone->get_name()->ptr()); gwip->rcWorkStack.push(rc); break; } @@ -5579,7 +5809,7 @@ void parse_item (Item* item, vector& field_vec, Item** sfitempp = isp->arguments(); for (uint32_t i = 0; i < isp->argument_count(); i++) - parse_item(sfitempp[i], field_vec, hasNonSupportItem, parseInfo); + parse_item(sfitempp[i], field_vec, hasNonSupportItem, parseInfo, gwi); break; } @@ -5598,7 +5828,6 @@ void parse_item (Item* item, vector& field_vec, for (uint32_t i = 0; i < isp->argument_count(); i++) parse_item(isp->arguments()[i], field_vec, hasNonSupportItem, parseInfo, gwi); -// parse_item(sfitempp[i], field_vec, hasNonSupportItem, parseInfo); break; } @@ -5609,7 +5838,7 @@ void parse_item (Item* item, vector& field_vec, Item* cond_item; while ((cond_item = it++)) - parse_item(cond_item, field_vec, hasNonSupportItem, parseInfo); + parse_item(cond_item, field_vec, hasNonSupportItem, parseInfo, gwi); break; } @@ -5628,14 +5857,19 @@ void parse_item (Item* item, vector& field_vec, // special handling for count(*). This should not be treated as constant. if (isp->argument_count() == 1 && - (sfitempp[0]->type() == Item::INT_ITEM || - sfitempp[0]->type() == Item::STRING_ITEM || - sfitempp[0]->type() == Item::REAL_ITEM || - sfitempp[0]->type() == Item::DECIMAL_ITEM)) + ( sfitempp[0]->type() == Item::CONST_ITEM && + (sfitempp[0]->cmp_type() == INT_RESULT || + sfitempp[0]->cmp_type() == STRING_RESULT || + sfitempp[0]->cmp_type() == REAL_RESULT || + sfitempp[0]->cmp_type() == DECIMAL_RESULT) + ) + ) + { field_vec.push_back((Item_field*)item); //dummy + } for (uint32_t i = 0; i < isp->argument_count(); i++) - parse_item(sfitempp[i], field_vec, hasNonSupportItem, parseInfo); + parse_item(sfitempp[i], field_vec, hasNonSupportItem, parseInfo, gwi); break; } @@ -5663,14 +5897,14 @@ void parse_item (Item* item, vector& field_vec, Item** sfitempp = isp->arguments(); for (uint32_t i = 0; i < isp->argument_count(); i++) - parse_item(sfitempp[i], field_vec, hasNonSupportItem, parseInfo); + parse_item(sfitempp[i], field_vec, hasNonSupportItem, parseInfo, gwi); break; } else if ((*(ref->ref))->type() == Item::CACHE_ITEM) { Item_cache* isp = reinterpret_cast(*(ref->ref)); - parse_item(isp->get_example(), field_vec, hasNonSupportItem, parseInfo); + parse_item(isp->get_example(), field_vec, hasNonSupportItem, parseInfo, gwi); break; } else if ((*(ref->ref))->type() == Item::REF_ITEM) @@ -5709,7 +5943,7 @@ void parse_item (Item* item, vector& field_vec, Item_row* row = (Item_row*)item; for (uint32_t i = 0; i < row->cols(); i++) - parse_item(row->element_index(i), field_vec, hasNonSupportItem, parseInfo); + parse_item(row->element_index(i), field_vec, hasNonSupportItem, parseInfo, gwi); break; } @@ -5717,7 +5951,11 @@ void parse_item (Item* item, vector& field_vec, case Item::EXPR_CACHE_ITEM: { // item is a Item_cache_wrapper. Shouldn't get here. - printf("EXPR_CACHE_ITEM in parse_item\n"); + // WIP Why + IDEBUG(std::cerr << "EXPR_CACHE_ITEM in parse_item\n" << std::endl); + gwi->fatalParseError = true; + // DRRTUY The questionable error text. I've seen + // ERR_CORRELATED_SUB_OR string parseErrorText = IDBErrorInfo::instance()->errorMsg(ERR_NON_SUPPORT_SUB_QUERY_TYPE); setError(gwi->thd, ER_CHECK_NOT_IMPLEMENTED, parseErrorText); break; @@ -5732,7 +5970,7 @@ void parse_item (Item* item, vector& field_vec, } } -bool isInfiniDB(TABLE* table_ptr) +bool isMCSTable(TABLE* table_ptr) { #if (defined(_MSC_VER) && defined(_DEBUG)) || defined(SAFE_MUTEX) @@ -5754,19 +5992,24 @@ bool isInfiniDB(TABLE* table_ptr) return false; } -int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool isUnion) +int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, + SCSEP& csep, + bool isUnion, + bool isPushdownHand) { #ifdef DEBUG_WALK_COND cerr << "getSelectPlan()" << endl; #endif // by pass the derived table resolve phase of mysql - if (!(((gwi.thd->lex)->sql_command == SQLCOM_UPDATE ) || + if ( !isPushdownHand && + !(((gwi.thd->lex)->sql_command == SQLCOM_UPDATE ) || ((gwi.thd->lex)->sql_command == SQLCOM_DELETE ) || ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE_MULTI ) || ((gwi.thd->lex)->sql_command == SQLCOM_DELETE_MULTI ) ) && gwi.thd->derived_tables_processing) { - gwi.thd->infinidb_vtable.isUnion = false; + // MCOL-2178 isUnion member only assigned, never used + //MIGR::infinidb_vtable.isUnion = false; return -1; } @@ -5814,7 +6057,7 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i // @bug 2123. Override large table estimate if infinidb_ordered hint was used. // @bug 2404. Always override if the infinidb_ordered_only variable is turned on. - if (gwi.thd->infinidb_vtable.override_largeside_estimate || get_ordered_only(gwi.thd)) + if (get_ordered_only(gwi.thd)) csep->overrideLargeSideEstimate(true); // @bug 5741. Set a flag when in Local PM only query mode @@ -5878,10 +6121,10 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i if (table_ptr->derived) { String str; - (table_ptr->derived->first_select())->print(gwi.thd, &str, QT_INFINIDB_DERIVED); + (table_ptr->derived->first_select())->print(gwi.thd, &str, QT_ORDINARY); SELECT_LEX* select_cursor = table_ptr->derived->first_select(); - FromSubQuery fromSub(gwi, select_cursor); + FromSubQuery fromSub(gwi, select_cursor, isPushdownHand); string alias(table_ptr->alias.str); fromSub.alias(lower(alias)); @@ -5900,11 +6143,12 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i gwi.tbList.push_back(tn); CalpontSystemCatalog::TableAliasName tan = make_aliastable("", alias, alias); gwi.tableMap[tan] = make_pair(0, table_ptr); - gwi.thd->infinidb_vtable.isUnion = true; //by-pass the 2nd pass of rnd_init + // MCOL-2178 isUnion member only assigned, never used + //MIGR::infinidb_vtable.isUnion = true; //by-pass the 2nd pass of rnd_init } else if (table_ptr->view) { - View* view = new View(table_ptr->view->select_lex, &gwi); + View* view = new View(*table_ptr->view->first_select_lex(), &gwi); CalpontSystemCatalog::TableAliasName tn = make_aliastable(table_ptr->db.str, table_ptr->table_name.str, table_ptr->alias.str); view->viewName(tn); gwi.viewList.push_back(view); @@ -5913,10 +6157,10 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i else { // check foreign engine tables - bool infiniDB = (table_ptr->table ? isInfiniDB(table_ptr->table) : true); + bool columnStore = (table_ptr->table ? isMCSTable(table_ptr->table) : true); // trigger system catalog cache - if (infiniDB) + if (columnStore) csc->columnRIDs(make_table(table_ptr->db.str, table_ptr->table_name.str), true); string table_name = table_ptr->table_name.str; @@ -5925,9 +6169,9 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i if (table_ptr->db.length && strcmp(table_ptr->db.str, "information_schema") == 0) table_name = (table_ptr->schema_table_name.length ? table_ptr->schema_table_name.str : table_ptr->alias.str); - CalpontSystemCatalog::TableAliasName tn = make_aliasview(table_ptr->db.str, table_name, table_ptr->alias.str, viewName, infiniDB); + CalpontSystemCatalog::TableAliasName tn = make_aliasview(table_ptr->db.str, table_name, table_ptr->alias.str, viewName, columnStore); gwi.tbList.push_back(tn); - CalpontSystemCatalog::TableAliasName tan = make_aliastable(table_ptr->db.str, table_name, table_ptr->alias.str, infiniDB); + CalpontSystemCatalog::TableAliasName tan = make_aliastable(table_ptr->db.str, table_name, table_ptr->alias.str, columnStore); gwi.tableMap[tan] = make_pair(0, table_ptr); #ifdef DEBUG_WALK_COND cerr << tn << endl; @@ -5965,9 +6209,14 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i bool unionSel = false; + // UNION master unit check + // Existed pushdown handlers won't get in this scope + // except UNION pushdown that is to come. + // is_unit_op() give a segv for derived_handler's SELECT_LEX if (!isUnion && select_lex.master_unit()->is_unit_op()) { - gwi.thd->infinidb_vtable.isUnion = true; + // MCOL-2178 isUnion member only assigned, never used + //MIGR::infinidb_vtable.isUnion = true; CalpontSelectExecutionPlan::SelectList unionVec; SELECT_LEX* select_cursor = select_lex.master_unit()->first_select(); unionSel = true; @@ -6000,7 +6249,7 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i union_gwi.thd = gwi.thd; uint32_t err = 0; - if ((err = getSelectPlan(union_gwi, *sl, plan, unionSel)) != 0) + if ((err = getSelectPlan(union_gwi, *sl, plan, unionSel, isPushdownHand)) != 0) return err; unionVec.push_back(SCEP(plan)); @@ -6026,7 +6275,7 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i csep->distinctUnionNum(distUnionNum); if (unionVec.empty()) - gwi.thd->infinidb_vtable.impossibleWhereOnUnion = true; + gwi.cs_vtable_impossible_where_on_union = true; } gwi.clauseType = WHERE; @@ -6036,7 +6285,7 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i // MariaDB bug 624 - without the fix_fields call, delete with join may error with "No query step". //#if MYSQL_VERSION_ID < 50172 //@bug 3039. fix fields for constants - if (!icp->fixed) + if (!icp->is_fixed()) { icp->fix_fields(gwi.thd, (Item**)&icp); } @@ -6046,6 +6295,27 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i #ifdef DEBUG_WALK_COND cerr << "------------------ WHERE -----------------------" << endl; icp->traverse_cond(debug_walk, &gwi, Item::POSTFIX); + if (join && join->cond_equal) + { + List_iterator li(join->cond_equal->current_level); + Item_equal *cur_item_eq; + while ((cur_item_eq= li++)) + { + // WIP replace the block with + //cur_item_eq->traverse_cond(debug_walk, gwip, Item::POSTFIX); + std::cerr << "item_equal("; + Item *item; + Item_equal_fields_iterator it(*cur_item_eq); + while ((item= it++)) + { + std::ostringstream ostream; + std::ostringstream& osr = ostream; + getColNameFromItem(osr, item); + std::cerr << osr.str() << ","; + } + std::cerr << ")" << std::endl; + } + } cerr << "------------------------------------------------\n" << endl; #endif @@ -6059,14 +6329,28 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i // processing. if (gwi.thd->derived_tables_processing) { - gwi.thd->infinidb_vtable.isUnion = false; - gwi.thd->infinidb_vtable.isUpdateWithDerive = true; + // MCOL-2178 isUnion member only assigned, never used + //MIGR::infinidb_vtable.isUnion = false; + gwi.cs_vtable_is_update_with_derive = true; return -1; } setError(gwi.thd, ER_INTERNAL_ERROR, gwi.parseErrorText, gwi); return ER_INTERNAL_ERROR; } + + // MCOL-3416 support for EQUAL_COND in MDB >= 10.1 + if (join && join->cond_equal) + { + // TODO MCOL-3416 This must traverse all levels not current_level only + List_iterator li(join->cond_equal->current_level); + Item_equal *cur_item_eq; + while ((cur_item_eq= li++)) + { + cur_item_eq->traverse_cond(gp_walk, &gwi, Item::POSTFIX); + } + } + } else if (join && join->zero_result_cause) { @@ -6080,62 +6364,63 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i #ifdef OUTER_JOIN_DEBUG List* tables = &(select_lex.top_join_list); List_iterator_fast ti(*tables); - //TABLE_LIST *inner; - //TABLE_LIST **table= (TABLE_LIST **)gwi.thd->alloc(sizeof(TABLE_LIST*) * tables->elements); - //for (TABLE_LIST **t= table + (tables->elements - 1); t >= table; t--) - // *t= ti++; - //DBUG_ASSERT(tables->elements >= 1); + TABLE_LIST **table= (TABLE_LIST **)gwi.thd->alloc(sizeof(TABLE_LIST*) * tables->elements); + for (TABLE_LIST **t= table + (tables->elements - 1); t >= table; t--) + *t= ti++; - //TABLE_LIST **end= table + tables->elements; - //for (TABLE_LIST **tbl= table; tbl < end; tbl++) - TABLE_LIST* curr; + DBUG_ASSERT(tables->elements >= 1); - while ((curr = ti++)) + TABLE_LIST **end= table + tables->elements; + for (TABLE_LIST **tbl= table; tbl < end; tbl++) { - TABLE_LIST* curr = *tbl; + TABLE_LIST* curr; - if (curr->table_name) - cerr << curr->table_name << " "; - else - cerr << curr->alias << endl; - - if (curr->outer_join) - cerr << " is inner table" << endl; - else if (curr->straight) - cerr << "straight_join" << endl; - else - cerr << "join" << endl; - - if (curr->nested_join) + while ((curr = ti++)) { - List* inners = &(curr->nested_join->join_list); - List_iterator_fast li(*inners); - TABLE_LIST** inner = (TABLE_LIST**)gwi.thd->alloc(sizeof(TABLE_LIST*) * inners->elements); + TABLE_LIST* curr = *tbl; - for (TABLE_LIST** t = inner + (inners->elements - 1); t >= inner; t--) - *t = li++; + if (curr->table_name.length) + cerr << curr->table_name.str << " "; + else + cerr << curr->alias.str << endl; - TABLE_LIST** end1 = inner + inners->elements; + if (curr->outer_join) + cerr << " is inner table" << endl; + else if (curr->straight) + cerr << "straight_join" << endl; + else + cerr << "join" << endl; - for (TABLE_LIST** tb = inner; tb < end1; tb++) + if (curr->nested_join) { - TABLE_LIST* curr1 = *tb; - cerr << curr1->alias << endl; + List* inners = &(curr->nested_join->join_list); + List_iterator_fast li(*inners); + TABLE_LIST** inner = (TABLE_LIST**)gwi.thd->alloc(sizeof(TABLE_LIST*) * inners->elements); - if (curr1->sj_on_expr) + for (TABLE_LIST** t = inner + (inners->elements - 1); t >= inner; t--) + *t = li++; + + TABLE_LIST** end1 = inner + inners->elements; + + for (TABLE_LIST** tb = inner; tb < end1; tb++) { - curr1->sj_on_expr->traverse_cond(debug_walk, &gwi, Item::POSTFIX); + TABLE_LIST* curr1 = *tb; + cerr << curr1->alias.str << endl; + + if (curr1->sj_on_expr) + { + curr1->sj_on_expr->traverse_cond(debug_walk, &gwi, Item::POSTFIX); + } } } - } - if (curr->sj_on_expr) - { - curr->sj_on_expr->traverse_cond(debug_walk, &gwi, Item::POSTFIX); + if (curr->sj_on_expr) + { + curr->sj_on_expr->traverse_cond(debug_walk, &gwi, Item::POSTFIX); + } } } - #endif uint32_t failed = buildOuterJoin(gwi, select_lex); @@ -6215,9 +6500,6 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i List_iterator_fast it(select_lex.item_list); Item* item; vector funcFieldVec; - string sel_cols_in_create; - string sel_cols_in_select; - bool redo = false; // empty rcWorkStack and ptWorkStack. They should all be empty by now. clearStacks(gwi); @@ -6267,18 +6549,13 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i { boost::shared_ptr spsc(sc); - if (sel_cols_in_create.length() != 0) - sel_cols_in_create += ", "; - string fullname; String str; - ifp->print(&str, QT_INFINIDB_NO_QUOTE); + ifp->print(&str, QT_ORDINARY); fullname = str.c_ptr(); - //sel_cols_in_create += fullname; if (ifp->is_autogenerated_name) // no alias { - sel_cols_in_create += fullname + " `" + escapeBackTick(str.c_ptr()) + "`"; sc->alias(fullname); } else // alias @@ -6286,15 +6563,8 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i if (!itemAlias.empty()) sc->alias(itemAlias); - sel_cols_in_create += fullname + " `" + escapeBackTick(sc->alias().c_str()) + "`"; } - if (ifp->is_autogenerated_name) - gwi.selectCols.push_back("`" + escapeBackTick(fullname.c_str()) + "`" + " `" + - escapeBackTick(itemAlias.empty() ? ifp->name.str : itemAlias.c_str()) + "`"); - else - gwi.selectCols.push_back("`" + escapeBackTick((itemAlias.empty() ? ifp->name.str : itemAlias.c_str())) + "`"); - gwi.returnedCols.push_back(spsc); gwi.columnMap.insert(CalpontSelectExecutionPlan::ColumnMap::value_type(string(ifp->field_name.str), spsc)); @@ -6303,7 +6573,7 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i if (ifp->cached_table) tmp = ifp->cached_table; - gwi.tableMap[make_aliastable(sc->schemaName(), sc->tableName(), sc->tableAlias(), sc->isInfiniDB())] = + gwi.tableMap[make_aliastable(sc->schemaName(), sc->tableName(), sc->tableAlias(), sc->isColumnStore())] = make_pair(1, tmp); } else @@ -6332,14 +6602,6 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i // add this agg col to returnedColumnList boost::shared_ptr spac(ac); gwi.returnedCols.push_back(spac); - gwi.selectCols.push_back('`' + escapeBackTick(spac->alias().c_str()) + '`'); - String str(256); - item->print(&str, QT_INFINIDB_NO_QUOTE); - - if (sel_cols_in_create.length() != 0) - sel_cols_in_create += ", "; - - sel_cols_in_create += string(str.c_ptr()) + " `" + escapeBackTick(spac->alias().c_str()) + "`"; break; } @@ -6367,7 +6629,7 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i uint16_t parseInfo = 0; vector tmpVec; bool hasNonSupportItem = false; - parse_item(ifp, tmpVec, hasNonSupportItem, parseInfo); + parse_item(ifp, tmpVec, hasNonSupportItem, parseInfo, &gwi); if (ifp->with_subquery() || string(ifp->func_name()) == string("") || @@ -6385,68 +6647,36 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i if (rc) { + // MCOL-2178 CS has to process determenistic functions with constant arguments. if (!hasNonSupportItem && !nonConstFunc(ifp) && !(parseInfo & AF_BIT) && tmpVec.size() == 0) { - if (isUnion || unionSel || gwi.subSelectType != CalpontSelectExecutionPlan::MAIN_SELECT || - parseInfo & SUB_BIT || select_lex.group_list.elements != 0) - { - srcp.reset(buildReturnedColumn(item, gwi, gwi.fatalParseError)); - gwi.returnedCols.push_back(srcp); + srcp.reset(buildReturnedColumn(item, gwi, gwi.fatalParseError)); + gwi.returnedCols.push_back(srcp); - if (ifp->name.length) - srcp->alias(ifp->name.str); + if (ifp->name.length) + srcp->alias(ifp->name.str); - continue; - } - - if ( ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE ) || - ((gwi.thd->lex)->sql_command == SQLCOM_DELETE ) || - ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE_MULTI ) || - ((gwi.thd->lex)->sql_command == SQLCOM_DELETE_MULTI ) ) - { } - else - { - redo = true; - String str; - ifp->print(&str, QT_INFINIDB_NO_QUOTE); - gwi.selectCols.push_back(string(str.c_ptr()) + " " + "`" + escapeBackTick(item->name.str) + "`"); - } - - break; + continue; } - //SRCP srcp(rc); gwi.returnedCols.push_back(srcp); - - if ( ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE ) || ((gwi.thd->lex)->sql_command == SQLCOM_DELETE ) || ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE_MULTI ) || ((gwi.thd->lex)->sql_command == SQLCOM_DELETE_MULTI )) - { } - else - { - String str(256); - ifp->print(&str, QT_INFINIDB_NO_QUOTE); - - if (sel_cols_in_create.length() != 0) - sel_cols_in_create += ", "; - - sel_cols_in_create += string(str.c_ptr()) + " `" + ifp->name.str + "`"; - gwi.selectCols.push_back("`" + escapeBackTick(ifp->name.str) + "`"); - } } - else // InfiniDB Non support functions still go through post process for now + else // This was a vtable post-process block { hasNonSupportItem = false; uint32_t before_size = funcFieldVec.size(); - parse_item(ifp, funcFieldVec, hasNonSupportItem, parseInfo); + parse_item(ifp, funcFieldVec, hasNonSupportItem, parseInfo, &gwi); uint32_t after_size = funcFieldVec.size(); // group by func and func in subquery can not be post processed + // pushdown handler projection functions // @bug3881. set_user_var can not be treated as constant function // @bug5716. Try to avoid post process function for union query. if ((gwi.subQuery || select_lex.group_list.elements != 0 || - !csep->unionVec().empty() || isUnion) && + !csep->unionVec().empty() || isUnion || isPushdownHand ) && !hasNonSupportItem && (after_size - before_size) == 0 && - !(parseInfo & AGG_BIT) && !(parseInfo & SUB_BIT) && - string(ifp->func_name()) != "set_user_var") + !(parseInfo & AGG_BIT) && !(parseInfo & SUB_BIT) + ) { String val, *str = ifp->val_str(&val); string valStr; @@ -6519,117 +6749,61 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i return -1; } } - - //@Bug 3021. Bypass postprocess for update and delete. - //if ( ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE ) || ((gwi.thd->lex)->sql_command == SQLCOM_DELETE ) || ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE_MULTI ) || ((gwi.thd->lex)->sql_command == SQLCOM_DELETE_MULTI )) - //{} else { - // @bug 3881. Here is the real redo part. - redo = true; - // @bug 1706 - String funcStr; - ifp->print(&funcStr, QT_INFINIDB); - string valStr; - valStr.assign(funcStr.ptr(), funcStr.length()); - gwi.selectCols.push_back(valStr + " `" + escapeBackTick(ifp->name.str) + "`"); - // clear the error set by buildFunctionColumn - gwi.fatalParseError = false; - gwi.parseErrorText = ""; + Message::Args args; + args.add(ifp->func_name()); + gwi.parseErrorText = + IDBErrorInfo::instance()->errorMsg(ERR_NON_SUPPORTED_FUNCTION, args); + setError(gwi.thd, ER_CHECK_NOT_IMPLEMENTED, gwi.parseErrorText, gwi); + return ER_CHECK_NOT_IMPLEMENTED; } } break; - } + } // End of FUNC_ITEM - case Item::INT_ITEM: + // DRRTUY Replace the whole section with typeid() checks or use + // reinterpret_cast here + case Item::CONST_ITEM: { - if ( ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE ) || ((gwi.thd->lex)->sql_command == SQLCOM_DELETE ) || ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE_MULTI ) || ((gwi.thd->lex)->sql_command == SQLCOM_DELETE_MULTI )) - { } - else + switch(item->cmp_type()) { - // do not push the dummy column (mysql added) to returnedCol - if (item->name.length && string(item->name.str) == "Not_used") - continue; + case INT_RESULT: + case STRING_RESULT: + case DECIMAL_RESULT: + case REAL_RESULT: + case TIME_RESULT: + { + if ( ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE ) || ((gwi.thd->lex)->sql_command == SQLCOM_DELETE ) || ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE_MULTI ) || ((gwi.thd->lex)->sql_command == SQLCOM_DELETE_MULTI )) + { } + else + { + // do not push the dummy column (mysql added) to returnedCol + if (item->name.length && string(item->name.str) == "Not_used") + continue; - // @bug3509. Constant column is sent to ExeMgr now. - SRCP srcp(buildReturnedColumn(item, gwi, gwi.fatalParseError)); + // @bug3509. Constant column is sent to ExeMgr now. + SRCP srcp(buildReturnedColumn(item, gwi, gwi.fatalParseError)); - if (item->name.length) - srcp->alias(item->name.str); + if (item->name.length) + srcp->alias(item->name.str); - gwi.returnedCols.push_back(srcp); + gwi.returnedCols.push_back(srcp); + } - Item_int* isp = reinterpret_cast(item); - ostringstream oss; - oss << isp->value << " `" << escapeBackTick(srcp->alias().c_str()) << "`"; - - if (sel_cols_in_create.length() != 0) - sel_cols_in_create += ", "; - - sel_cols_in_create += oss.str(); - gwi.selectCols.push_back(oss.str()); + break; + } + // MCOL-2178 This switch doesn't handl + // ROW_ + default: + { + IDEBUG(cerr << "Warning unsupported cmp_type() in projection" << endl); + //noop + } } - break; - } - - case Item::STRING_ITEM: - { - if ( ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE ) || ((gwi.thd->lex)->sql_command == SQLCOM_DELETE ) || ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE_MULTI ) || ((gwi.thd->lex)->sql_command == SQLCOM_DELETE_MULTI )) - { } - else - { - SRCP srcp(buildReturnedColumn(item, gwi, gwi.fatalParseError)); - gwi.returnedCols.push_back(srcp); - - if (item->name.length) - srcp->alias(item->name.str); - - Item_string* isp = reinterpret_cast(item); - String val, *str = isp->val_str(&val); - string valStr; - valStr.assign(str->ptr(), str->length()); - string name = "'" + valStr + "'" + " " + "`" + escapeBackTick(srcp->alias().c_str()) + "`"; - - if (sel_cols_in_create.length() != 0) - sel_cols_in_create += ", "; - - sel_cols_in_create += name; - gwi.selectCols.push_back(name); - } - - break; - } - - case Item::DECIMAL_ITEM: - { - if ( ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE ) || ((gwi.thd->lex)->sql_command == SQLCOM_DELETE ) || ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE_MULTI ) || ((gwi.thd->lex)->sql_command == SQLCOM_DELETE_MULTI )) - { } - else - { - SRCP srcp(buildReturnedColumn(item, gwi, gwi.fatalParseError)); - gwi.returnedCols.push_back(srcp); - - if (item->name.length) - srcp->alias(item->name.str); - - Item_decimal* isp = reinterpret_cast(item); - String val, *str = isp->val_str(&val); - string valStr; - valStr.assign(str->ptr(), str->length()); - ostringstream oss; - oss << valStr.c_str() << " `" << escapeBackTick(srcp->alias().c_str()) << "`"; - - if (sel_cols_in_create.length() != 0) - sel_cols_in_create += ", "; - - sel_cols_in_create += oss.str(); - gwi.selectCols.push_back(oss.str()); - } - - break; - } + } // CONST_ITEM ends here case Item::NULL_ITEM: { @@ -6642,14 +6816,6 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i if (item->name.length) srcp->alias(item->name.str); - - string name = string("null `") + escapeBackTick(srcp->alias().c_str()) + string("`") ; - - if (sel_cols_in_create.length() != 0) - sel_cols_in_create += ", "; - - sel_cols_in_create += name; - gwi.selectCols.push_back("null"); } break; @@ -6706,20 +6872,6 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i rc->alias(sub->name.str); gwi.returnedCols.push_back(SRCP(rc)); - String str; - sub->get_select_lex()->print(gwi.thd, &str, QT_INFINIDB_NO_QUOTE); - sel_cols_in_create += "(" + string(str.c_ptr()) + ")"; - - if (sub->name.length) - { - sel_cols_in_create += "`" + escapeBackTick(sub->name.str) + "`"; - gwi.selectCols.push_back(sub->name.str); - } - else - { - sel_cols_in_create += "`" + escapeBackTick(str.c_ptr()) + "`"; - gwi.selectCols.push_back("`" + escapeBackTick(str.c_ptr()) + "`"); - } break; } @@ -6757,6 +6909,23 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i gwi.returnedCols.push_back(srcp); break; } + case Item::TYPE_HOLDER: + { + if(!gwi.tbList.size()) + { + gwi.parseErrorText = "subquery with VALUES"; + gwi.fatalParseError = true; + setError(gwi.thd, ER_CHECK_NOT_IMPLEMENTED, gwi.parseErrorText, gwi); + return ER_CHECK_NOT_IMPLEMENTED; + } + else + { + std::cerr << "********** received TYPE_HOLDER *********" << std::endl; + + } + break; + } + default: { @@ -6876,7 +7045,7 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i } String str; - funcFieldVec[i]->print(&str, QT_INFINIDB_NO_QUOTE); + funcFieldVec[i]->print(&str, QT_ORDINARY); sc->alias(string(str.c_ptr())); //sc->tableAlias(funcFieldVec[i]->table_name); sc->tableAlias(sc->tableAlias()); @@ -6899,25 +7068,18 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i gwi.returnedCols.push_back(srcp); gwi.columnMap.insert(CalpontSelectExecutionPlan::ColumnMap::value_type(string(funcFieldVec[i]->field_name.str), srcp)); - if (sel_cols_in_create.length() != 0) - sel_cols_in_create += ", "; - string fullname; fullname = str.c_ptr(); - sel_cols_in_create += fullname + " `" + escapeBackTick(fullname.c_str()) + "`"; TABLE_LIST* tmp = (funcFieldVec[i]->cached_table ? funcFieldVec[i]->cached_table : 0); - gwi.tableMap[make_aliastable(sc->schemaName(), sc->tableName(), sc->tableAlias(), sc->isInfiniDB())] = + gwi.tableMap[make_aliastable(sc->schemaName(), sc->tableName(), sc->tableAlias(), sc->isColumnStore())] = make_pair(1, tmp); } } - // post-process Order by list and expressions on select by redo phase1. only for vtable - // ignore ORDER BY clause for union select unit - string ord_cols = ""; // for normal select phase SRCP minSc; // min width projected column. for count(*) use // Group by list. not valid for union main query - if (gwi.thd->infinidb_vtable.vtable_state == THD::INFINIDB_CREATE_VTABLE && !unionSel) + if (!unionSel) { gwi.clauseType = GROUP_BY; Item* nonSupportItem = NULL; @@ -7089,10 +7251,13 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i // @bug5638. The group by column is constant but not counter, alias has to match a column // on the select list else if (!groupcol->counter_used && - (groupItem->type() == Item::INT_ITEM || - groupItem->type() == Item::STRING_ITEM || - groupItem->type() == Item::REAL_ITEM || - groupItem->type() == Item::DECIMAL_ITEM)) + (groupItem->type() == Item::CONST_ITEM && + (groupItem->cmp_type() == INT_RESULT || + groupItem->cmp_type() == STRING_RESULT || + groupItem->cmp_type() == REAL_RESULT || + groupItem->cmp_type() == DECIMAL_RESULT) + ) + ) { ReturnedColumn* rc = 0; @@ -7194,17 +7359,9 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i } } - if (gwi.thd->infinidb_vtable.vtable_state == THD::INFINIDB_CREATE_VTABLE) { SQL_I_List order_list = select_lex.order_list; ORDER* ordercol = reinterpret_cast(order_list.first); - string create_query(gwi.thd->infinidb_vtable.create_vtable_query.c_ptr()); - string select_query(gwi.thd->infinidb_vtable.select_vtable_query.c_ptr()); - string lower_create_query(gwi.thd->infinidb_vtable.create_vtable_query.c_ptr()); - string lower_select_query(gwi.thd->infinidb_vtable.select_vtable_query.c_ptr()); - boost::algorithm::to_lower(lower_create_query); - boost::algorithm::to_lower(lower_select_query); - // check if window functions are in order by. InfiniDB process order by list if // window functions are involved, either in order by or projection. @@ -7212,16 +7369,32 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i { if ((*(ordercol->item))->type() == Item::WINDOW_FUNC_ITEM) gwi.hasWindowFunc = true; + // MCOL-2166 Looking for this sorting item in GROUP_BY items list. + // Shouldn't look into this if query doesn't have GROUP BY or + // aggregations + if(isPushdownHand + && select_lex.agg_func_used() && select_lex.group_list.first + && !sortItemIsInGrouping(*ordercol->item, select_lex.group_list.first)) + { + std::ostringstream ostream; + std::ostringstream& osr = ostream; + getColNameFromItem(osr, *ordercol->item); + Message::Args args; + args.add(ostream.str()); + string emsg = IDBErrorInfo::instance()->errorMsg(ERR_NOT_GROUPBY_EXPRESSION, args); + gwi.parseErrorText = emsg; + setError(gwi.thd, ER_INTERNAL_ERROR, emsg, gwi); + return ERR_NOT_GROUPBY_EXPRESSION; + } } // re-visit the first of ordercol list ordercol = reinterpret_cast(order_list.first); - // for subquery, order+limit by will be supported in infinidb. build order by columns - // @todo union order by and limit support - if (gwi.hasWindowFunc - || gwi.subSelectType != CalpontSelectExecutionPlan::MAIN_SELECT - || ( isUnion && ordercol )) + // for subquery or pushdown query, order+limit by will be supported in CS + // union order by and limit are supported + if (gwi.hasWindowFunc || isPushdownHand || ( isUnion && ordercol ) + || gwi.subSelectType != CalpontSelectExecutionPlan::MAIN_SELECT ) { for (; ordercol; ordercol = ordercol->next) { @@ -7240,15 +7413,28 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i Item* ord_item = *(ordercol->item); // ignore not_used column on order by. - if (ord_item->type() == Item::INT_ITEM && ord_item->full_name() && string(ord_item->full_name()) == "Not_used") + if ((ord_item->type() == Item::CONST_ITEM + && ord_item->cmp_type() == INT_RESULT) + && ord_item->full_name() + && !strcmp(ord_item->full_name(), "Not_used")) + { continue; - else if (ord_item->type() == Item::INT_ITEM) + } + else if (ord_item->type() == Item::CONST_ITEM + && ord_item->cmp_type() == INT_RESULT) + { + // DRRTUY This section looks useless b/c there is no + // way to put constant INT into an ORDER BY list rc = gwi.returnedCols[((Item_int*)ord_item)->val_int() - 1]->clone(); + } else if (ord_item->type() == Item::SUBSELECT_ITEM) + { gwi.fatalParseError = true; + } else + { rc = buildReturnedColumn(ord_item, gwi, gwi.fatalParseError); - + } // @bug5501 try item_ptr if item can not be fixed. For some // weird dml statement state, item can not be fixed but the // infomation is available in item_ptr. @@ -7279,10 +7465,11 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i gwi.orderByCols.push_back(SRCP(rc)); } } + // DRRTUY The whole block is marked for removal in 1.4.1 +#if 0 else if (!isUnion) { vector fieldVec; - bool addToSel; // the following order by is just for redo phase if (!unionSel) @@ -7295,101 +7482,14 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i while (ord_item->type() == Item::REF_ITEM) ord_item = (*((Item_ref*)ord_item)->ref); - // @bug 1706. re-construct the order by item one by one - //Item* ord_item = *(ordercol->item); - if (ord_cols.length() != 0) - ord_cols += ", "; + //ReturnedColumn* rc = 0; + // check if this order by column is on the select list + //Item_func* ifp = (Item_func*)(*(ordercol->item)); + //rc = buildFunctionColumn(ifp, gwi, gwi.fatalParseError); - addToSel = true; - string fullname; - - if (ordercol->in_field_list && ordercol->counter_used) + if (ord_item->type() == Item::FUNC_ITEM) { - ostringstream oss; - oss << ordercol->counter; - ord_cols += oss.str(); - - if (ordercol->direction != ORDER::ORDER_ASC) - ord_cols += " desc"; - - continue; - } - - else if (ord_item->type() == Item::FUNC_ITEM) - { - // @bug 2621. order by alias - if (!ord_item->is_autogenerated_name && ord_item->name.length) - { - ord_cols += ord_item->name.str; - continue; - } - - // if there's group by clause or aggregate column, check to see - // if this item or the arguments is on the GB list. - ReturnedColumn* rc = 0; - // check if this order by column is on the select list - Item_func* ifp = (Item_func*)(*(ordercol->item)); - rc = buildFunctionColumn(ifp, gwi, gwi.fatalParseError); - - if (rc) - { - for (uint32_t i = 0; i < gwi.returnedCols.size(); i++) - { - if (rc && rc->operator==(gwi.returnedCols[i].get())) - { - ostringstream oss; - oss << i + 1; - ord_cols += oss.str(); - addToSel = false; - break; - } - } - } - - if (addToSel) - { - FunctionColumn* fc = dynamic_cast(rc); - - if (fc) - { - addToSel = false; - redo = true; - string ord_func = string(ifp->func_name()) + "("; - - for (uint32_t i = 0; i < fc->functionParms().size(); i++) - { - if (i != 0) - ord_func += ","; - - for (uint32_t j = 0; j < gwi.returnedCols.size(); j++) - { - if (fc->functionParms()[i]->data()->operator==(gwi.returnedCols[j].get())) - { - ord_func += "`" + escapeBackTick(gwi.returnedCols[j]->alias().c_str()) + "`"; - continue; - } - - AggregateColumn* ac = dynamic_cast(fc->functionParms()[i]->data()); - - if (ac) - { - gwi.parseErrorText = IDBErrorInfo::instance()->errorMsg(ERR_NON_SUPPORT_ORDER_BY); - setError(gwi.thd, ER_CHECK_NOT_IMPLEMENTED, gwi.parseErrorText, gwi); - return ER_CHECK_NOT_IMPLEMENTED; - } - - addToSel = true; - //continue; - - } - } - - ord_func += ")"; - - if (!addToSel) - ord_cols += ord_func; - } - } + //FunctionColumn* fc = dynamic_cast(rc); } else if (ord_item->type() == Item::SUBSELECT_ITEM) { @@ -7397,7 +7497,6 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i setError(gwi.thd, ER_CHECK_NOT_IMPLEMENTED, emsg, gwi); return ER_CHECK_NOT_IMPLEMENTED; } - else if (ord_item->type() == Item::SUM_FUNC_ITEM) { ReturnedColumn* ac = 0; @@ -7421,38 +7520,12 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i if (!ret) continue; - if (ac->operator==(gwi.returnedCols[i].get())) - { - ostringstream oss; - oss << i + 1; - ord_cols += oss.str(); - addToSel = false; - break; - } } if (ac || !gwi.groupByCols.empty()) { - if (addToSel) - { - redo = true; - // @bug 3076. do not add the argument of aggregate function to the SELECT list, - // instead, add the whole column - String str; - ord_item->print(&str, QT_INFINIDB_NO_QUOTE); - - if (sel_cols_in_create.length() != 0) - sel_cols_in_create += ", "; - - sel_cols_in_create += str.c_ptr(); - //gwi.selectCols.push_back(" `" + string(str.c_ptr()) + "`"); - SRCP srcp(ac); - gwi.returnedCols.push_back(srcp); - ord_cols += " `" + escapeBackTick(str.c_ptr()) + "`"; - } - - if (ordercol->direction != ORDER::ORDER_ASC) - ord_cols += " desc"; + SRCP srcp(ac); + gwi.returnedCols.push_back(srcp); continue; } @@ -7461,13 +7534,6 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i { Item_field* field = reinterpret_cast(ord_item); ReturnedColumn* rc = buildSimpleColumn(field, gwi); - fullname = field->full_name(); -// if (field->db_name) -// fullname += string(field->db_name) + "."; -// if (field->table_name) -// fullname += string(field->table_name) + "."; -// if (field->field_name) -// fullname += string(field->field_name); for (uint32_t i = 0; i < gwi.returnedCols.size(); i++) { @@ -7479,26 +7545,13 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i continue; } - if (strcasecmp(fullname.c_str(), gwi.returnedCols[i]->alias().c_str()) == 0 || - strcasecmp(ord_item->name.str, gwi.returnedCols[i]->alias().c_str()) == 0) - { - ord_cols += string(" `") + escapeBackTick(gwi.returnedCols[i]->alias().c_str()) + '`'; - addToSel = false; - break; - } - if (sc && sc->sameColumn(rc)) { - ostringstream oss; - oss << i + 1; - ord_cols += oss.str(); - addToSel = false; break; } } } - if (addToSel) { // @bug 2719. Error out order by not on the distinct select list. if (select_lex.options & SELECT_DISTINCT) @@ -7510,7 +7563,7 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i bool hasNonSupportItem = false; uint16_t parseInfo = 0; - parse_item(ord_item, fieldVec, hasNonSupportItem, parseInfo); + parse_item(ord_item, fieldVec, hasNonSupportItem, parseInfo, &gwi); if (hasNonSupportItem) { @@ -7519,18 +7572,10 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i return ER_CHECK_NOT_IMPLEMENTED; } - String str; - ord_item->print(&str, QT_INFINIDB); - ord_cols += str.c_ptr(); } - - if (ordercol->direction != ORDER::ORDER_ASC) - ord_cols += " desc"; } } - redo = (redo || fieldVec.size() != 0); - // populate string to be added to the select list for order by for (uint32_t i = 0; i < fieldVec.size(); i++) { @@ -7544,7 +7589,7 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i } String str; - fieldVec[i]->print(&str, QT_INFINIDB_NO_QUOTE); + fieldVec[i]->print(&str, QT_ORDINARY); sc->alias(string(str.c_ptr())); SRCP srcp(sc); uint32_t j = 0; @@ -7562,22 +7607,15 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i if (j == gwi.returnedCols.size()) { - string fullname; - - if (sel_cols_in_create.length() != 0) - sel_cols_in_create += ", "; - - fullname = str.c_ptr(); - sel_cols_in_create += fullname + " `" + escapeBackTick(fullname.c_str()) + "`"; - gwi.returnedCols.push_back(srcp); gwi.columnMap.insert(CalpontSelectExecutionPlan::ColumnMap::value_type(string(fieldVec[i]->field_name.str), srcp)); TABLE_LIST* tmp = (fieldVec[i]->cached_table ? fieldVec[i]->cached_table : 0); - gwi.tableMap[make_aliastable(sc->schemaName(), sc->tableName(), sc->tableAlias(), sc->isInfiniDB())] = + gwi.tableMap[make_aliastable(sc->schemaName(), sc->tableName(), sc->tableAlias(), sc->isColumnStore())] = make_pair(1, tmp); } } } +#endif // make sure columnmap, returnedcols and count(*) arg_list are not empty TableMap::iterator tb_iter = gwi.tableMap.begin(); @@ -7654,235 +7692,26 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i gwi.returnedCols.push_back(minSc); } - if (!isUnion && !gwi.hasWindowFunc && gwi.subSelectType == CalpontSelectExecutionPlan::MAIN_SELECT) + // ORDER BY translation part + if (!isUnion && !gwi.hasWindowFunc + && gwi.subSelectType == CalpontSelectExecutionPlan::MAIN_SELECT ) { - std::ostringstream vtb; - vtb << "infinidb_vtable.$vtable_" << gwi.thd->thread_id; - - //vtb << "$vtable_" << gwi.thd->thread_id; - // re-construct the select query and redo phase 1 - if (redo) - { - // select now() from region case. returnedCols should have minSc. - if (sel_cols_in_create.length() == 0) - { - SimpleColumn* sc = dynamic_cast(gwi.returnedCols[0].get()); - - if (sc) - sel_cols_in_create = dynamic_cast(gwi.returnedCols[0].get())->columnName(); - else - sel_cols_in_create = gwi.returnedCols[0]->alias(); - } - - // select * from derived table case - if (gwi.selectCols.empty()) - sel_cols_in_create = " * "; - - create_query = "create temporary table " + vtb.str() + " engine = aria as select " + sel_cols_in_create + " from "; - TABLE_LIST* table_ptr = select_lex.get_table_list(); - - bool firstTb = true; - - // put all tables, derived tables and views on the list - //TABLE_LIST* table_ptr = select_lex.get_table_list(); - set aliasSet; // to avoid duplicate table alias - - for (; table_ptr; table_ptr = table_ptr->next_global) - { - if (string(table_ptr->table_name.str).find("$vtable") != string::npos) - continue; - - if (table_ptr->derived) - { - if (aliasSet.find(table_ptr->alias.str) != aliasSet.end()) - continue; - - String str; - (table_ptr->derived->first_select())->print(gwi.thd, &str, QT_INFINIDB_DERIVED); - - if (!firstTb) - create_query += ", "; - - create_query += "(" + string(str.c_ptr()) + ") " + string(table_ptr->alias.str); - firstTb = false; - aliasSet.insert(table_ptr->alias.str); - } - else if (table_ptr->view) - { - if (aliasSet.find(table_ptr->alias.str) != aliasSet.end()) - continue; - - if (!firstTb) - create_query += ", "; - - create_query += string(table_ptr->db.str) + "." + string(table_ptr->table_name.str) + - string(" `") + escapeBackTick(table_ptr->alias.str) + string("`"); - aliasSet.insert(table_ptr->alias.str); - firstTb = false; - } - else - { - // table referenced by view is represented by viewAlias_tableAlias. - // consistent with item.cc field print. - if (table_ptr->referencing_view) - { - if (aliasSet.find(string(table_ptr->referencing_view->alias.str) + "_" + - string(table_ptr->alias.str)) != aliasSet.end()) - continue; - - if (!firstTb) - create_query += ", "; - - create_query += string(table_ptr->db.str) + "." + string(table_ptr->table_name.str) + string(" "); - create_query += string(" `") + - escapeBackTick(table_ptr->referencing_view->alias.str) + "_" + - escapeBackTick(table_ptr->alias.str) + string("`"); - aliasSet.insert(string(table_ptr->referencing_view->alias.str) + "_" + - string(table_ptr->alias.str)); - } - else - { - if (aliasSet.find(table_ptr->alias.str) != aliasSet.end()) - continue; - - if (!firstTb) - create_query += ", "; - - create_query += string(table_ptr->db.str) + "." + string(table_ptr->table_name.str) + string(" "); - create_query += string("`") + escapeBackTick(table_ptr->alias.str) + string("`"); - aliasSet.insert(table_ptr->alias.str); - } - - firstTb = false; - } - } - - - gwi.thd->infinidb_vtable.create_vtable_query.free(); - gwi.thd->infinidb_vtable.create_vtable_query.append(create_query.c_str(), create_query.length()); - gwi.thd->infinidb_vtable.vtable_state = THD::INFINIDB_REDO_PHASE1; // redo phase 1 - - // turn off select distinct from post process unless there're post process functions - // on the select list. - string sel_query = "select "; - - if (/*join->select_options*/select_lex.options & SELECT_DISTINCT && redo) - sel_query = "select distinct "; - else - sel_query = "select "; - - // select * from derived table... - if (gwi.selectCols.size() == 0) - sel_query += " * "; - - for (uint32_t i = 0; i < gwi.selectCols.size(); i++) - { - sel_query += gwi.selectCols[i]; - - if ( i + 1 != gwi.selectCols.size()) - sel_query += ", "; - } - - select_query.replace(lower_select_query.find("select *"), string("select *").length(), sel_query); - } - else - { - // remove order by clause in case this phase has been executed before. - // need a better fix later, like skip all the other non-optimized phase. - size_t pos = lower_select_query.find("order by"); - - if (pos != string::npos) - select_query.replace(pos, lower_select_query.length() - pos, ""); - - //select_query = "select * from " + vtb.str(); + { if (unionSel) order_list = select_lex.master_unit()->global_parameters()->order_list; ordercol = reinterpret_cast(order_list.first); - ord_cols = ""; for (; ordercol; ordercol = ordercol->next) { Item* ord_item = *(ordercol->item); - - // @bug 1706. re-construct the order by item one by one, because the ord_cols constucted so far - // is for REDO phase. - if (ord_cols.length() != 0) - ord_cols += ", "; - - if (ordercol->in_field_list && ordercol->counter_used) - { - ostringstream oss; - oss << ordercol->counter; - ord_cols += oss.str(); - } - else if (ord_item->type() == Item::NULL_ITEM) - { - // MCOL-793 Do nothing for an ORDER BY NULL - } - else if (ord_item->type() == Item::SUM_FUNC_ITEM) - { - Item_sum* ifp = (Item_sum*)(*(ordercol->item)); - ReturnedColumn* fc = buildAggregateColumn(ifp, gwi); - - for (uint32_t i = 0; i < gwi.returnedCols.size(); i++) - { - if (fc->operator==(gwi.returnedCols[i].get())) - { - ostringstream oss; - oss << i + 1; - ord_cols += oss.str(); - break; - } - } - - //continue; - } - // @bug 3518. if order by clause = selected column, use position. - else if (ord_item->name.length && ord_item->type() == Item::FIELD_ITEM) - { - Item_field* field = reinterpret_cast(ord_item); - string fullname; - - if (field->db_name) - fullname += string(field->db_name) + "."; - - if (field->table_name) - fullname += string(field->table_name) + "."; - - if (field->field_name.length) - fullname += string(field->field_name.str); - - uint32_t i = 0; - - for (i = 0; i < gwi.returnedCols.size(); i++) - { - SimpleColumn* sc = dynamic_cast(gwi.returnedCols[i].get()); - - if (sc && ((Item_field*)ord_item)->cached_table && - (strcasecmp(getViewName(((Item_field*)ord_item)->cached_table).c_str(), sc->viewName().c_str()) != 0)) - continue; - - if (strcasecmp(fullname.c_str(), gwi.returnedCols[i]->alias().c_str()) == 0 || - strcasecmp(ord_item->name.str, gwi.returnedCols[i]->alias().c_str()) == 0) - { - ostringstream oss; - oss << i + 1; - ord_cols += oss.str(); - break; - } - } - - if (i == gwi.returnedCols.size()) - ord_cols += string(" `") + escapeBackTick(ord_item->name.str) + '`'; - } - - else if (ord_item->name.length) + + if (ord_item->name.length) { // for union order by 1 case. For unknown reason, it doesn't show in_field_list - if (ord_item->type() == Item::INT_ITEM) + if (ord_item->type() == Item::CONST_ITEM + && ord_item->cmp_type() == INT_RESULT) { - ord_cols += ord_item->name.str; } else if (ord_item->type() == Item::SUBSELECT_ITEM) { @@ -7892,7 +7721,6 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i } else { - ord_cols += string(" `") + escapeBackTick(ord_item->name.str) + '`'; } } else if (ord_item->type() == Item::FUNC_ITEM) @@ -7906,32 +7734,28 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i { ostringstream oss; oss << i + 1; - ord_cols += oss.str(); break; } } } - else - { - String str; - ord_item->print(&str, QT_INFINIDB_NO_QUOTE); - ord_cols += string(str.c_ptr()); - } - - if (ordercol->direction != ORDER::ORDER_ASC) - ord_cols += " desc"; } } - if (ord_cols.length() > 0) // has order by + if ( gwi.orderByCols.size() ) // has order by { - gwi.thd->infinidb_vtable.has_order_by = true; csep->hasOrderBy(true); - ord_cols = " order by " + ord_cols; - select_query += ord_cols; + // To activate LimitedOrderBy + if(isPushdownHand) + { + csep->specHandlerProcessed(true); + } } } + // LIMIT processing part + uint64_t limitNum = std::numeric_limits::max(); + + // non-MAIN union branch if (unionSel || gwi.subSelectType != CalpontSelectExecutionPlan::MAIN_SELECT) { if (select_lex.master_unit()->global_parameters()->explicit_limit) @@ -7948,16 +7772,9 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i csep->limitNum(select->val_int()); } - if (unionSel && gwi.subSelectType == CalpontSelectExecutionPlan::MAIN_SELECT) - { - ostringstream limit; - limit << " limit "; - limit << csep->limitStart() << ", "; - limit << csep->limitNum(); - select_query += limit.str(); - } } } + // union with explicit select at the top level else if (isUnion && select_lex.explicit_limit) { if (select_lex.braces) @@ -7969,10 +7786,10 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i csep->limitNum(((Item_int*)select_lex.select_limit)->val_int()); } } + // other types of queries that have explicit LIMIT else if (select_lex.explicit_limit) { uint32_t limitOffset = 0; - uint32_t limitNum = std::numeric_limits::max(); if (join) { @@ -7983,9 +7800,9 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i // select_lex->offset_limit if not null. if (join->select_lex && join->select_lex->offset_limit && - join->select_lex->offset_limit->fixed && + join->select_lex->offset_limit->is_fixed() && join->select_lex->select_limit && - join->select_lex->select_limit->fixed) + join->select_lex->select_limit->is_fixed()) { limitOffset = join->select_lex->offset_limit->val_int(); limitNum = join->select_lex->select_limit->val_int(); @@ -8019,24 +7836,25 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i // relate to bug4848. let mysql drive limit when limit session variable set. // do not set in csep. @bug5096. ignore session limit setting for dml - if ((gwi.thd->variables.select_limit == (uint64_t) - 1 || - (gwi.thd->variables.select_limit != (uint64_t) - 1 && - gwi.thd->infinidb_vtable.vtable_state != THD::INFINIDB_CREATE_VTABLE)) && - !csep->hasOrderBy()) + if (gwi.thd->variables.select_limit == (uint64_t) - 1 && + !csep->hasOrderBy()) { csep->limitStart(limitOffset); csep->limitNum(limitNum); } - else + // Pushdown queries w ORDER BY and LIMIT + else if (isPushdownHand && csep->hasOrderBy()) { - ostringstream limit; - limit << " limit " << limitOffset << ", " << limitNum; - select_query += limit.str(); + csep->limitStart(limitOffset); + csep->limitNum(limitNum); } } - - gwi.thd->infinidb_vtable.select_vtable_query.free(); - gwi.thd->infinidb_vtable.select_vtable_query.append(select_query.c_str(), select_query.length()); + // Pushdown queries with ORDER BY w/o explicit limit + else if (isPushdownHand && csep->hasOrderBy()) + { + // We must set this to activate LimitedOrderBy in ExeMgr + csep->limitNum((uint64_t) - 2); + } // We don't currently support limit with correlated subquery if (csep->limitNum() != (uint64_t) - 1 && @@ -8047,9 +7865,9 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i setError(gwi.thd, ER_INTERNAL_ERROR, gwi.parseErrorText, gwi); return ER_CHECK_NOT_IMPLEMENTED; } - } + } // LIMIT processing finishes here - if (/*join->select_options*/select_lex.options & SELECT_DISTINCT) + if (select_lex.options & SELECT_DISTINCT) csep->distinct(true); // add the smallest column to count(*) parm. @@ -8132,38 +7950,10 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i csep->derivedTableList(gwi.derivedTbList); csep->selectSubList(selectSubList); csep->subSelectList(gwi.subselectList); - gwi.thd->infinidb_vtable.duplicate_field_name = false; clearStacks(gwi); return 0; } -int cp_get_plan(THD* thd, SCSEP& csep) -{ - LEX* lex = thd->lex; - idbassert(lex != 0); - - SELECT_LEX select_lex = lex->select_lex; - gp_walk_info gwi; - gwi.thd = thd; - int status = getSelectPlan(gwi, select_lex, csep); - - if (status > 0) - return ER_INTERNAL_ERROR; - else if (status < 0) - return status; - -#ifdef DEBUG_WALK_COND - cerr << "---------------- cp_get_plan EXECUTION PLAN ----------------" << endl; - cerr << *csep << endl ; - cerr << "-------------- EXECUTION PLAN END --------------\n" << endl; -#endif - - // Derived table projection and filter optimization. - derivedTableOptimization(thd, csep); - - return 0; -} - int cp_get_table_plan(THD* thd, SCSEP& csep, cal_table_info& ti) { gp_walk_info* gwi = ti.condInfo; @@ -8279,10 +8069,54 @@ int cp_get_group_plan(THD* thd, SCSEP& csep, cal_impl_if::cal_group_info& gi) return ER_INTERNAL_ERROR; else if (status < 0) return status; + // Derived table projection and filter optimization. + derivedTableOptimization(thd, csep); return 0; } +int cs_get_derived_plan(derived_handler* handler, THD* thd, SCSEP& csep, gp_walk_info& gwi) +{ + SELECT_LEX select_lex = *handler->select; + int status = getSelectPlan(gwi, select_lex, csep, false, true); + + if (status > 0) + return ER_INTERNAL_ERROR; + else if (status < 0) + return status; + +#ifdef DEBUG_WALK_COND + cerr << "---------------- cs_get_derived_plan EXECUTION PLAN ----------------" << endl; + cerr << *csep << endl ; + cerr << "-------------- EXECUTION PLAN END --------------\n" << endl; +#endif + // Derived table projection and filter optimization. + derivedTableOptimization(thd, csep); + return 0; +} + +int cs_get_select_plan(select_handler* handler, THD* thd, SCSEP& csep, gp_walk_info& gwi) +{ + SELECT_LEX select_lex = *handler->select; + int status = getSelectPlan(gwi, select_lex, csep, false, true); + + if (status > 0) + return ER_INTERNAL_ERROR; + else if (status < 0) + return status; + +#ifdef DEBUG_WALK_COND + cerr << "---------------- cs_get_select_plan EXECUTION PLAN ----------------" << endl; + cerr << *csep << endl ; + cerr << "-------------- EXECUTION PLAN END --------------\n" << endl; +#endif + // Derived table projection and filter optimization. + derivedTableOptimization(thd, csep); + + return 0; +} + + /*@brief buildConstColFromFilter- change SimpleColumn into ConstColumn*/ /*********************************************************** * DESCRIPTION: @@ -8290,6 +8124,8 @@ int cp_get_group_plan(THD* thd, SCSEP& csep, cal_impl_if::cal_group_info& gi) * filter predicate is used, e.g. * field = 'AIR', field IN ('AIR'). This utility function tries to * replace such fields with ConstantColumns using cond_pushed filters. + * TBD Take into account that originalSC SimpleColumn could be: + * SimpleColumn, ArithmeticColumn, FunctionColumn. * PARAMETERS: * originalSC SimpleColumn* removed field * gwi main strucutre @@ -8322,9 +8158,10 @@ ConstantColumn* buildConstColFromFilter(SimpleColumn* originalSC, continue; op = simpFilter->op(); + execplan::ReturnedColumn* rc = dynamic_cast(simpleCol); - if ( originalSC->sameColumn(dynamic_cast(simpleCol)) - && op.get()->op() == OP_EQ && constCol) + // The filter could have any kind of op + if ( originalSC->sameColumn(rc) ) { #ifdef DEBUG_WALK_COND cerr << "buildConstColFromFilter() replaced " << endl; @@ -8371,7 +8208,7 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro // @bug 2123. Override large table estimate if infinidb_ordered hint was used. // @bug 2404. Always override if the infinidb_ordered_only variable is turned on. - if (gwi.thd->infinidb_vtable.override_largeside_estimate || get_ordered_only(gwi.thd)) + if (get_ordered_only(gwi.thd)) csep->overrideLargeSideEstimate(true); // @bug 5741. Set a flag when in Local PM only query mode @@ -8435,10 +8272,11 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro if (table_ptr->derived) { String str; - (table_ptr->derived->first_select())->print(gwi.thd, &str, QT_INFINIDB_DERIVED); + (table_ptr->derived->first_select())->print(gwi.thd, &str, QT_ORDINARY); SELECT_LEX* select_cursor = table_ptr->derived->first_select(); - FromSubQuery fromSub(gwi, select_cursor); + // Use Pushdown handler for subquery processing + FromSubQuery fromSub(gwi, select_cursor, true); string alias(table_ptr->alias.str); fromSub.alias(lower(alias)); @@ -8457,11 +8295,12 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro gwi.tbList.push_back(tn); CalpontSystemCatalog::TableAliasName tan = make_aliastable("", alias, alias); gwi.tableMap[tan] = make_pair(0, table_ptr); -// gwi.thd->infinidb_vtable.isUnion = true; //by-pass the 2nd pass of rnd_init + // MCOL-2178 isUnion member only assigned, never used + //MIGR::infinidb_vtable.isUnion = true; //by-pass the 2nd pass of rnd_init } else if (table_ptr->view) { - View* view = new View(table_ptr->view->select_lex, &gwi); + View* view = new View(*table_ptr->view->first_select_lex(), &gwi); CalpontSystemCatalog::TableAliasName tn = make_aliastable(table_ptr->db.str, table_ptr->table_name.str, table_ptr->alias.str); view->viewName(tn); gwi.viewList.push_back(view); @@ -8470,10 +8309,10 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro else { // check foreign engine tables - bool infiniDB = (table_ptr->table ? isInfiniDB(table_ptr->table) : true); + bool columnStore = (table_ptr->table ? isMCSTable(table_ptr->table) : true); // trigger system catalog cache - if (infiniDB) + if (columnStore) csc->columnRIDs(make_table(table_ptr->db.str, table_ptr->table_name.str), true); string table_name = table_ptr->table_name.str; @@ -8482,9 +8321,9 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro if (table_ptr->db.length && strcmp(table_ptr->db.str, "information_schema") == 0) table_name = (table_ptr->schema_table_name.length ? table_ptr->schema_table_name.str : table_ptr->alias.str); - CalpontSystemCatalog::TableAliasName tn = make_aliasview(table_ptr->db.str, table_name, table_ptr->alias.str, viewName, infiniDB); + CalpontSystemCatalog::TableAliasName tn = make_aliasview(table_ptr->db.str, table_name, table_ptr->alias.str, viewName, columnStore); gwi.tbList.push_back(tn); - CalpontSystemCatalog::TableAliasName tan = make_aliastable(table_ptr->db.str, table_name, table_ptr->alias.str, infiniDB); + CalpontSystemCatalog::TableAliasName tan = make_aliastable(table_ptr->db.str, table_name, table_ptr->alias.str, columnStore); gwi.tableMap[tan] = make_pair(0, table_ptr); #ifdef DEBUG_WALK_COND cerr << tn << endl; @@ -8531,7 +8370,7 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro // MariaDB bug 624 - without the fix_fields call, delete with join may error with "No query step". //#if MYSQL_VERSION_ID < 50172 //@bug 3039. fix fields for constants - if (!icp->fixed) + if (!icp->is_fixed()) { icp->fix_fields(gwi.thd, (Item**)&icp); } @@ -8554,8 +8393,8 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro // processing. if (gwi.thd->derived_tables_processing) { - gwi.thd->infinidb_vtable.isUnion = false; - gwi.thd->infinidb_vtable.isUpdateWithDerive = true; + // MCOL-2178 isUnion member only assigned, never used + //MIGR::infinidb_vtable.isUnion = false; return -1; } @@ -8650,8 +8489,6 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro List_iterator_fast it(*gi.groupByFields); Item* item; vector funcFieldVec; - string sel_cols_in_create; - string sel_cols_in_select; bool redo = false; // empty rcWorkStack and ptWorkStack. They should all be empty by now. @@ -8711,18 +8548,13 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro boost::shared_ptr spcc(constCol); boost::shared_ptr spsc(sc); - if (sel_cols_in_create.length() != 0) - sel_cols_in_create += ", "; - string fullname; String str; - ifp->print(&str, QT_INFINIDB_NO_QUOTE); + ifp->print(&str, QT_ORDINARY); fullname = str.c_ptr(); - //sel_cols_in_create += fullname; if (ifp->is_autogenerated_name) // no alias { - sel_cols_in_create += fullname + " `" + escapeBackTick(str.c_ptr()) + "`"; sc->alias(fullname); } else // alias @@ -8730,15 +8562,8 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro if (!itemAlias.empty()) sc->alias(itemAlias); - sel_cols_in_create += fullname + " `" + escapeBackTick(sc->alias().c_str()) + "`"; } - if (ifp->is_autogenerated_name) - gwi.selectCols.push_back("`" + escapeBackTick(fullname.c_str()) + "`" + " `" + - escapeBackTick(itemAlias.empty() ? ifp->name.str : itemAlias.c_str()) + "`"); - else - gwi.selectCols.push_back("`" + escapeBackTick((itemAlias.empty() ? ifp->name.str : itemAlias.c_str())) + "`"); - // MCOL-1052 Replace SimpleColumn with ConstantColumn, // since it must have a single value only. if (constCol) @@ -8757,7 +8582,7 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro if (ifp->cached_table) tmp = ifp->cached_table; - gwi.tableMap[make_aliastable(sc->schemaName(), sc->tableName(), sc->tableAlias(), sc->isInfiniDB())] = + gwi.tableMap[make_aliastable(sc->schemaName(), sc->tableName(), sc->tableAlias(), sc->isColumnStore())] = make_pair(1, tmp); } else @@ -8789,14 +8614,6 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro // This item could be used in projection or HAVING later. gwi.extSelAggColsItems.push_back(item); - gwi.selectCols.push_back('`' + escapeBackTick(spac->alias().c_str()) + '`'); - String str(256); - item->print(&str, QT_INFINIDB_NO_QUOTE); - - if (sel_cols_in_create.length() != 0) - sel_cols_in_create += ", "; - - sel_cols_in_create += string(str.c_ptr()) + " `" + escapeBackTick(spac->alias().c_str()) + "`"; break; } @@ -8824,7 +8641,7 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro uint16_t parseInfo = 0; vector tmpVec; bool hasNonSupportItem = false; - parse_item(ifp, tmpVec, hasNonSupportItem, parseInfo); + parse_item(ifp, tmpVec, hasNonSupportItem, parseInfo, &gwi); if (ifp->with_subquery() || string(ifp->func_name()) == string("") || @@ -8856,38 +8673,11 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro continue; } - if ( ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE ) || - ((gwi.thd->lex)->sql_command == SQLCOM_DELETE ) || - ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE_MULTI ) || - ((gwi.thd->lex)->sql_command == SQLCOM_DELETE_MULTI ) ) - { } - else - { - redo = true; - String str; - ifp->print(&str, QT_INFINIDB_NO_QUOTE); - gwi.selectCols.push_back(string(str.c_ptr()) + " " + "`" + escapeBackTick(item->name.str) + "`"); - } - break; } - //SRCP srcp(rc); gwi.returnedCols.push_back(srcp); - if ( ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE ) || ((gwi.thd->lex)->sql_command == SQLCOM_DELETE ) || ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE_MULTI ) || ((gwi.thd->lex)->sql_command == SQLCOM_DELETE_MULTI )) - { } - else - { - String str(256); - ifp->print(&str, QT_INFINIDB_NO_QUOTE); - - if (sel_cols_in_create.length() != 0) - sel_cols_in_create += ", "; - - sel_cols_in_create += string(str.c_ptr()) + " `" + ifp->name.str + "`"; - gwi.selectCols.push_back("`" + escapeBackTick(ifp->name.str) + "`"); - } } else // InfiniDB Non support functions still go through post process for now { @@ -8979,18 +8769,8 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro return -1; } } - - //@Bug 3021. Bypass postprocess for update and delete. - //if ( ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE ) || ((gwi.thd->lex)->sql_command == SQLCOM_DELETE ) || ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE_MULTI ) || ((gwi.thd->lex)->sql_command == SQLCOM_DELETE_MULTI )) - //{} else { - // @bug 3881. Here is the real redo part. - redo = true; - // @bug 1706 - String funcStr; - ifp->print(&funcStr, QT_INFINIDB); - gwi.selectCols.push_back(string(funcStr.c_ptr()) + " `" + escapeBackTick(ifp->name.str) + "`"); // clear the error set by buildFunctionColumn gwi.fatalParseError = false; gwi.parseErrorText = ""; @@ -9000,115 +8780,60 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro break; } - case Item::INT_ITEM: + // DRRTUY Replace the whole section with typeid() checks or use + // reinterpret_cast here + case Item::CONST_ITEM: { - if ( ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE ) || ((gwi.thd->lex)->sql_command == SQLCOM_DELETE ) || ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE_MULTI ) || ((gwi.thd->lex)->sql_command == SQLCOM_DELETE_MULTI )) - { } - else + switch(item->cmp_type()) { - // do not push the dummy column (mysql added) to returnedCol - if (item->name.length && string(item->name.str) == "Not_used") - continue; + case INT_RESULT: + case STRING_RESULT: + case DECIMAL_RESULT: + case REAL_RESULT: + case TIME_RESULT: + { + if ( ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE ) || ((gwi.thd->lex)->sql_command == SQLCOM_DELETE ) || ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE_MULTI ) || ((gwi.thd->lex)->sql_command == SQLCOM_DELETE_MULTI )) + { } + else + { + // do not push the dummy column (mysql added) to returnedCol + if (item->name.length && string(item->name.str) == "Not_used") + continue; - // @bug3509. Constant column is sent to ExeMgr now. - SRCP srcp(buildReturnedColumn(item, gwi, gwi.fatalParseError)); + // @bug3509. Constant column is sent to ExeMgr now. + SRCP srcp(buildReturnedColumn(item, gwi, gwi.fatalParseError)); - if (item->name.length) - srcp->alias(item->name.str); + if (item->name.length) + srcp->alias(item->name.str); - gwi.returnedCols.push_back(srcp); + gwi.returnedCols.push_back(srcp); + } - Item_int* isp = reinterpret_cast(item); - ostringstream oss; - oss << isp->value << " `" << escapeBackTick(srcp->alias().c_str()) << "`"; + break; + } - if (sel_cols_in_create.length() != 0) - sel_cols_in_create += ", "; - - sel_cols_in_create += oss.str(); - gwi.selectCols.push_back(oss.str()); + // MCOL-2178 This switch doesn't handl + // ROW_ + default: + { + IDEBUG(cerr << "Warning unsupported cmp_type() in projection" << endl); + } } - break; - } - - case Item::STRING_ITEM: - { - if ( ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE ) || ((gwi.thd->lex)->sql_command == SQLCOM_DELETE ) || ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE_MULTI ) || ((gwi.thd->lex)->sql_command == SQLCOM_DELETE_MULTI )) - { } - else - { - SRCP srcp(buildReturnedColumn(item, gwi, gwi.fatalParseError)); - gwi.returnedCols.push_back(srcp); - - if (item->name.length) - srcp->alias(item->name.str); - - Item_string* isp = reinterpret_cast(item); - String val, *str = isp->val_str(&val); - string valStr; - valStr.assign(str->ptr(), str->length()); - string name = "'" + valStr + "'" + " " + "`" + escapeBackTick(srcp->alias().c_str()) + "`"; - - if (sel_cols_in_create.length() != 0) - sel_cols_in_create += ", "; - - sel_cols_in_create += name; - gwi.selectCols.push_back(name); - } - - break; - } - - case Item::DECIMAL_ITEM: - { - if ( ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE ) || ((gwi.thd->lex)->sql_command == SQLCOM_DELETE ) || ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE_MULTI ) || ((gwi.thd->lex)->sql_command == SQLCOM_DELETE_MULTI )) - { } - else - { - SRCP srcp(buildReturnedColumn(item, gwi, gwi.fatalParseError)); - gwi.returnedCols.push_back(srcp); - - if (item->name.length) - srcp->alias(item->name.str); - - Item_decimal* isp = reinterpret_cast(item); - String val, *str = isp->val_str(&val); - string valStr; - valStr.assign(str->ptr(), str->length()); - ostringstream oss; - oss << valStr.c_str() << " `" << escapeBackTick(srcp->alias().c_str()) << "`"; - - if (sel_cols_in_create.length() != 0) - sel_cols_in_create += ", "; - - sel_cols_in_create += oss.str(); - gwi.selectCols.push_back(oss.str()); - } - - break; - } + } // CONST_ITEM ends here case Item::NULL_ITEM: { - /*if ( ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE ) || ((gwi.thd->lex)->sql_command == SQLCOM_DELETE ) || ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE_MULTI ) || ((gwi.thd->lex)->sql_command == SQLCOM_DELETE_MULTI ) ) + if ( ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE ) || ((gwi.thd->lex)->sql_command == SQLCOM_DELETE ) || ((gwi.thd->lex)->sql_command == SQLCOM_UPDATE_MULTI ) || ((gwi.thd->lex)->sql_command == SQLCOM_DELETE_MULTI ) ) { } else { SRCP srcp(buildReturnedColumn(item, gwi, gwi.fatalParseError)); gwi.returnedCols.push_back(srcp); - if (item->name) - srcp->alias(item->name); - - string name = string("null `") + escapeBackTick(srcp->alias().c_str()) + string("`") ; - - if (sel_cols_in_create.length() != 0) - sel_cols_in_create += ", "; - - sel_cols_in_create += name; - gwi.selectCols.push_back("null"); - }*/ + if (item->name.length) + srcp->alias(item->name.str); + } break; } @@ -9164,20 +8889,6 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro rc->alias(sub->name.str); gwi.returnedCols.push_back(SRCP(rc)); - String str; - sub->get_select_lex()->print(gwi.thd, &str, QT_INFINIDB_NO_QUOTE); - sel_cols_in_create += "(" + string(str.c_ptr()) + ")"; - - if (sub->name.length) - { - sel_cols_in_create += "`" + escapeBackTick(sub->name.str) + "`"; - gwi.selectCols.push_back(sub->name.str); - } - else - { - sel_cols_in_create += "`" + escapeBackTick(str.c_ptr()) + "`"; - gwi.selectCols.push_back("`" + escapeBackTick(str.c_ptr()) + "`"); - } break; } @@ -9333,7 +9044,7 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro } String str; - funcFieldVec[i]->print(&str, QT_INFINIDB_NO_QUOTE); + funcFieldVec[i]->print(&str, QT_ORDINARY); sc->alias(string(str.c_ptr())); //sc->tableAlias(funcFieldVec[i]->table_name); sc->tableAlias(sc->tableAlias()); @@ -9356,14 +9067,10 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro gwi.returnedCols.push_back(srcp); gwi.columnMap.insert(CalpontSelectExecutionPlan::ColumnMap::value_type(string(funcFieldVec[i]->field_name.str), srcp)); - if (sel_cols_in_create.length() != 0) - sel_cols_in_create += ", "; - string fullname; fullname = str.c_ptr(); - sel_cols_in_create += fullname + " `" + escapeBackTick(fullname.c_str()) + "`"; TABLE_LIST* tmp = (funcFieldVec[i]->cached_table ? funcFieldVec[i]->cached_table : 0); - gwi.tableMap[make_aliastable(sc->schemaName(), sc->tableName(), sc->tableAlias(), sc->isInfiniDB())] = + gwi.tableMap[make_aliastable(sc->schemaName(), sc->tableName(), sc->tableAlias(), sc->isColumnStore())] = make_pair(1, tmp); } } @@ -9374,7 +9081,7 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro SRCP minSc; // min width projected column. for count(*) use // Group by list. not valid for union main query - if (gwi.thd->infinidb_vtable.vtable_state == THD::INFINIDB_CREATE_VTABLE && !unionSel) + if (!unionSel) { gwi.clauseType = GROUP_BY; Item* nonSupportItem = NULL; @@ -9546,10 +9253,14 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro // @bug5638. The group by column is constant but not counter, alias has to match a column // on the select list else if (!groupcol->counter_used && - (groupItem->type() == Item::INT_ITEM || - groupItem->type() == Item::STRING_ITEM || - groupItem->type() == Item::REAL_ITEM || - groupItem->type() == Item::DECIMAL_ITEM)) + (groupItem->type() == Item::CONST_ITEM && + (groupItem->cmp_type() == INT_RESULT || + groupItem->cmp_type() == STRING_RESULT || + groupItem->cmp_type() == REAL_RESULT || + groupItem->cmp_type() == DECIMAL_RESULT) + ) + ) + { ReturnedColumn* rc = 0; @@ -9652,15 +9363,9 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro } // GROUP processing ends here - if (gwi.thd->infinidb_vtable.vtable_state == THD::INFINIDB_CREATE_VTABLE) + // ORDER BY processing starts here { ORDER* ordercol = reinterpret_cast(gi.groupByOrder); - string create_query(gwi.thd->infinidb_vtable.create_vtable_query.c_ptr()); - string select_query(gwi.thd->infinidb_vtable.select_vtable_query.c_ptr()); - string lower_create_query(gwi.thd->infinidb_vtable.create_vtable_query.c_ptr()); - string lower_select_query(gwi.thd->infinidb_vtable.select_vtable_query.c_ptr()); - boost::algorithm::to_lower(lower_create_query); - boost::algorithm::to_lower(lower_select_query); // check if window functions are in order by. InfiniDB process order by list if @@ -9696,12 +9401,22 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro bool nonAggField = true; // ignore not_used column on order by. - if (ord_item->type() == Item::INT_ITEM && ord_item->full_name() && string(ord_item->full_name()) == "Not_used") + if ((ord_item->type() == Item::CONST_ITEM + && ord_item->cmp_type() == INT_RESULT) + && ord_item->full_name() + && !strcmp(ord_item->full_name(), "Not_used")) + { continue; - else if (ord_item->type() == Item::INT_ITEM) + } + else if (ord_item->type() == Item::CONST_ITEM + && ord_item->cmp_type() == INT_RESULT) + { rc = gwi.returnedCols[((Item_int*)ord_item)->val_int() - 1]->clone(); + } else if (ord_item->type() == Item::SUBSELECT_ITEM) + { gwi.fatalParseError = true; + } else if (ordercol->in_field_list && ord_item->type() == Item::FIELD_ITEM) { rc = buildReturnedColumn(ord_item, gwi, gwi.fatalParseError); @@ -9752,26 +9467,9 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro // this ORDER BY item. if ( iter == gwi.groupByCols.end() ) { - Item_ident* iip = reinterpret_cast(ord_item); std::ostringstream ostream; - ostream << "'"; - - if (iip->db_name) - ostream << iip->db_name << '.'; - else - ostream << "unknown db" << '.'; - - if (iip->table_name) - ostream << iip->table_name << '.'; - else - ostream << "unknown table" << '.'; - - if (iip->field_name.length) - ostream << iip->field_name.str; - else - ostream << "unknown field"; - - ostream << "'"; + std::ostringstream& osr = ostream; + getColNameFromItem(osr, *ordercol->item); Message::Args args; args.add(ostream.str()); string emsg = IDBErrorInfo::instance()->errorMsg(ERR_NOT_GROUPBY_EXPRESSION, args); @@ -9901,33 +9599,11 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro if (!isUnion && !gwi.hasWindowFunc && gwi.subSelectType == CalpontSelectExecutionPlan::MAIN_SELECT) { - std::ostringstream vtb; - vtb << "infinidb_vtable.$vtable_" << gwi.thd->thread_id; - - //vtb << "$vtable_" << gwi.thd->thread_id; // re-construct the select query and redo phase 1 if (redo) { - // select now() from region case. returnedCols should have minSc. - if (sel_cols_in_create.length() == 0) - { - SimpleColumn* sc = dynamic_cast(gwi.returnedCols[0].get()); - - if (sc) - sel_cols_in_create = dynamic_cast(gwi.returnedCols[0].get())->columnName(); - else - sel_cols_in_create = gwi.returnedCols[0]->alias(); - } - - // select * from derived table case - if (gwi.selectCols.empty()) - sel_cols_in_create = " * "; - - create_query = "create temporary table " + vtb.str() + " engine = aria as select " + sel_cols_in_create + " from "; TABLE_LIST* table_ptr = gi.groupByTables; - bool firstTb = true; - // put all tables, derived tables and views on the list //TABLE_LIST* table_ptr = select_lex.get_table_list(); set aliasSet; // to avoid duplicate table alias @@ -9942,14 +9618,6 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro if (aliasSet.find(table_ptr->alias.str) != aliasSet.end()) continue; - String str; - (table_ptr->derived->first_select())->print(gwi.thd, &str, QT_INFINIDB_DERIVED); - - if (!firstTb) - create_query += ", "; - - create_query += "(" + string(str.c_ptr()) + ") " + string(table_ptr->alias.str); - firstTb = false; aliasSet.insert(table_ptr->alias.str); } else if (table_ptr->view) @@ -9957,13 +9625,7 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro if (aliasSet.find(table_ptr->alias.str) != aliasSet.end()) continue; - if (!firstTb) - create_query += ", "; - - create_query += string(table_ptr->db.str) + "." + string(table_ptr->table_name.str) + - string(" `") + escapeBackTick(table_ptr->alias.str) + string("`"); aliasSet.insert(table_ptr->alias.str); - firstTb = false; } else { @@ -9975,13 +9637,6 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro string(table_ptr->alias.str)) != aliasSet.end()) continue; - if (!firstTb) - create_query += ", "; - - create_query += string(table_ptr->db.str) + "." + string(table_ptr->table_name.str) + string(" "); - create_query += string(" `") + - escapeBackTick(table_ptr->referencing_view->alias.str) + "_" + - escapeBackTick(table_ptr->alias.str) + string("`"); aliasSet.insert(string(table_ptr->referencing_view->alias.str) + "_" + string(table_ptr->alias.str)); } @@ -9990,83 +9645,31 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro if (aliasSet.find(table_ptr->alias.str) != aliasSet.end()) continue; - if (!firstTb) - create_query += ", "; - - create_query += string(table_ptr->db.str) + "." + string(table_ptr->table_name.str) + string(" "); - create_query += string("`") + escapeBackTick(table_ptr->alias.str) + string("`"); aliasSet.insert(table_ptr->alias.str); } - firstTb = false; } } - - gwi.thd->infinidb_vtable.create_vtable_query.free(); - gwi.thd->infinidb_vtable.create_vtable_query.append(create_query.c_str(), create_query.length()); - gwi.thd->infinidb_vtable.vtable_state = THD::INFINIDB_REDO_PHASE1; // redo phase 1 - - // turn off select distinct from post process unless there're post process functions - // on the select list. - string sel_query = "select "; - - if (gi.groupByDistinct && redo) - sel_query = "select distinct "; - else - sel_query = "select "; - - // select * from derived table... - if (gwi.selectCols.size() == 0) - sel_query += " * "; - - for (uint32_t i = 0; i < gwi.selectCols.size(); i++) - { - sel_query += gwi.selectCols[i]; - - if ( i + 1 != gwi.selectCols.size()) - sel_query += ", "; - } - - //select_query.replace(lower_select_query.find("select *"), string("select *").length(), sel_query); } else { // remove order by clause in case this phase has been executed before. // need a better fix later, like skip all the other non-optimized phase. - size_t pos = lower_select_query.find("order by"); - if (pos != string::npos) - select_query.replace(pos, lower_select_query.length() - pos, ""); - - //select_query = "select * from " + vtb.str(); // MCOL-1052 if (unionSel) { ordercol = reinterpret_cast(gi.groupByOrder); - //order_list = gi.groupByOrder; } else ordercol = 0; - ord_cols = ""; - for (; ordercol; ordercol = ordercol->next) { Item* ord_item = *(ordercol->item); - // @bug 1706. re-construct the order by item one by one, because the ord_cols constucted so far - // is for REDO phase. - if (ord_cols.length() != 0) - ord_cols += ", "; - - if (ordercol->in_field_list && ordercol->counter_used) - { - ostringstream oss; - oss << ordercol->counter; - ord_cols += oss.str(); - } - else if (ord_item->type() == Item::NULL_ITEM) + if (ord_item->type() == Item::NULL_ITEM) { // MCOL-793 Do nothing for an ORDER BY NULL } @@ -10130,7 +9733,8 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro else if (ord_item->name.length) { // for union order by 1 case. For unknown reason, it doesn't show in_field_list - if (ord_item->type() == Item::INT_ITEM) + if (ord_item->type() == Item::CONST_ITEM + && ord_item->cmp_type() == INT_RESULT) { ord_cols += ord_item->name.str; } @@ -10164,7 +9768,7 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro else { String str; - ord_item->print(&str, QT_INFINIDB_NO_QUOTE); + ord_item->print(&str, QT_ORDINARY); ord_cols += string(str.c_ptr()); } @@ -10175,7 +9779,6 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro if ( gwi.orderByCols.size() ) // has order by { - gwi.thd->infinidb_vtable.has_order_by = true; csep->hasOrderBy(true); csep->specHandlerProcessed(true); } @@ -10202,9 +9805,6 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro csep->limitStart(((Item_int*)gi.groupByTables->select_lex->offset_limit)->val_int()); } - //gwi.thd->infinidb_vtable.select_vtable_query.free(); - //gwi.thd->infinidb_vtable.select_vtable_query.append(select_query.c_str(), select_query.length()); - // We don't currently support limit with correlated subquery if (csep->limitNum() != (uint64_t) - 1 && gwi.subQuery && !gwi.correlatedTbNameVec.empty()) @@ -10300,7 +9900,6 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro csep->derivedTableList(gwi.derivedTbList); csep->selectSubList(selectSubList); csep->subSelectList(gwi.subselectList); - gwi.thd->infinidb_vtable.duplicate_field_name = false; clearStacks(gwi); return 0; } diff --git a/dbcon/mysql/ha_calpont_impl.cpp b/dbcon/mysql/ha_calpont_impl.cpp index 1d3c98003..7892f7c73 100644 --- a/dbcon/mysql/ha_calpont_impl.cpp +++ b/dbcon/mysql/ha_calpont_impl.cpp @@ -1,5 +1,5 @@ -/* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + /* Copyright (C) 2014 InfiniDB, Inc. + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -80,6 +80,7 @@ using namespace execplan; using namespace dataconvert; #include "sm.h" +#include "ha_mcs_pushdown.h" #include "bytestream.h" #include "messagequeue.h" @@ -168,8 +169,6 @@ static const string interval_names[] = const unsigned NONSUPPORTED_ERR_THRESH = 2000; -//TODO: make this session-safe (put in connMap?) -//vector rmParms; ResourceManager* rm = ResourceManager::instance(); bool useHdfs = rm->useHdfs(); @@ -272,8 +271,8 @@ void storeNumericField(Field** f, int64_t value, CalpontSystemCatalog::ColType& // @bug4388 stick to InfiniDB's scale in case mysql gives wrong scale due // to create vtable limitation. - if (f2->dec < ct.scale) - f2->dec = ct.scale; + //if (f2->dec < ct.scale) + // f2->dec = ct.scale; char buf[256]; dataconvert::DataConvert::decimalToString(value, (unsigned)ct.scale, buf, 256, ct.colDataType); @@ -578,10 +577,6 @@ int fetchNextRow(uchar* buf, cal_table_info& ti, cal_connection_info* ci, bool h * At a later date we should set this more intelligently * based on the result set. */ - /* MCOL-683: UTF-8 datetime no msecs is 57, this sometimes happens! */ -// if (((*f)->field_length > 19) && ((*f)->field_length != 57)) -// (*f)->field_length = strlen(tmp); - Field_varstring* f2 = (Field_varstring*)*f; f2->store(tmp, strlen(tmp), f2->charset()); break; @@ -743,28 +738,18 @@ int fetchNextRow(uchar* buf, cal_table_info& ti, cal_connection_info* ci, bool h if (dl == std::numeric_limits::infinity()) continue; - //int64_t* icvp = (int64_t*)&dl; - //intColVal = *icvp; Field_float* f2 = (Field_float*)*f; // bug 3485, reserve enough space for the longest float value // -3.402823466E+38 to -1.175494351E-38, 0, and // 1.175494351E-38 to 3.402823466E+38. (*f)->field_length = 40; - //float float_val = *(float*)(&value); - //f2->store(float_val); - if (f2->decimals() < (uint32_t)row.getScale(s)) - f2->dec = (uint32_t)row.getScale(s); - f2->store(dl); if ((*f)->null_ptr) *(*f)->null_ptr &= ~(*f)->null_bit; break; - - //storeNumericField(f, intColVal, colType); - //break; } case CalpontSystemCatalog::DOUBLE: @@ -781,26 +766,12 @@ int fetchNextRow(uchar* buf, cal_table_info& ti, cal_connection_info* ci, bool h // 2.2250738585072014E-308 to 1.7976931348623157E+308. (*f)->field_length = 310; - //double double_val = *(double*)(&value); - //f2->store(double_val); - if ((f2->decimals() == DECIMAL_NOT_SPECIFIED && row.getScale(s) > 0) - || f2->decimals() < row.getScale(s)) - { - f2->dec = row.getScale(s); - } - f2->store(dl); if ((*f)->null_ptr) *(*f)->null_ptr &= ~(*f)->null_bit; break; - - - //int64_t* icvp = (int64_t*)&dl; - //intColVal = *icvp; - //storeNumericField(f, intColVal, colType); - //break; } case CalpontSystemCatalog::LONGDOUBLE: @@ -817,12 +788,6 @@ int fetchNextRow(uchar* buf, cal_table_info& ti, cal_connection_info* ci, bool h { char buf[310]; Field_new_decimal* f2 = (Field_new_decimal*)*f; - if ((f2->decimals() == DECIMAL_NOT_SPECIFIED && row.getScale(s) > 0) - || f2->decimals() < row.getScale(s)) - { - f2->dec = row.getScale(s); - } -// dl /= pow(10.0, (double)f2->dec); snprintf(buf, 310, "%.20Lg", dl); f2->store(buf, strlen(buf), f2->charset()); if ((*f)->null_ptr) @@ -838,12 +803,6 @@ int fetchNextRow(uchar* buf, cal_table_info& ti, cal_connection_info* ci, bool h // 2.2250738585072014E-308 to 1.7976931348623157E+308. (*f)->field_length = 310; - if ((f2->decimals() == DECIMAL_NOT_SPECIFIED && row.getScale(s) > 0) - || f2->decimals() < row.getScale(s)) - { - f2->dec = row.getScale(s); - } - f2->store(static_cast(dl)); if ((*f)->null_ptr) *(*f)->null_ptr &= ~(*f)->null_bit; @@ -1217,7 +1176,7 @@ vector getOnUpdateTimestampColumns(string& schema, string& tableName, in return returnVal; } -uint32_t doUpdateDelete(THD* thd) +uint32_t doUpdateDelete(THD* thd, gp_walk_info& gwi) { if (get_fe_conn_info_ptr() == NULL) set_fe_conn_info_ptr((void*)new cal_connection_info()); @@ -1234,7 +1193,6 @@ uint32_t doUpdateDelete(THD* thd) //@Bug 4387. Check BRM status before start statement. boost::scoped_ptr dbrmp(new DBRM()); int rc = dbrmp->isReadWrite(); - thd->infinidb_vtable.isInfiniDBDML = true; if (rc != 0 ) { @@ -1316,7 +1274,6 @@ uint32_t doUpdateDelete(THD* thd) } // @bug 1127. Re-construct update stmt using lex instead of using the original query. -// string dmlStmt=""; string dmlStmt = string(idb_mysql_query_str(thd)); string schemaName; string tableName(""); @@ -1334,28 +1291,16 @@ uint32_t doUpdateDelete(THD* thd) { ColumnAssignment* columnAssignmentPtr; Item_field* item; -// TABLE_LIST* table_ptr = thd->lex->select_lex.get_table_list(); - List_iterator_fast field_it(thd->lex->select_lex.item_list); + List_iterator_fast field_it(thd->lex->first_select_lex()->item_list); List_iterator_fast value_it(thd->lex->value_list); -// dmlStmt += "update "; updateCP->queryType(CalpontSelectExecutionPlan::UPDATE); ci->stats.fQueryType = updateCP->queryType(); uint32_t cnt = 0; tr1::unordered_set timeStampColumnNames; -// for (; table_ptr; table_ptr= table_ptr->next_local) -// { -// dmlStmt += string(table_ptr->table_name); -// if (table_ptr->next_local) -// dmlStmt += ", "; -// } - -// dmlStmt += " set "; - while ((item = (Item_field*) field_it++)) { cnt++; -// dmlStmt += string(item->name) + "="; string tmpTableName = bestTableName(item); @@ -1395,34 +1340,43 @@ uint32_t doUpdateDelete(THD* thd) else schemaName = string(item->db_name); + columnAssignmentPtr = new ColumnAssignment(item->name.str, "=", ""); if (item->field_type() == MYSQL_TYPE_TIMESTAMP || item->field_type() == MYSQL_TYPE_TIMESTAMP2) { timeStampColumnNames.insert(string(item->name.str)); } - columnAssignmentPtr = new ColumnAssignment(); - columnAssignmentPtr->fColumn = string(item->name.str); - columnAssignmentPtr->fOperator = "="; - columnAssignmentPtr->fFuncScale = 0; Item* value = value_it++; - if (value->type() == Item::STRING_ITEM) + if (value->type() == Item::CONST_ITEM) { - //@Bug 2587 use val_str to replace value->name to get rid of 255 limit - String val, *str; - str = value->val_str(&val); - columnAssignmentPtr->fScalarExpression.assign(str->ptr(), str->length()); - columnAssignmentPtr->fFromCol = false; + if (value->cmp_type() == STRING_RESULT) + { + //@Bug 2587 use val_str to replace value->name to get rid of 255 limit + String val, *str; + str = value->val_str(&val); + columnAssignmentPtr->fScalarExpression.assign(str->ptr(), str->length()); + columnAssignmentPtr->fFromCol = false; + } + else if (value->cmp_type() == INT_RESULT) + { + std::ostringstream oss; + + if (value->unsigned_flag) + { + oss << value->val_uint(); + } + else + { + oss << value->val_int(); + } + + columnAssignmentPtr->fScalarExpression = oss.str(); + columnAssignmentPtr->fFromCol = false; + } } - else if ( value->type() == Item::VARBIN_ITEM ) - { - String val, *str; - str = value->val_str(&val); - columnAssignmentPtr->fScalarExpression.assign(str->ptr(), str->length()); - columnAssignmentPtr->fFromCol = false; - } - else if ( value->type() == Item::FUNC_ITEM ) + else if ( value->type() == Item::FUNC_ITEM ) { //Bug 2092 handle negative values Item_func* ifp = (Item_func*)value; @@ -1487,23 +1441,6 @@ uint32_t doUpdateDelete(THD* thd) } } } - else if ( value->type() == Item::INT_ITEM ) - { - std::ostringstream oss; - - if (value->unsigned_flag) - { - oss << value->val_uint(); - } - else - { - oss << value->val_int(); - } - -// dmlStmt += oss.str(); - columnAssignmentPtr->fScalarExpression = oss.str(); - columnAssignmentPtr->fFromCol = false; - } else if ( value->type() == Item::FIELD_ITEM) { isFromCol = true; @@ -1528,8 +1465,9 @@ uint32_t doUpdateDelete(THD* thd) else if ( value->type() == Item::NULL_ITEM ) { // dmlStmt += "NULL"; - columnAssignmentPtr->fScalarExpression = "NULL"; + columnAssignmentPtr->fScalarExpression = ""; columnAssignmentPtr->fFromCol = false; + columnAssignmentPtr->fIsNull = true; } else if ( value->type() == Item::SUBSELECT_ITEM ) { @@ -1566,7 +1504,6 @@ uint32_t doUpdateDelete(THD* thd) setError(thd, ER_INTERNAL_ERROR, logging::IDBErrorInfo::instance()->errorMsg(ERR_WF_UPDATE)); return ER_CHECK_NOT_IMPLEMENTED; - //return 0; } else { @@ -1586,8 +1523,6 @@ uint32_t doUpdateDelete(THD* thd) } colAssignmentListPtr->push_back ( columnAssignmentPtr ); -// if (cnt < thd->lex->select_lex.item_list.elements) -// dmlStmt += ", "; } // Support for on update current_timestamp() for timestamp fields @@ -1598,11 +1533,7 @@ uint32_t doUpdateDelete(THD* thd) { if (timeStampColumnNames.find(onUpdateTimeStampColumns[i]) == timeStampColumnNames.end()) { - columnAssignmentPtr = new ColumnAssignment(); - columnAssignmentPtr->fColumn = string(onUpdateTimeStampColumns[i]); - columnAssignmentPtr->fOperator = "="; - columnAssignmentPtr->fFuncScale = 0; - columnAssignmentPtr->fFromCol = false; + columnAssignmentPtr = new ColumnAssignment(string(onUpdateTimeStampColumns[i]), "=", ""); struct timeval tv; char buf[64]; gettimeofday(&tv, 0); @@ -1616,7 +1547,6 @@ uint32_t doUpdateDelete(THD* thd) } else { -// dmlStmt = string(idb_mysql_query_str(thd)); updateCP->queryType(CalpontSelectExecutionPlan::DELETE); ci->stats.fQueryType = updateCP->queryType(); } @@ -1635,7 +1565,7 @@ uint32_t doUpdateDelete(THD* thd) } else { - first_table = (TABLE_LIST*) thd->lex->select_lex.table_list.first; + first_table = (TABLE_LIST*) thd->lex->first_select_lex()->table_list.first; aTableName.schema = first_table->table->s->db.str; aTableName.table = first_table->table->s->table_name.str; } @@ -1648,7 +1578,6 @@ uint32_t doUpdateDelete(THD* thd) } catch (IDBExcept& ie) { -// setError(thd, ER_UNKNOWN_TABLE, ie.what()); setError(thd, ER_INTERNAL_ERROR, ie.what()); return ER_INTERNAL_ERROR; } @@ -1686,9 +1615,9 @@ uint32_t doUpdateDelete(THD* thd) } else if ((thd->lex)->sql_command == SQLCOM_DELETE_MULTI) //@Bug 6121 error out on multi tables delete. { - if ( (thd->lex->select_lex.join) != 0) + if ( (thd->lex->first_select_lex()->join) != 0) { - multi_delete* deleteTable = (multi_delete*)((thd->lex->select_lex.join)->result); + multi_delete* deleteTable = (multi_delete*)((thd->lex->first_select_lex()->join)->result); first_table = (TABLE_LIST*) deleteTable->get_tables(); if (deleteTable->get_num_of_tables() == 1) @@ -1711,7 +1640,7 @@ uint32_t doUpdateDelete(THD* thd) } else { - first_table = (TABLE_LIST*) thd->lex->select_lex.table_list.first; + first_table = (TABLE_LIST*) thd->lex->first_select_lex()->table_list.first; schemaName = first_table->table->s->db.str; tableName = first_table->table->s->table_name.str; aliasName = first_table->alias.str; @@ -1722,7 +1651,7 @@ uint32_t doUpdateDelete(THD* thd) } else { - first_table = (TABLE_LIST*) thd->lex->select_lex.table_list.first; + first_table = (TABLE_LIST*) thd->lex->first_select_lex()->table_list.first; schemaName = first_table->table->s->db.str; tableName = first_table->table->s->table_name.str; aliasName = first_table->alias.str; @@ -1755,16 +1684,16 @@ uint32_t doUpdateDelete(THD* thd) if (( (thd->lex)->sql_command == SQLCOM_UPDATE ) || ( (thd->lex)->sql_command == SQLCOM_UPDATE_MULTI ) ) { - items = (thd->lex->select_lex.item_list); - thd->lex->select_lex.item_list = thd->lex->value_list; + items = (thd->lex->first_select_lex()->item_list); + thd->lex->first_select_lex()->item_list = thd->lex->value_list; } - select_lex = lex->select_lex; + select_lex = *lex->first_select_lex(); //@Bug 2808 Error out on order by or limit clause //@bug5096. support dml limit. - if (/*( select_lex.explicit_limit ) || */( select_lex.order_list.elements != 0 ) ) + if (( thd->lex->first_select_lex()->order_list.elements != 0 ) ) { string emsg("DML Statement with order by clause is not currently supported."); thd->raise_error_printf(ER_INTERNAL_ERROR, emsg.c_str()); @@ -1773,13 +1702,8 @@ uint32_t doUpdateDelete(THD* thd) return 0; } - //thd->infinidb_vtable.isInfiniDBDML = true; - THD::infinidb_state origState = thd->infinidb_vtable.vtable_state; //if (( (thd->lex)->sql_command == SQLCOM_UPDATE ) || ( (thd->lex)->sql_command == SQLCOM_UPDATE_MULTI ) ) { - gp_walk_info gwi; - thd->infinidb_vtable.vtable_state = THD::INFINIDB_CREATE_VTABLE; - gwi.thd = thd; //updateCP->subType (CalpontSelectExecutionPlan::SINGLEROW_SUBS); //set scalar updateCP->subType (CalpontSelectExecutionPlan::SELECT_SUBS); //@Bug 2975. @@ -1813,15 +1737,14 @@ uint32_t doUpdateDelete(THD* thd) gwi.clauseType = WHERE; - if (getSelectPlan(gwi, select_lex, updateCP) != 0) //@Bug 3030 Modify the error message for unsupported functions + if (getSelectPlan(gwi, select_lex, updateCP, false, true) != 0) //@Bug 3030 Modify the error message for unsupported functions { - if (thd->infinidb_vtable.isUpdateWithDerive) + if (gwi.cs_vtable_is_update_with_derive) { // @bug 4457. MySQL inconsistence! for some queries, some structures are only available // in the derived_tables_processing phase. So by pass the phase for DML only when the // execution plan can not be successfully generated. recover lex before returning; - thd->lex->select_lex.item_list = items; - thd->infinidb_vtable.vtable_state = origState; + thd->lex->first_select_lex()->item_list = items; return 0; } @@ -1971,7 +1894,7 @@ uint32_t doUpdateDelete(THD* thd) //cout<< "Plan is " << endl << *updateCP << endl; if (( (thd->lex)->sql_command == SQLCOM_UPDATE ) || ( (thd->lex)->sql_command == SQLCOM_UPDATE_MULTI ) ) - thd->lex->select_lex.item_list = items; + thd->lex->first_select_lex()->item_list = items; } //cout<< "Plan is " << endl << *updateCP << endl; @@ -1987,8 +1910,6 @@ uint32_t doUpdateDelete(THD* thd) boost::shared_ptr plan = pDMLPackage->get_ExecutionPlan(); updateCP->rmParms(ci->rmParms); updateCP->serialize(*plan); - // recover original vtable state - thd->infinidb_vtable.vtable_state = origState; //cout << "plan has bytes " << plan->length() << endl; pDMLPackage->write(bytestream); @@ -2335,29 +2256,12 @@ int ha_calpont_impl_discover_existence(const char* schema, const char* name) int ha_calpont_impl_rnd_init(TABLE* table) { -#ifdef DEBUG_SETENV - string home(getenv("HOME")); - - if (!getenv("COLUMNSTORE_HOME")) - { - string calpontHome(home + "/Calpont/etc/"); - setenv("COLUMNSTORE_HOME", calpontHome.c_str(), 1); - } - - if (!getenv("COLUMNSTORE_CONFIG_FILE")) - { - string calpontConfigFile(home + "/mariadb/columnstore/etc/Columnstore.xml"); - setenv("COLUMNSTORE_CONFIG_FILE", calpontConfigFile.c_str(), 1); - } - - if (!getenv("CALPONT_CSC_IDENT")) - setenv("CALPONT_CSC_IDENT", "dm", 1); - -#endif - IDEBUG( cout << "rnd_init for table " << table->s->table_name.str << endl ); THD* thd = current_thd; + gp_walk_info gwi; + gwi.thd = thd; + //check whether the system is ready to process statement. #ifndef _MSC_VER static DBRM dbrm(true); @@ -2367,20 +2271,22 @@ int ha_calpont_impl_rnd_init(TABLE* table) { // Still not ready setError(thd, ER_INTERNAL_ERROR, "The system is not yet ready to accept queries"); - thd->infinidb_vtable.vtable_state = THD::INFINIDB_ERROR; return ER_INTERNAL_ERROR; } else if (bSystemQueryReady < 0) { // Still not ready setError(thd, ER_INTERNAL_ERROR, "DBRM is not responding. Cannot accept queries"); - thd->infinidb_vtable.vtable_state = THD::INFINIDB_ERROR; return ER_INTERNAL_ERROR; } - #endif - // prevent "create table as select" from running on slave - thd->infinidb_vtable.hasInfiniDBTable = true; + + // Set this to close all outstanding FEP connections on + // client disconnect in handlerton::closecon_handlerton(). + if ( !thd_get_ha_data(thd, mcs_hton)) + { + thd_set_ha_data(thd, mcs_hton, reinterpret_cast(0x42)); + } cal_connection_info* ci = reinterpret_cast(get_fe_conn_info_ptr()); @@ -2395,40 +2301,12 @@ int ha_calpont_impl_rnd_init(TABLE* table) thd->lex->sql_command == SQLCOM_LOAD)) return 0; - // @bug 3005. if the table is not $vtable, then this could be a UDF defined on the connector. - // watch this for other complications - if (thd->infinidb_vtable.vtable_state == THD::INFINIDB_SELECT_VTABLE && - string(table->s->table_name.str).find("$vtable") != 0) - return 0; - - // return error is error status is already set - if (thd->infinidb_vtable.vtable_state == THD::INFINIDB_ERROR) - return ER_INTERNAL_ERROR; - - // by pass the extra union trips. return 0 - if (thd->infinidb_vtable.isUnion && thd->infinidb_vtable.vtable_state == THD::INFINIDB_CREATE_VTABLE) - return 0; - - // @bug 2232. Basic SP support. Error out non support sp cases. - // @bug 3939. Only error out for sp with select. Let pass for alter table in sp. - if (thd->infinidb_vtable.call_sp && (thd->lex)->sql_command != SQLCOM_ALTER_TABLE) - { - setError(thd, ER_CHECK_NOT_IMPLEMENTED, "This stored procedure syntax is not supported by Columnstore in this version"); - thd->infinidb_vtable.vtable_state = THD::INFINIDB_ERROR; - return ER_INTERNAL_ERROR; - } - - // mysql reads table twice for order by - if (thd->infinidb_vtable.vtable_state == THD::INFINIDB_REDO_PHASE1 || - thd->infinidb_vtable.vtable_state == THD::INFINIDB_ORDER_BY) - return 0; - if ( (thd->lex)->sql_command == SQLCOM_ALTER_TABLE ) return 0; //Update and delete code if ( ((thd->lex)->sql_command == SQLCOM_UPDATE) || ((thd->lex)->sql_command == SQLCOM_DELETE) || ((thd->lex)->sql_command == SQLCOM_DELETE_MULTI) || ((thd->lex)->sql_command == SQLCOM_UPDATE_MULTI)) - return doUpdateDelete(thd); + return doUpdateDelete(thd, gwi); uint32_t sessionID = tid2sid(thd->thread_id); boost::shared_ptr csc = CalpontSystemCatalog::makeCalpontSystemCatalog(sessionID); @@ -2439,12 +2317,6 @@ int ha_calpont_impl_rnd_init(TABLE* table) idbassert(ci != 0); - // MySQL sometimes calls rnd_init multiple times, plan should only be - // generated and sent once. - if (thd->infinidb_vtable.vtable_state == THD::INFINIDB_CREATE_VTABLE && - !thd->infinidb_vtable.isNewQuery) - return 0; - if (thd->killed == KILL_QUERY || thd->killed == KILL_QUERY_HARD) { force_close_fep_conn(thd, ci); @@ -2456,24 +2328,12 @@ int ha_calpont_impl_rnd_init(TABLE* table) sm::cpsm_conhdl_t* hndl; SCSEP csep; - // update traceFlags according to the autoswitch state. replication query - // on slave are in table mode (create table as...) - if (thd->infinidb_vtable.vtable_state == THD::INFINIDB_DISABLE_VTABLE || - (thd->slave_thread && thd->infinidb_vtable.vtable_state == THD::INFINIDB_INIT)) - { - ci->traceFlags |= CalpontSelectExecutionPlan::TRACE_TUPLE_OFF; - thd->infinidb_vtable.vtable_state = THD::INFINIDB_DISABLE_VTABLE; - } - else - { - ci->traceFlags = (ci->traceFlags | CalpontSelectExecutionPlan::TRACE_TUPLE_OFF)^ - CalpontSelectExecutionPlan::TRACE_TUPLE_OFF; - } + // update traceFlags according to the autoswitch state. + ci->traceFlags |= CalpontSelectExecutionPlan::TRACE_TUPLE_OFF; bool localQuery = get_local_query(thd); // table mode - if (thd->infinidb_vtable.vtable_state == THD::INFINIDB_DISABLE_VTABLE) { ti = ci->tableMap[table]; @@ -2538,154 +2398,15 @@ int ha_calpont_impl_rnd_init(TABLE* table) // for ExeMgr logging sqltext. only log once for the query although multi plans may be sent if (ci->tableMap.size() == 1) + { ti.csep->data(idb_mysql_query_str(thd)); + } + else + { + ti.csep->data(""); + } } - // vtable mode - else - { - //if (!ci->cal_conn_hndl || thd->infinidb_vtable.vtable_state == THD::INFINIDB_CREATE_VTABLE) - if ( thd->infinidb_vtable.vtable_state == THD::INFINIDB_CREATE_VTABLE) - { - ci->stats.reset(); // reset query stats - ci->stats.setStartTime(); - if (thd->main_security_ctx.user) - { - ci->stats.fUser = thd->main_security_ctx.user; - } - else - { - ci->stats.fUser = ""; - } - if (thd->main_security_ctx.host) - ci->stats.fHost = thd->main_security_ctx.host; - else if (thd->main_security_ctx.host_or_ip) - ci->stats.fHost = thd->main_security_ctx.host_or_ip; - else - ci->stats.fHost = "unknown"; - - try - { - ci->stats.userPriority(ci->stats.fHost, ci->stats.fUser); - } - catch (std::exception& e) - { - string msg = string("Columnstore User Priority - ") + e.what(); - ci->warningMsg = msg; - } - - // if the previous query has error, re-establish the connection - if (ci->queryState != 0) - { - sm::sm_cleanup(ci->cal_conn_hndl); - ci->cal_conn_hndl = 0; - } - } - - sm::sm_init(sessionID, &ci->cal_conn_hndl, localQuery); - idbassert(ci->cal_conn_hndl != 0); - ci->cal_conn_hndl->csc = csc; - idbassert(ci->cal_conn_hndl->exeMgr != 0); - - try - { - ci->cal_conn_hndl->connect(); - } - catch (...) - { - setError(thd, ER_INTERNAL_ERROR, IDBErrorInfo::instance()->errorMsg(ERR_LOST_CONN_EXEMGR)); - CalpontSystemCatalog::removeCalpontSystemCatalog(sessionID); - goto error; - } - - hndl = ci->cal_conn_hndl; - - if (thd->infinidb_vtable.vtable_state != THD::INFINIDB_SELECT_VTABLE) - { - //CalpontSelectExecutionPlan csep; - if (!csep) - csep.reset(new CalpontSelectExecutionPlan()); - - SessionManager sm; - BRM::TxnID txnID; - txnID = sm.getTxnID(sessionID); - - if (!txnID.valid) - { - txnID.id = 0; - txnID.valid = true; - } - - QueryContext verID; - verID = sm.verID(); - - csep->txnID(txnID.id); - csep->verID(verID); - csep->sessionID(sessionID); - - if (thd->db.length) - csep->schemaName(thd->db.str); - - csep->traceFlags(ci->traceFlags); - - if (thd->infinidb_vtable.isInsertSelect) - csep->queryType(CalpontSelectExecutionPlan::INSERT_SELECT); - - //get plan - int status = cp_get_plan(thd, csep); - - //if (cp_get_plan(thd, csep) != 0) - if (status > 0) - goto internal_error; - else if (status < 0) - return 0; - - // @bug 2547. don't need to send the plan if it's impossible where for all unions. - if (thd->infinidb_vtable.impossibleWhereOnUnion) - return 0; - - string query; - query.assign(thd->infinidb_vtable.original_query.ptr(), - thd->infinidb_vtable.original_query.length()); - csep->data(query); - - try - { - csep->priority( ci->stats.userPriority(ci->stats.fHost, ci->stats.fUser)); - } - catch (std::exception& e) - { - string msg = string("Columnstore User Priority - ") + e.what(); - push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 9999, msg.c_str()); - } - -#ifdef PLAN_HEX_FILE - // plan serialization - string tmpDir = aTmpDir + "/li1-plan.hex"; - - ifstream ifs(tmpDir.c_str()); - ByteStream bs1; - ifs >> bs1; - ifs.close(); - csep->unserialize(bs1); -#endif - - if (ci->traceFlags & 1) - { - cerr << "---------------- EXECUTION PLAN ----------------" << endl; - cerr << *csep << endl ; - cerr << "-------------- EXECUTION PLAN END --------------\n" << endl; - } - else - { - IDEBUG( cout << "---------------- EXECUTION PLAN ----------------" << endl ); - IDEBUG( cerr << *csep << endl ); - IDEBUG( cout << "-------------- EXECUTION PLAN END --------------\n" << endl ); - } - } - }// end of execution plan generation - - if (thd->infinidb_vtable.vtable_state != THD::INFINIDB_SELECT_VTABLE) { ByteStream msg; ByteStream emsgBs; @@ -2760,14 +2481,7 @@ int ha_calpont_impl_rnd_init(TABLE* table) ci->rmParms.clear(); - if (thd->infinidb_vtable.vtable_state == THD::INFINIDB_DISABLE_VTABLE) - { - ci->tableMap[table] = ti; - } - else - { - ci->queryState = 1; - } + ci->tableMap[table] = ti; break; } @@ -2780,10 +2494,7 @@ int ha_calpont_impl_rnd_init(TABLE* table) idbassert(hndl != 0); hndl->csc = csc; - if (thd->infinidb_vtable.vtable_state == THD::INFINIDB_DISABLE_VTABLE) - ti.conn_hndl = hndl; - else - ci->cal_conn_hndl = hndl; + ti.conn_hndl = hndl; try { @@ -2801,92 +2512,81 @@ int ha_calpont_impl_rnd_init(TABLE* table) } } - // set query state to be in_process. Sometimes mysql calls rnd_init multiple - // times, this makes sure plan only being generated and sent once. It will be - // reset when query finishes in sm::end_query - thd->infinidb_vtable.isNewQuery = false; - // common path for both vtable select phase and table mode -- open scan handle ti = ci->tableMap[table]; ti.msTablePtr = table; - if ((thd->infinidb_vtable.vtable_state == THD::INFINIDB_SELECT_VTABLE) || - (thd->infinidb_vtable.vtable_state == THD::INFINIDB_DISABLE_VTABLE) || - (thd->infinidb_vtable.vtable_state == THD::INFINIDB_REDO_QUERY)) + if (ti.tpl_ctx == 0) { - if (ti.tpl_ctx == 0) + ti.tpl_ctx = new sm::cpsm_tplh_t(); + ti.tpl_scan_ctx = sm::sp_cpsm_tplsch_t(new sm::cpsm_tplsch_t()); + } + + // make sure rowgroup is null so the new meta data can be taken. This is for some case mysql + // call rnd_init for a table more than once. + ti.tpl_scan_ctx->rowGroup = NULL; + + try + { + tableid = execplan::IDB_VTABLE_ID; + } + catch (...) + { + string emsg = "No table ID found for table " + string(table->s->table_name.str); + setError(thd, ER_INTERNAL_ERROR, emsg); + CalpontSystemCatalog::removeCalpontSystemCatalog(sessionID); + goto internal_error; + } + + try + { + sm::tpl_open(tableid, ti.tpl_ctx, hndl); + sm::tpl_scan_open(tableid, ti.tpl_scan_ctx, hndl); + } + catch (std::exception& e) + { + string emsg = "table can not be opened: " + string(e.what()); + setError(thd, ER_INTERNAL_ERROR, emsg); + CalpontSystemCatalog::removeCalpontSystemCatalog(sessionID); + goto internal_error; + } + catch (...) + { + string emsg = "table can not be opened"; + setError(thd, ER_INTERNAL_ERROR, emsg); + CalpontSystemCatalog::removeCalpontSystemCatalog(sessionID); + goto internal_error; + } + + ti.tpl_scan_ctx->traceFlags = ci->traceFlags; + + if ((ti.tpl_scan_ctx->ctp).size() == 0) + { + uint32_t num_attr = table->s->fields; + + for (uint32_t i = 0; i < num_attr; i++) { - ti.tpl_ctx = new sm::cpsm_tplh_t(); - ti.tpl_scan_ctx = sm::sp_cpsm_tplsch_t(new sm::cpsm_tplsch_t()); + CalpontSystemCatalog::ColType ctype; + ti.tpl_scan_ctx->ctp.push_back(ctype); } - // make sure rowgroup is null so the new meta data can be taken. This is for some case mysql - // call rnd_init for a table more than once. - ti.tpl_scan_ctx->rowGroup = NULL; + // populate coltypes here for table mode because tableband gives treeoid for dictionary column + { + CalpontSystemCatalog::RIDList oidlist = csc->columnRIDs(make_table(table->s->db.str, table->s->table_name.str), true); - try - { - tableid = execplan::IDB_VTABLE_ID; - } - catch (...) - { - string emsg = "No table ID found for table " + string(table->s->table_name.str); - setError(thd, ER_INTERNAL_ERROR, emsg); - CalpontSystemCatalog::removeCalpontSystemCatalog(sessionID); - goto internal_error; - } - - try - { - sm::tpl_open(tableid, ti.tpl_ctx, hndl); - sm::tpl_scan_open(tableid, ti.tpl_scan_ctx, hndl); - } - catch (std::exception& e) - { - string emsg = "table can not be opened: " + string(e.what()); - setError(thd, ER_INTERNAL_ERROR, emsg); - CalpontSystemCatalog::removeCalpontSystemCatalog(sessionID); - goto internal_error; - } - catch (...) - { - string emsg = "table can not be opened"; - setError(thd, ER_INTERNAL_ERROR, emsg); - CalpontSystemCatalog::removeCalpontSystemCatalog(sessionID); - goto internal_error; - } - - ti.tpl_scan_ctx->traceFlags = ci->traceFlags; - - if ((ti.tpl_scan_ctx->ctp).size() == 0) - { - uint32_t num_attr = table->s->fields; - - for (uint32_t i = 0; i < num_attr; i++) + if (oidlist.size() != num_attr) { - CalpontSystemCatalog::ColType ctype; - ti.tpl_scan_ctx->ctp.push_back(ctype); + string emsg = "Size mismatch probably caused by front end out of sync"; + setError(thd, ER_INTERNAL_ERROR, emsg); + CalpontSystemCatalog::removeCalpontSystemCatalog(sessionID); + goto internal_error; } - // populate coltypes here for table mode because tableband gives treeoid for dictionary column - if (thd->infinidb_vtable.vtable_state == THD::INFINIDB_DISABLE_VTABLE) + for (unsigned int j = 0; j < oidlist.size(); j++) { - CalpontSystemCatalog::RIDList oidlist = csc->columnRIDs(make_table(table->s->db.str, table->s->table_name.str), true); - - if (oidlist.size() != num_attr) - { - string emsg = "Size mismatch probably caused by front end out of sync"; - setError(thd, ER_INTERNAL_ERROR, emsg); - CalpontSystemCatalog::removeCalpontSystemCatalog(sessionID); - goto internal_error; - } - - for (unsigned int j = 0; j < oidlist.size(); j++) - { - CalpontSystemCatalog::ColType ctype = csc->colType(oidlist[j].objnum); - ti.tpl_scan_ctx->ctp[ctype.colPosition] = ctype; - ti.tpl_scan_ctx->ctp[ctype.colPosition].colPosition = -1; - } + CalpontSystemCatalog::ColType ctype = csc->colType(oidlist[j].objnum); + ti.tpl_scan_ctx->ctp[ctype.colPosition] = ctype; + ti.tpl_scan_ctx->ctp[ctype.colPosition].colPosition = -1; } } } @@ -2895,14 +2595,14 @@ int ha_calpont_impl_rnd_init(TABLE* table) return 0; error: - + // CS doesn't need to close the actual sockets + // b/c it tries to reuse it running next query. if (ci->cal_conn_hndl) { sm::sm_cleanup(ci->cal_conn_hndl); ci->cal_conn_hndl = 0; } - // do we need to close all connection handle of the table map? return ER_INTERNAL_ERROR; internal_error: @@ -2933,30 +2633,14 @@ int ha_calpont_impl_rnd_next(uchar* buf, TABLE* table) thd->lex->sql_command == SQLCOM_LOAD)) return 0; - if (thd->infinidb_vtable.vtable_state == THD::INFINIDB_ERROR) - return ER_INTERNAL_ERROR; - - // @bug 3005 - if (thd->infinidb_vtable.vtable_state == THD::INFINIDB_SELECT_VTABLE && - string(table->s->table_name.str).find("$vtable") != 0) - return HA_ERR_END_OF_FILE; - if (((thd->lex)->sql_command == SQLCOM_UPDATE) || ((thd->lex)->sql_command == SQLCOM_DELETE) || ((thd->lex)->sql_command == SQLCOM_DELETE_MULTI) || ((thd->lex)->sql_command == SQLCOM_UPDATE_MULTI)) return HA_ERR_END_OF_FILE; // @bug 2547 - if (thd->infinidb_vtable.impossibleWhereOnUnion) - return HA_ERR_END_OF_FILE; - - // @bug 2232. Basic SP support - // @bug 3939. Only error out for sp with select. Let pass for alter table in sp. - if (thd->infinidb_vtable.call_sp && (thd->lex)->sql_command != SQLCOM_ALTER_TABLE) - { - setError(thd, ER_CHECK_NOT_IMPLEMENTED, "This stored procedure syntax is not supported by Columnstore in this version"); - thd->infinidb_vtable.vtable_state = THD::INFINIDB_ERROR; - return ER_INTERNAL_ERROR; - } + // MCOL-2178 This variable can never be true in the scope of this function + // if (MIGR::infinidb_vtable.impossibleWhereOnUnion) + // return HA_ERR_END_OF_FILE; if (get_fe_conn_info_ptr() == NULL) set_fe_conn_info_ptr((void*)new cal_connection_info()); @@ -3019,15 +2703,15 @@ int ha_calpont_impl_rnd_next(uchar* buf, TABLE* table) return rc; } -int ha_calpont_impl_rnd_end(TABLE* table) +int ha_calpont_impl_rnd_end(TABLE* table, bool is_pushdown_hand) { int rc = 0; THD* thd = current_thd; cal_connection_info* ci = NULL; bool replicationEnabled = false; - if (thd->infinidb_vtable.cal_conn_info) - ci = reinterpret_cast(thd->infinidb_vtable.cal_conn_info); + if (get_fe_conn_info_ptr() != NULL) + ci = reinterpret_cast(get_fe_conn_info_ptr()); if (ci && ci->replicationEnabled) { @@ -3045,19 +2729,15 @@ int ha_calpont_impl_rnd_end(TABLE* table) thd->lex->sql_command == SQLCOM_LOAD)) return 0; - thd->infinidb_vtable.isNewQuery = true; + + // MCOL-2178 isUnion member only assigned, never used + // if (is_pushdown_hand) + // { + // MIGR::infinidb_vtable.isUnion = false; + // } if (get_fe_conn_info_ptr() != NULL) ci = reinterpret_cast(get_fe_conn_info_ptr()); - if (thd->infinidb_vtable.vtable_state == THD::INFINIDB_ORDER_BY ) - { - thd->infinidb_vtable.vtable_state = THD::INFINIDB_SELECT_VTABLE; // flip back to normal state - return rc; - } - -// if (thd->infinidb_vtable.vtable_state == THD::INFINIDB_REDO_PHASE1) -// return rc; - if ( (thd->lex)->sql_command == SQLCOM_ALTER_TABLE ) return rc; @@ -3096,7 +2776,7 @@ int ha_calpont_impl_rnd_end(TABLE* table) cal_table_info ti = ci->tableMap[table]; sm::cpsm_conhdl_t* hndl; - if (thd->infinidb_vtable.vtable_state == THD::INFINIDB_DISABLE_VTABLE) + if (!is_pushdown_hand) hndl = ti.conn_hndl; else hndl = ci->cal_conn_hndl; @@ -3119,10 +2799,13 @@ int ha_calpont_impl_rnd_end(TABLE* table) try { - sm::tpl_close(ti.tpl_ctx, &hndl, ci->stats); + { + bool ask_4_stats = (ci->traceFlags) ? true : false; + sm::tpl_close(ti.tpl_ctx, &hndl, ci->stats, ask_4_stats); + } // set conn hndl back. could be changed in tpl_close - if (thd->infinidb_vtable.vtable_state == THD::INFINIDB_DISABLE_VTABLE) + if (!is_pushdown_hand) ti.conn_hndl = hndl; else ci->cal_conn_hndl = hndl; @@ -3156,10 +2839,6 @@ int ha_calpont_impl_rnd_end(TABLE* table) ti.tpl_ctx = 0; - if (thd->infinidb_vtable.vtable_state == THD::INFINIDB_SELECT_VTABLE && - thd->infinidb_vtable.has_order_by) - thd->infinidb_vtable.vtable_state = THD::INFINIDB_ORDER_BY; - ci->tableMap[table] = ti; // push warnings from CREATE phase @@ -3170,6 +2849,8 @@ int ha_calpont_impl_rnd_end(TABLE* table) // reset expressionId just in case ci->expressionId = 0; + thd_set_ha_data(thd, mcs_hton, reinterpret_cast(ci)); + return rc; } @@ -3182,11 +2863,6 @@ int ha_calpont_impl_create(const char* name, TABLE* table_arg, HA_CREATE_INFO* c cal_connection_info* ci = reinterpret_cast(get_fe_conn_info_ptr()); - // @bug1940 Do nothing for select query. Support of set default engine to IDB. - if (thd->infinidb_vtable.vtable_state == THD::INFINIDB_CREATE_VTABLE || - string(name).find("@0024vtable") != string::npos) - return 0; - //@Bug 1948. Mysql calls create table to create a new table with new signature. if (ci->alterTableState > 0) return 0; @@ -3222,10 +2898,6 @@ int ha_calpont_impl_delete_table(const char* name) //if this is an InfiniDB tmp table ('#sql*.frm') just leave... if (!memcmp((uchar*)name, tmp_file_prefix, tmp_file_prefix_length)) return 0; - // @bug1940 Do nothing for select query. Support of set default engine to IDB. - if (string(name).find("@0024vtable") != string::npos) - return 0; - if (get_fe_conn_info_ptr() == NULL) set_fe_conn_info_ptr((void*)new cal_connection_info()); @@ -3243,7 +2915,7 @@ int ha_calpont_impl_delete_table(const char* name) } else { - TABLE_LIST* first_table = (TABLE_LIST*) thd->lex->select_lex.table_list.first; + TABLE_LIST* first_table = (TABLE_LIST*) thd->lex->first_select_lex()->table_list.first; dbName = const_cast(first_table->db.str); } @@ -3262,26 +2934,10 @@ int ha_calpont_impl_delete_table(const char* name) return 0; } - // @bug 1793. make vtable droppable in calpontsys. "$vtable" ==> "@0024vtable" passed in as name. - if (strcmp(dbName, "calpontsys") == 0 && string(name).find("@0024vtable") == string::npos) - { - std::string stmt(idb_mysql_query_str(thd)); - boost::algorithm::to_upper(stmt); - - //@Bug 2432. systables can be dropped with restrict - if (stmt.find(" RESTRICT") != string::npos) - { - return 0; - } - - setError(thd, ER_INTERNAL_ERROR, "Calpont system tables can only be dropped with restrict."); - return 1; - } - int rc = ha_calpont_impl_delete_table_(dbName, name, *ci); return rc; } -int ha_calpont_impl_write_row(uchar* buf, TABLE* table) +int ha_calpont_impl_write_row(const uchar* buf, TABLE* table) { THD* thd = current_thd; //sleep(100); @@ -3384,14 +3040,11 @@ void ha_calpont_impl_start_bulk_insert(ha_rows rows, TABLE* table) if (ci->alterTableState > 0) return; - if (thd->infinidb_vtable.vtable_state != THD::INFINIDB_ALTER_VTABLE) - thd->infinidb_vtable.isInfiniDBDML = true; - if (thd->slave_thread && !ci->replicationEnabled) return; //@bug 5660. Error out DDL/DML on slave node, or on local query node - if (ci->isSlaveNode && thd->infinidb_vtable.vtable_state != THD::INFINIDB_ALTER_VTABLE) + if (ci->isSlaveNode) { string emsg = logging::IDBErrorInfo::instance()->errorMsg(ERR_DML_DDL_SLAVE); setError(current_thd, ER_CHECK_NOT_IMPLEMENTED, emsg); @@ -4159,12 +3812,6 @@ int ha_calpont_impl_end_bulk_insert(bool abort, TABLE* table) int ha_calpont_impl_commit (handlerton* hton, THD* thd, bool all) { - if (thd->infinidb_vtable.vtable_state == THD::INFINIDB_CREATE_VTABLE || - thd->infinidb_vtable.vtable_state == THD::INFINIDB_ALTER_VTABLE || - thd->infinidb_vtable.vtable_state == THD::INFINIDB_DROP_VTABLE || - thd->infinidb_vtable.vtable_state == THD::INFINIDB_REDO_PHASE1) - return 0; - if (get_fe_conn_info_ptr() == NULL) set_fe_conn_info_ptr((void*)new cal_connection_info()); @@ -4197,15 +3844,6 @@ int ha_calpont_impl_commit (handlerton* hton, THD* thd, bool all) int ha_calpont_impl_rollback (handlerton* hton, THD* thd, bool all) { - // @bug 1738. no need to rollback for select. This is to avoid concurrent session - // conflict because DML is not thread safe. - //comment out for bug 3874. Select should never come to rollback. If there is no active transaction, - //rollback in DMLProc is not doing anything anyway - //if (!(current_thd->variables.option_bits & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) - //{ - // return 0; - //} - if (get_fe_conn_info_ptr() == NULL) set_fe_conn_info_ptr((void*)new cal_connection_info()); @@ -4215,7 +3853,6 @@ int ha_calpont_impl_rollback (handlerton* hton, THD* thd, bool all) { ci->dmlProc = new MessageQueueClient("DMLProc"); - //cout << "rollback starts a client " << ci->dmlProc << " for session " << thd->thread_id << endl; } int rc = ha_calpont_impl_rollback_(hton, thd, all, *ci); @@ -4242,7 +3879,7 @@ int ha_calpont_impl_close_connection (handlerton* hton, THD* thd) // An ugly way. I will use ha_data w/o external_lock. // This in MCOL-2178 cal_connection_info* ci = NULL; - if(thd_get_ha_data(thd, hton)) + if(thd_get_ha_data(thd, hton) != (void*)0x42) // 0x42 is the magic CS sets when setup hton { ci = reinterpret_cast(thd_get_ha_data(thd, hton)); } @@ -4264,13 +3901,14 @@ int ha_calpont_impl_close_connection (handlerton* hton, THD* thd) ci->cal_conn_hndl = 0; } + thd_set_ha_data(thd, hton, NULL); + return rc; } int ha_calpont_impl_rename_table(const char* from, const char* to) { IDEBUG( cout << "ha_calpont_impl_rename_table: " << from << " => " << to << endl ); - THD* thd = current_thd; if (get_fe_conn_info_ptr() == NULL) set_fe_conn_info_ptr((void*)new cal_connection_info()); @@ -4290,8 +3928,6 @@ int ha_calpont_impl_rename_table(const char* from, const char* to) IDEBUG( cout << "ha_calpont_impl_rename_table: was in state ALTER_SECOND_RENAME, now in NOT_ALTER" << endl ); return 0; } - else if ( thd->infinidb_vtable.vtable_state == THD::INFINIDB_ALTER_VTABLE ) - return 0; int rc = ha_calpont_impl_rename_table_(from, to, *ci); return rc; @@ -4307,12 +3943,6 @@ COND* ha_calpont_impl_cond_push(COND* cond, TABLE* table) { THD* thd = current_thd; - if (thd->slave_thread && thd->infinidb_vtable.vtable_state == THD::INFINIDB_INIT) - thd->infinidb_vtable.vtable_state = THD::INFINIDB_DISABLE_VTABLE; - - if (thd->infinidb_vtable.vtable_state != THD::INFINIDB_DISABLE_VTABLE) - return cond; - if (((thd->lex)->sql_command == SQLCOM_UPDATE) || ((thd->lex)->sql_command == SQLCOM_UPDATE_MULTI) || ((thd->lex)->sql_command == SQLCOM_DELETE) || @@ -4397,12 +4027,6 @@ int ha_calpont_impl_external_lock(THD* thd, TABLE* table, int lock_type) string alias; alias.assign(table->alias.ptr(), table->alias.length()); IDEBUG( cout << "external_lock for " << alias << endl ); - idbassert((thd->infinidb_vtable.vtable_state >= THD::INFINIDB_INIT_CONNECT && - thd->infinidb_vtable.vtable_state <= THD::INFINIDB_REDO_QUERY) || - thd->infinidb_vtable.vtable_state == THD::INFINIDB_ERROR); - - if ( thd->infinidb_vtable.vtable_state == THD::INFINIDB_INIT ) - return 0; if (get_fe_conn_info_ptr() == NULL) set_fe_conn_info_ptr((void*)new cal_connection_info()); @@ -4411,51 +4035,56 @@ int ha_calpont_impl_external_lock(THD* thd, TABLE* table, int lock_type) if (thd->killed == KILL_QUERY || thd->killed == KILL_QUERY_HARD) { + ci->physTablesList.clear(); + ci->tableMap.clear(); force_close_fep_conn(thd, ci); return 0; } - CalTableMap::iterator mapiter = ci->tableMap.find(table); -#ifdef _MSC_VER - //FIXME: fix this! (must be related to F_UNLCK define in winport) - if (mapiter != ci->tableMap.end() && lock_type == 0) // make sure it's the release lock (2nd) call -#else + CalTableMap::iterator mapiter = ci->tableMap.find(table); if (mapiter != ci->tableMap.end() && lock_type == 2) // make sure it's the release lock (2nd) call -#endif { // table mode - if (thd->infinidb_vtable.vtable_state == THD::INFINIDB_DISABLE_VTABLE) + if (mapiter->second.conn_hndl) { - if (mapiter->second.conn_hndl) - { - if (ci->traceFlags & 1) - push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, 9999, mapiter->second.conn_hndl->queryStats.c_str()); + if (ci->traceFlags & 1) + push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, 9999, mapiter->second.conn_hndl->queryStats.c_str()); - ci->queryStats = mapiter->second.conn_hndl->queryStats; - ci->extendedStats = mapiter->second.conn_hndl->extendedStats; - ci->miniStats = mapiter->second.conn_hndl->miniStats; - sm::sm_cleanup(mapiter->second.conn_hndl); - mapiter->second.conn_hndl = 0; - } - - if (mapiter->second.condInfo) - { - delete mapiter->second.condInfo; - mapiter->second.condInfo = 0; - } - - // only push this warning for once - if (ci->tableMap.size() == 1 && - thd->infinidb_vtable.vtable_state == THD::INFINIDB_DISABLE_VTABLE && thd->infinidb_vtable.autoswitch) - { - push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 9999, infinidb_autoswitch_warning.c_str()); - } - ci->queryState = 0; + ci->queryStats = mapiter->second.conn_hndl->queryStats; + ci->extendedStats = mapiter->second.conn_hndl->extendedStats; + ci->miniStats = mapiter->second.conn_hndl->miniStats; + sm::sm_cleanup(mapiter->second.conn_hndl); + mapiter->second.conn_hndl = 0; } - else // vtable mode + + if (mapiter->second.condInfo) { - if (thd->infinidb_vtable.vtable_state == THD::INFINIDB_SELECT_VTABLE) + delete mapiter->second.condInfo; + mapiter->second.condInfo = 0; + } + + // MCOL-2178 Check for tableMap size to set this only once. + ci->queryState = 0; + ci->tableMap.erase(table); + } + else + { + if (lock_type == 0) + { + ci->physTablesList.insert(table); + // MCOL-2178 Disable Conversion of Big IN Predicates Into Subqueries + thd->variables.in_subquery_conversion_threshold=~0; + } + else if (lock_type == 2) + { + std::set::iterator iter = ci->physTablesList.find(table); + if ( iter != ci->physTablesList.end() ) + { + ci->physTablesList.erase(table); + } + + if ( iter != ci->physTablesList.end() && ci->physTablesList.empty() ) { if (!ci->cal_conn_hndl) return 0; @@ -4467,14 +4096,16 @@ int ha_calpont_impl_external_lock(THD* thd, TABLE* table, int lock_type) ci->extendedStats = ci->cal_conn_hndl->extendedStats; ci->miniStats = ci->cal_conn_hndl->miniStats; ci->queryState = 0; - thd->infinidb_vtable.override_largeside_estimate = false; // MCOL-3247 Use THD::ha_data as a per-plugin per-session - // storage for cal_conn_hndl to use it later in close_connection - thd_set_ha_data(thd, calpont_hton, get_fe_conn_info_ptr()); + // storage for cal_conn_hndl to use it later in close_connection + thd_set_ha_data(thd, mcs_hton, get_fe_conn_info_ptr()); + ci->tableMap.clear(); + // MCOL-2178 Enable Conversion of Big IN Predicates Into Subqueries + thd->variables.in_subquery_conversion_threshold = IN_SUBQUERY_CONVERSION_THRESHOLD; + restore_optimizer_flags(thd); } - } - ci->tableMap.erase(table); + } } return 0; @@ -4516,38 +4147,16 @@ int ha_calpont_impl_group_by_init(ha_calpont_group_by_handler* group_hand, TABLE { // Still not ready setError(thd, ER_INTERNAL_ERROR, "The system is not yet ready to accept queries"); - thd->infinidb_vtable.vtable_state = THD::INFINIDB_ERROR; return ER_INTERNAL_ERROR; } else if (bSystemQueryReady < 0) { // Still not ready setError(thd, ER_INTERNAL_ERROR, "DBRM is not responding. Cannot accept queries"); - thd->infinidb_vtable.vtable_state = THD::INFINIDB_ERROR; return ER_INTERNAL_ERROR; } #endif - // prevent "create table as select" from running on slave - thd->infinidb_vtable.hasInfiniDBTable = true; - - // return error if error status has been already set - if (thd->infinidb_vtable.vtable_state == THD::INFINIDB_ERROR) - return ER_INTERNAL_ERROR; - - // MCOL-1052 - // by pass the extra union trips. return 0 - //if (thd->infinidb_vtable.isUnion && thd->infinidb_vtable.vtable_state == THD::INFINIDB_CREATE_VTABLE) - // return 0; - - // @bug 2232. Basic SP support. Error out non support sp cases. - // @bug 3939. Only error out for sp with select. Let pass for alter table in sp. - if (thd->infinidb_vtable.call_sp && (thd->lex)->sql_command != SQLCOM_ALTER_TABLE) - { - setError(thd, ER_CHECK_NOT_IMPLEMENTED, "This stored procedure syntax is not supported by Columnstore in this version"); - thd->infinidb_vtable.vtable_state = THD::INFINIDB_ERROR; - return ER_INTERNAL_ERROR; - } uint32_t sessionID = tid2sid(thd->thread_id); boost::shared_ptr csc = CalpontSystemCatalog::makeCalpontSystemCatalog(sessionID); @@ -4561,12 +4170,6 @@ int ha_calpont_impl_group_by_init(ha_calpont_group_by_handler* group_hand, TABLE idbassert(ci != 0); - // MySQL sometimes calls rnd_init multiple times, plan should only be - // generated and sent once. - if (thd->infinidb_vtable.vtable_state == THD::INFINIDB_DISABLE_VTABLE && - !thd->infinidb_vtable.isNewQuery) - return 0; - if (thd->killed == KILL_QUERY || thd->killed == KILL_QUERY_HARD) { force_close_fep_conn(thd, ci); @@ -4700,14 +4303,16 @@ int ha_calpont_impl_group_by_init(ha_calpont_group_by_handler* group_hand, TABLE // send plan whenever group_init is called int status = cp_get_group_plan(thd, csep, gi); - if (status > 0) + // Never proceed if status != 0 to avoid empty DA + // crashes on later stages + if (status != 0) goto internal_error; - else if (status < 0) - return 0; // @bug 2547. don't need to send the plan if it's impossible where for all unions. - if (thd->infinidb_vtable.impossibleWhereOnUnion) - return 0; + // MCOL-2178 commenting the below out since cp_get_group_plan does not modify this variable + // which has a default value of false + //if (MIGR::infinidb_vtable.impossibleWhereOnUnion) + // return 0; string query; // Set the query text only once if the server executes @@ -4827,14 +4432,7 @@ int ha_calpont_impl_group_by_init(ha_calpont_group_by_handler* group_hand, TABLE ci->rmParms.clear(); - if (thd->infinidb_vtable.vtable_state == THD::INFINIDB_DISABLE_VTABLE) - { - ci->tableMap[table] = ti; - } - else - { - ci->queryState = 1; - } + ci->queryState = 1; break; } @@ -4847,15 +4445,9 @@ int ha_calpont_impl_group_by_init(ha_calpont_group_by_handler* group_hand, TABLE idbassert(hndl != 0); hndl->csc = csc; - // The next section is useless - if (thd->infinidb_vtable.vtable_state == THD::INFINIDB_DISABLE_VTABLE) - ti.conn_hndl = hndl; - else - { - ci->cal_conn_hndl = hndl; - ci->cal_conn_hndl_st.pop(); - ci->cal_conn_hndl_st.push(ci->cal_conn_hndl); - } + ci->cal_conn_hndl = hndl; + ci->cal_conn_hndl_st.pop(); + ci->cal_conn_hndl_st.push(ci->cal_conn_hndl); try { hndl->connect(); @@ -4875,18 +4467,11 @@ int ha_calpont_impl_group_by_init(ha_calpont_group_by_handler* group_hand, TABLE // set query state to be in_process. Sometimes mysql calls rnd_init multiple // times, this makes sure plan only being generated and sent once. It will be // reset when query finishes in sm::end_query - thd->infinidb_vtable.isNewQuery = false; // common path for both vtable select phase and table mode -- open scan handle ti = ci->tableMap[table]; ti.msTablePtr = table; - // MCOL-1052 - thd->infinidb_vtable.vtable_state = THD::INFINIDB_SELECT_VTABLE; - - if ((thd->infinidb_vtable.vtable_state == THD::INFINIDB_SELECT_VTABLE) || - (thd->infinidb_vtable.vtable_state == THD::INFINIDB_DISABLE_VTABLE) || - (thd->infinidb_vtable.vtable_state == THD::INFINIDB_REDO_QUERY)) { // MCOL-1601 Using stacks of ExeMgr conn hndls, table and scan contexts. ti.tpl_ctx = new sm::cpsm_tplh_t(); @@ -4941,27 +4526,6 @@ int ha_calpont_impl_group_by_init(ha_calpont_group_by_handler* group_hand, TABLE CalpontSystemCatalog::ColType ctype; ti.tpl_scan_ctx->ctp.push_back(ctype); } - - // populate coltypes here for table mode because tableband gives treeoid for dictionary column - if (thd->infinidb_vtable.vtable_state == THD::INFINIDB_DISABLE_VTABLE) - { - CalpontSystemCatalog::RIDList oidlist = csc->columnRIDs(make_table(table->s->db.str, table->s->table_name.str), true); - - if (oidlist.size() != num_attr) - { - string emsg = "Size mismatch probably caused by front end out of sync"; - setError(thd, ER_INTERNAL_ERROR, emsg); - CalpontSystemCatalog::removeCalpontSystemCatalog(sessionID); - goto internal_error; - } - - for (unsigned int j = 0; j < oidlist.size(); j++) - { - CalpontSystemCatalog::ColType ctype = csc->colType(oidlist[j].objnum); - ti.tpl_scan_ctx->ctp[ctype.colPosition] = ctype; - ti.tpl_scan_ctx->ctp[ctype.colPosition].colPosition = -1; - } - } } } @@ -5010,26 +4574,15 @@ int ha_calpont_impl_group_by_next(ha_calpont_group_by_handler* group_hand, TABLE { THD* thd = current_thd; - if (thd->infinidb_vtable.vtable_state == THD::INFINIDB_ERROR) - return ER_INTERNAL_ERROR; - if (((thd->lex)->sql_command == SQLCOM_UPDATE) || ((thd->lex)->sql_command == SQLCOM_DELETE) || ((thd->lex)->sql_command == SQLCOM_DELETE_MULTI) || ((thd->lex)->sql_command == SQLCOM_UPDATE_MULTI)) return HA_ERR_END_OF_FILE; // @bug 2547 - if (thd->infinidb_vtable.impossibleWhereOnUnion) - return HA_ERR_END_OF_FILE; + // MCOL-2178 + // if (MIGR::infinidb_vtable.impossibleWhereOnUnion) + // return HA_ERR_END_OF_FILE; - // @bug 2232. Basic SP support - // @bug 3939. Only error out for sp with select. Let pass for alter table in sp. - /*if (thd->infinidb_vtable.call_sp && (thd->lex)->sql_command != SQLCOM_ALTER_TABLE) - { - setError(thd, ER_CHECK_NOT_IMPLEMENTED, "This stored procedure syntax is not supported by Columnstore in this version"); - thd->infinidb_vtable.vtable_state = THD::INFINIDB_ERROR; - return ER_INTERNAL_ERROR; - } - */ if (get_fe_conn_info_ptr() == NULL) set_fe_conn_info_ptr((void*)new cal_connection_info()); @@ -5111,18 +4664,6 @@ int ha_calpont_impl_group_by_end(ha_calpont_group_by_handler* group_hand, TABLE* THD* thd = current_thd; cal_connection_info* ci = NULL; - thd->infinidb_vtable.isNewQuery = true; - thd->infinidb_vtable.isUnion = false; - - if (get_fe_conn_info_ptr() != NULL) - ci = reinterpret_cast(get_fe_conn_info_ptr()); - - if (!ci) - { - thd->infinidb_vtable.cal_conn_info = (void*)(new cal_connection_info()); - ci = reinterpret_cast(thd->infinidb_vtable.cal_conn_info); - } - if (thd->slave_thread && !ci->replicationEnabled && ( thd->lex->sql_command == SQLCOM_INSERT || thd->lex->sql_command == SQLCOM_INSERT_SELECT || @@ -5134,7 +4675,13 @@ int ha_calpont_impl_group_by_end(ha_calpont_group_by_handler* group_hand, TABLE* thd->lex->sql_command == SQLCOM_LOAD)) return 0; - if (((thd->lex)->sql_command == SQLCOM_INSERT) || + // MCOL-2178 isUnion member only assigned, never used + // MIGR::infinidb_vtable.isUnion = false; + + if (get_fe_conn_info_ptr() != NULL) + ci = reinterpret_cast(get_fe_conn_info_ptr()); + + if (((thd->lex)->sql_command == SQLCOM_INSERT) || ((thd->lex)->sql_command == SQLCOM_INSERT_SELECT) ) { force_close_fep_conn(thd, ci, true); // with checking prev command rc @@ -5202,7 +4749,10 @@ int ha_calpont_impl_group_by_end(ha_calpont_group_by_handler* group_hand, TABLE* { if(hndl) { - sm::tpl_close(ti.tpl_ctx, &hndl, ci->stats, clearScanCtx); + { + bool ask_4_stats = (ci->traceFlags) ? true : false; + sm::tpl_close(ti.tpl_ctx, &hndl, ci->stats, ask_4_stats, clearScanCtx); + } // Normaly stats variables are set in external_lock method but we set it here // since they we pretend we are in vtable_disabled mode and the stats vars won't be set. // We sum the stats up here since server could run a number of @@ -5275,4 +4825,450 @@ int ha_calpont_impl_group_by_end(ha_calpont_group_by_handler* group_hand, TABLE* return rc; } + +/*@brief Initiate the query for derived_handler */ +/*********************************************************** + * DESCRIPTION: + * Execute the query and saves derived table query. + * There is an extra handler argument so I ended up with a + * new init function. The code is a copy of + * ha_calpont_impl_rnd_init() mostly. + * PARAMETERS: + * mcs_handler_info* pnt to an envelope struct + * TABLE* table - dest table to put the results into + * RETURN: + * rc as int + ***********************************************************/ +int ha_cs_impl_pushdown_init(mcs_handler_info* handler_info, TABLE* table) +{ + IDEBUG( cout << "pushdown_init for table " << endl ); + THD* thd = current_thd; + + gp_walk_info gwi; + gwi.thd = thd; + + //check whether the system is ready to process statement. +#ifndef _MSC_VER + static DBRM dbrm(true); + int bSystemQueryReady = dbrm.getSystemQueryReady(); + + if (bSystemQueryReady == 0) + { + // Still not ready + setError(thd, ER_INTERNAL_ERROR, "The system is not yet ready to accept queries"); + return ER_INTERNAL_ERROR; + } + else if (bSystemQueryReady < 0) + { + // Still not ready + setError(thd, ER_INTERNAL_ERROR, "DBRM is not responding. Cannot accept queries"); + return ER_INTERNAL_ERROR; + } +#endif + + // Set this to close all outstanding FEP connections on + // client disconnect in handlerton::closecon_handlerton(). + if ( !thd_get_ha_data(thd, mcs_hton)) + { + thd_set_ha_data(thd, mcs_hton, reinterpret_cast(0x42)); + } + + if ( (thd->lex)->sql_command == SQLCOM_ALTER_TABLE ) + { + return 0; + } + + //Update and delete code + if ( ((thd->lex)->sql_command == SQLCOM_UPDATE) || ((thd->lex)->sql_command == SQLCOM_DELETE) || ((thd->lex)->sql_command == SQLCOM_DELETE_MULTI) || ((thd->lex)->sql_command == SQLCOM_UPDATE_MULTI)) + return doUpdateDelete(thd, gwi); + + uint32_t sessionID = tid2sid(thd->thread_id); + boost::shared_ptr csc = CalpontSystemCatalog::makeCalpontSystemCatalog(sessionID); + csc->identity(CalpontSystemCatalog::FE); + + if (!get_fe_conn_info_ptr()) + set_fe_conn_info_ptr(reinterpret_cast(new cal_connection_info(), thd)); + + cal_connection_info* ci = reinterpret_cast(get_fe_conn_info_ptr()); + + idbassert(ci != 0); + + if (thd->killed == KILL_QUERY || thd->killed == KILL_QUERY_HARD) + { + if (ci->cal_conn_hndl) + { + // send ExeMgr a signal before closing the connection + ByteStream msg; + ByteStream::quadbyte qb = 0; + msg << qb; + + try + { + ci->cal_conn_hndl->exeMgr->write(msg); + } + catch (...) + { + // canceling query. ignore connection failure. + } + + sm::sm_cleanup(ci->cal_conn_hndl); + ci->cal_conn_hndl = 0; + } + + return 0; + } + + sm::tableid_t tableid = 0; + cal_table_info ti; + sm::cpsm_conhdl_t* hndl; + SCSEP csep; + // Declare handlers ptrs in this scope for future use. + select_handler* sh = NULL; + derived_handler* dh = NULL; + + // update traceFlags according to the autoswitch state. + ci->traceFlags = (ci->traceFlags | CalpontSelectExecutionPlan::TRACE_TUPLE_OFF)^ + CalpontSelectExecutionPlan::TRACE_TUPLE_OFF; + + bool localQuery = (get_local_query(thd) > 0 ? true : false); + + { + ci->stats.reset(); // reset query stats + ci->stats.setStartTime(); + ci->stats.fUser = thd->main_security_ctx.user; + + if (thd->main_security_ctx.host) + ci->stats.fHost = thd->main_security_ctx.host; + else if (thd->main_security_ctx.host_or_ip) + ci->stats.fHost = thd->main_security_ctx.host_or_ip; + else + ci->stats.fHost = "unknown"; + + try + { + ci->stats.userPriority(ci->stats.fHost, ci->stats.fUser); + } + catch (std::exception& e) + { + string msg = string("Columnstore User Priority - ") + e.what(); + ci->warningMsg = msg; + } + + // if the previous query has error, re-establish the connection + if (ci->queryState != 0) + { + sm::sm_cleanup(ci->cal_conn_hndl); + ci->cal_conn_hndl = 0; + } + + sm::sm_init(sessionID, &ci->cal_conn_hndl, localQuery); + idbassert(ci->cal_conn_hndl != 0); + ci->cal_conn_hndl->csc = csc; + idbassert(ci->cal_conn_hndl->exeMgr != 0); + + try + { + ci->cal_conn_hndl->connect(); + } + catch (...) + { + setError(thd, ER_INTERNAL_ERROR, IDBErrorInfo::instance()->errorMsg(ERR_LOST_CONN_EXEMGR)); + CalpontSystemCatalog::removeCalpontSystemCatalog(sessionID); + goto error; + } + + hndl = ci->cal_conn_hndl; + + IDEBUG( std::cout << idb_mysql_query_str(thd) << std::endl ); + + { + if (!csep) + csep.reset(new CalpontSelectExecutionPlan()); + + SessionManager sm; + BRM::TxnID txnID; + txnID = sm.getTxnID(sessionID); + + if (!txnID.valid) + { + txnID.id = 0; + txnID.valid = true; + } + + QueryContext verID; + verID = sm.verID(); + + csep->txnID(txnID.id); + csep->verID(verID); + csep->sessionID(sessionID); + + if (thd->db.length) + csep->schemaName(thd->db.str); + + csep->traceFlags(ci->traceFlags); + + // cast the handler and get a plan. + int status = 42; + if (handler_info->hndl_type == mcs_handler_types_t::SELECT) + { + sh = reinterpret_cast(handler_info->hndl_ptr); + status = cs_get_select_plan(sh, thd, csep, gwi); + } + else if (handler_info->hndl_type == DERIVED) + { + dh = reinterpret_cast(handler_info->hndl_ptr); + status = cs_get_derived_plan(dh, thd, csep, gwi); + } + + // Return an error to avoid MDB crash later in end_statement + if (status != 0) + goto internal_error; + + // @bug 2547. don't need to send the plan if it's impossible where for all unions. + if (gwi.cs_vtable_impossible_where_on_union) + { + return 0; + } + + string query; + query.assign(idb_mysql_query_str(thd)); + csep->data(query); + + try + { + csep->priority( ci->stats.userPriority(ci->stats.fHost, ci->stats.fUser)); + } + catch (std::exception& e) + { + string msg = string("Columnstore User Priority - ") + e.what(); + push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 9999, msg.c_str()); + } + +// DRRTUY Make this runtime configureable +#ifdef PLAN_HEX_FILE + // plan serialization + ifstream ifs("/tmp/li1-plan.hex"); + ByteStream bs1; + ifs >> bs1; + ifs.close(); + csep->unserialize(bs1); +#endif + + if (ci->traceFlags & 1) + { + cerr << "---------------- EXECUTION PLAN ----------------" << endl; + cerr << *csep << endl ; + cerr << "-------------- EXECUTION PLAN END --------------\n" << endl; + } + else + { + IDEBUG( cout << "---------------- EXECUTION PLAN ----------------" << endl ); + IDEBUG( cerr << *csep << endl ); + IDEBUG( cout << "-------------- EXECUTION PLAN END --------------\n" << endl ); + } + } + }// end of execution plan generation + + { + ByteStream msg; + ByteStream emsgBs; + + while (true) + { + try + { + ByteStream::quadbyte qb = 4; + msg << qb; + hndl->exeMgr->write(msg); + msg.restart(); + csep->rmParms(ci->rmParms); + + //send plan + csep->serialize(msg); + hndl->exeMgr->write(msg); + + //get ExeMgr status back to indicate a vtable joblist success or not + msg.restart(); + emsgBs.restart(); + msg = hndl->exeMgr->read(); + emsgBs = hndl->exeMgr->read(); + string emsg; + + if (msg.length() == 0 || emsgBs.length() == 0) + { + emsg = "Lost connection to ExeMgr. Please contact your administrator"; + setError(thd, ER_INTERNAL_ERROR, emsg); + return ER_INTERNAL_ERROR; + } + + string emsgStr; + emsgBs >> emsgStr; + bool err = false; + + if (msg.length() == 4) + { + msg >> qb; + + if (qb != 0) + { + err = true; + // for makejoblist error, stats contains only error code and insert from here + // because table fetch is not started + ci->stats.setEndTime(); + ci->stats.fQuery = csep->data(); + ci->stats.fQueryType = csep->queryType(); + ci->stats.fErrorNo = qb; + + try + { + ci->stats.insert(); + } + catch (std::exception& e) + { + string msg = string("Columnstore Query Stats - ") + e.what(); + push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 9999, msg.c_str()); + } + } + } + else + { + err = true; + } + + if (err) + { + setError(thd, ER_INTERNAL_ERROR, emsgStr); + return ER_INTERNAL_ERROR; + } + + ci->rmParms.clear(); + + ci->queryState = 1; + + break; + } + catch (...) + { + sm::sm_cleanup(hndl); + hndl = 0; + + sm::sm_init(sessionID, &hndl, localQuery); + idbassert(hndl != 0); + hndl->csc = csc; + + ci->cal_conn_hndl = hndl; + + try + { + hndl->connect(); + } + catch (...) + { + setError(thd, ER_INTERNAL_ERROR, IDBErrorInfo::instance()->errorMsg(ERR_LOST_CONN_EXEMGR)); + CalpontSystemCatalog::removeCalpontSystemCatalog(sessionID); + goto error; + } + + msg.restart(); + } + } + } + + // set query state to be in_process. Sometimes mysql calls rnd_init multiple + // times, this makes sure plan only being generated and sent once. It will be + // reset when query finishes in sm::end_query + + // common path for both vtable select phase and table mode -- open scan handle + ti = ci->tableMap[table]; + // This is the server's temp table for the result. + if(sh) + { + ti.msTablePtr = sh->table; + } + else + { + ti.msTablePtr = dh->table; + } + + { + if (ti.tpl_ctx == 0) + { + ti.tpl_ctx = new sm::cpsm_tplh_t(); + ti.tpl_scan_ctx = sm::sp_cpsm_tplsch_t(new sm::cpsm_tplsch_t()); + } + + // make sure rowgroup is null so the new meta data can be taken. This is for some case mysql + // call rnd_init for a table more than once. + ti.tpl_scan_ctx->rowGroup = NULL; + + try + { + tableid = execplan::IDB_VTABLE_ID; + } + catch (...) + { + string emsg = "No table ID found for table " + string(table->s->table_name.str); + setError(thd, ER_INTERNAL_ERROR, emsg); + CalpontSystemCatalog::removeCalpontSystemCatalog(sessionID); + goto internal_error; + } + + try + { + sm::tpl_open(tableid, ti.tpl_ctx, hndl); + sm::tpl_scan_open(tableid, ti.tpl_scan_ctx, hndl); + } + catch (std::exception& e) + { + string emsg = "table can not be opened: " + string(e.what()); + setError(thd, ER_INTERNAL_ERROR, emsg); + CalpontSystemCatalog::removeCalpontSystemCatalog(sessionID); + goto internal_error; + } + catch (...) + { + string emsg = "table can not be opened"; + setError(thd, ER_INTERNAL_ERROR, emsg); + CalpontSystemCatalog::removeCalpontSystemCatalog(sessionID); + goto internal_error; + } + + ti.tpl_scan_ctx->traceFlags = ci->traceFlags; + + if ((ti.tpl_scan_ctx->ctp).size() == 0) + { + uint32_t num_attr = table->s->fields; + + for (uint32_t i = 0; i < num_attr; i++) + { + CalpontSystemCatalog::ColType ctype; + ti.tpl_scan_ctx->ctp.push_back(ctype); + } + } + } + + ci->tableMap[table] = ti; + return 0; + +error: + + if (ci->cal_conn_hndl) + { + sm::sm_cleanup(ci->cal_conn_hndl); + ci->cal_conn_hndl = 0; + } + + // do we need to close all connection handle of the table map + return ER_INTERNAL_ERROR; + +internal_error: + + if (ci->cal_conn_hndl) + { + sm::sm_cleanup(ci->cal_conn_hndl); + ci->cal_conn_hndl = 0; + } + + return ER_INTERNAL_ERROR; +} // vim:sw=4 ts=4: diff --git a/dbcon/mysql/ha_calpont_impl.h b/dbcon/mysql/ha_calpont_impl.h index bdc0e0eef..ee96876db 100644 --- a/dbcon/mysql/ha_calpont_impl.h +++ b/dbcon/mysql/ha_calpont_impl.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -20,6 +20,7 @@ #define HA_CALPONT_IMPL_H__ #include "idb_mysql.h" +#include "ha_mcs_pushdown.h" #ifdef NEED_CALPONT_EXTERNS extern int ha_calpont_impl_discover_existence(const char* schema, const char* name); @@ -29,8 +30,8 @@ extern int ha_calpont_impl_open(const char* name, int mode, uint32_t test_if_loc extern int ha_calpont_impl_close(void); extern int ha_calpont_impl_rnd_init(TABLE* table); extern int ha_calpont_impl_rnd_next(uchar* buf, TABLE* table); -extern int ha_calpont_impl_rnd_end(TABLE* table); -extern int ha_calpont_impl_write_row(uchar* buf, TABLE* table); +extern int ha_calpont_impl_rnd_end(TABLE* table, bool is_derived_hand = false); +extern int ha_calpont_impl_write_row(const uchar* buf, TABLE* table); extern void ha_calpont_impl_start_bulk_insert(ha_rows rows, TABLE* table); extern int ha_calpont_impl_end_bulk_insert(bool abort, TABLE* table); extern int ha_calpont_impl_rename_table(const char* from, const char* to); @@ -45,6 +46,7 @@ extern int ha_calpont_impl_rnd_pos(uchar* buf, uchar* pos); extern int ha_calpont_impl_group_by_init(ha_calpont_group_by_handler* group_hand, TABLE* table); extern int ha_calpont_impl_group_by_next(ha_calpont_group_by_handler* group_hand, TABLE* table); extern int ha_calpont_impl_group_by_end(ha_calpont_group_by_handler* group_hand, TABLE* table); +extern int ha_cs_impl_pushdown_init(mcs_handler_info* handler_info , TABLE* table); #endif @@ -52,9 +54,10 @@ extern int ha_calpont_impl_group_by_end(ha_calpont_group_by_handler* group_hand, #include "ha_calpont_impl_if.h" #include "calpontsystemcatalog.h" #include "ha_calpont.h" +#include "ha_mcs_pushdown.h" extern int ha_calpont_impl_rename_table_(const char* from, const char* to, cal_impl_if::cal_connection_info& ci); -extern int ha_calpont_impl_write_row_(uchar* buf, TABLE* table, cal_impl_if::cal_connection_info& ci, ha_rows& rowsInserted); -extern int ha_calpont_impl_write_batch_row_(uchar* buf, TABLE* table, cal_impl_if::cal_connection_info& ci); +extern int ha_calpont_impl_write_row_(const uchar* buf, TABLE* table, cal_impl_if::cal_connection_info& ci, ha_rows& rowsInserted); +extern int ha_calpont_impl_write_batch_row_(const uchar* buf, TABLE* table, cal_impl_if::cal_connection_info& ci); extern int ha_calpont_impl_write_last_batch(TABLE* table, cal_impl_if::cal_connection_info& ci, bool abort); extern int ha_calpont_impl_commit_ (handlerton* hton, THD* thd, bool all, cal_impl_if::cal_connection_info& ci); extern int ha_calpont_impl_rollback_ (handlerton* hton, THD* thd, bool all, cal_impl_if::cal_connection_info& ci); @@ -71,6 +74,7 @@ extern std::string ha_calpont_impl_cleartablelock( cal_impl_if::cal_connection_ extern int ha_calpont_impl_group_by_init(ha_calpont_group_by_handler* group_hand, TABLE* table); extern int ha_calpont_impl_group_by_next(ha_calpont_group_by_handler* group_hand, TABLE* table); extern int ha_calpont_impl_group_by_end(ha_calpont_group_by_handler* group_hand, TABLE* table); +extern int ha_cs_impl_derived_next(TABLE* table); #endif #endif diff --git a/dbcon/mysql/ha_calpont_impl_if.h b/dbcon/mysql/ha_calpont_impl_if.h index 6d8945ad8..967299aaf 100644 --- a/dbcon/mysql/ha_calpont_impl_if.h +++ b/dbcon/mysql/ha_calpont_impl_if.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -94,6 +94,7 @@ typedef std::map selectCols; execplan::CalpontSelectExecutionPlan::ReturnedColumnList returnedCols; execplan::CalpontSelectExecutionPlan::ReturnedColumnList groupByCols; @@ -142,6 +143,9 @@ struct gp_walk_info std::map derivedTbFilterMap; uint32_t derivedTbCnt; std::vector subselectList; + // Workaround for duplicate equi-JOIN predicates + // See isDuplicateSF() for more info. + List equiCondSFList; // Kludge for Bug 750 int32_t recursionLevel; @@ -150,6 +154,8 @@ struct gp_walk_info // Kludge for MCOL-1472 bool inCaseStmt; + bool cs_vtable_is_update_with_derive; + bool cs_vtable_impossible_where_on_union; gp_walk_info() : sessionid(0), fatalParseError(false), @@ -166,8 +172,10 @@ struct gp_walk_info lastSub(0), derivedTbCnt(0), recursionLevel(-1), - recursionHWM(0), - inCaseStmt(false) + recursionHWM(0), + inCaseStmt(false), + cs_vtable_is_update_with_derive(false), + cs_vtable_impossible_where_on_union(false) {} ~gp_walk_info() {} @@ -286,6 +294,7 @@ struct cal_connection_info std::stack cal_conn_hndl_st; int queryState; CalTableMap tableMap; + std::set physTablesList; sm::tableid_t currentTable; uint32_t traceFlags; std::string queryStats; @@ -337,14 +346,16 @@ const std::string infinidb_err_msg = "\nThe query includes syntax that is not su int cp_get_plan(THD* thd, execplan::SCSEP& csep); int cp_get_table_plan(THD* thd, execplan::SCSEP& csep, cal_impl_if::cal_table_info& ti); int cp_get_group_plan(THD* thd, execplan::SCSEP& csep, cal_impl_if::cal_group_info& gi); -int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, execplan::SCSEP& csep, bool isUnion = false); +int cs_get_derived_plan(derived_handler* handler, THD* thd, execplan::SCSEP& csep, gp_walk_info& gwi); +int cs_get_select_plan(select_handler* handler, THD* thd, execplan::SCSEP& csep, gp_walk_info& gwi); +int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, execplan::SCSEP& csep, bool isUnion = false, bool isPushdownHand = false); int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, execplan::SCSEP& csep, cal_group_info& gi, bool isUnion = false); void setError(THD* thd, uint32_t errcode, const std::string errmsg, gp_walk_info* gwi); void setError(THD* thd, uint32_t errcode, const std::string errmsg); void gp_walk(const Item* item, void* arg); void parse_item (Item* item, std::vector& field_vec, bool& hasNonSupportItem, uint16& parseInfo, gp_walk_info* gwip = NULL); const std::string bestTableName(const Item_field* ifp); -bool isInfiniDB(TABLE* table_ptr); +bool isMCSTable(TABLE* table_ptr); // execution plan util functions prototypes execplan::ReturnedColumn* buildReturnedColumn(Item* item, gp_walk_info& gwi, bool& nonSupport, bool pushdownHand = false); diff --git a/dbcon/mysql/ha_calpont_partition.cpp b/dbcon/mysql/ha_calpont_partition.cpp index 5ee2311d0..5cd957675 100644 --- a/dbcon/mysql/ha_calpont_partition.cpp +++ b/dbcon/mysql/ha_calpont_partition.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/mysql/ha_calpont_udf.cpp b/dbcon/mysql/ha_calpont_udf.cpp index 1e6f20301..3c5b8dd41 100644 --- a/dbcon/mysql/ha_calpont_udf.cpp +++ b/dbcon/mysql/ha_calpont_udf.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/mysql/ha_exists_sub.cpp b/dbcon/mysql/ha_exists_sub.cpp index eb6bc84b8..ee3326803 100644 --- a/dbcon/mysql/ha_exists_sub.cpp +++ b/dbcon/mysql/ha_exists_sub.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/mysql/ha_from_sub.cpp b/dbcon/mysql/ha_from_sub.cpp index 94f4e1d18..0093330aa 100644 --- a/dbcon/mysql/ha_from_sub.cpp +++ b/dbcon/mysql/ha_from_sub.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -322,9 +322,12 @@ ParseTree* setDerivedFilter(THD* thd, ParseTree*& n, FromSubQuery::FromSubQuery(gp_walk_info& gwip) : SubQuery(gwip) {} -FromSubQuery::FromSubQuery(gp_walk_info& gwip, SELECT_LEX* sub) : - SubQuery(gwip), - fFromSub(sub) +FromSubQuery::FromSubQuery(gp_walk_info& gwip, + SELECT_LEX* sub, + bool isPushdownHandler) : + SubQuery(gwip), + fFromSub(sub), + fPushdownHand(isPushdownHandler) {} FromSubQuery::~FromSubQuery() @@ -344,8 +347,9 @@ SCSEP FromSubQuery::transform() gwi.subQuery = this; gwi.viewName = fGwip.viewName; csep->derivedTbAlias(fAlias); // always lower case + csep->derivedTbView(fGwip.viewName.alias); - if (getSelectPlan(gwi, *fFromSub, csep) != 0) + if (getSelectPlan(gwi, *fFromSub, csep, fPushdownHand) != 0) { fGwip.fatalParseError = true; diff --git a/dbcon/mysql/ha_in_sub.cpp b/dbcon/mysql/ha_in_sub.cpp index 3f257961a..a582ea5bf 100644 --- a/dbcon/mysql/ha_in_sub.cpp +++ b/dbcon/mysql/ha_in_sub.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/mysql/ha_mcs_client_udfs.cpp b/dbcon/mysql/ha_mcs_client_udfs.cpp index 9113ae51b..6f6436101 100644 --- a/dbcon/mysql/ha_mcs_client_udfs.cpp +++ b/dbcon/mysql/ha_mcs_client_udfs.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/mysql/ha_mcs_pushdown.cpp b/dbcon/mysql/ha_mcs_pushdown.cpp new file mode 100644 index 000000000..713b70145 --- /dev/null +++ b/dbcon/mysql/ha_mcs_pushdown.cpp @@ -0,0 +1,619 @@ +/* + Copyright (c) 2019 MariaDB + + 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 St, Fifth Floor, Boston, MA 02110-1301 USA */ + + +// ha_calpont.cpp includes this file. + +void mutate_optimizer_flags(THD *thd_) +{ + // MCOL-2178 Disable all optimizer flags as it was in the fork. + // CS restores it later in SH::scan_end() and in case of an error + // in SH::scan_init() + set_original_optimizer_flags(thd_->variables.optimizer_switch, thd_); + thd_->variables.optimizer_switch = OPTIMIZER_SWITCH_IN_TO_EXISTS | + OPTIMIZER_SWITCH_EXISTS_TO_IN | + OPTIMIZER_SWITCH_COND_PUSHDOWN_FOR_DERIVED; +} + +void restore_optimizer_flags(THD *thd_) +{ + // MCOL-2178 restore original optimizer flags after SH, DH + ulonglong orig_flags = get_original_optimizer_flags(thd_); + if (orig_flags) + { + thd_->variables.optimizer_switch = orig_flags; + set_original_optimizer_flags(0, thd_); + } +} + + +/*@brief check_walk - It traverses filter conditions*/ +/************************************************************ + * DESCRIPTION: + * It traverses filter predicates looking for unsupported + * JOIN types: non-equi JOIN, e.g t1.c1 > t2.c2; + * logical OR. + * PARAMETERS: + * thd - THD pointer. + * derived - TABLE_LIST* to work with. + * RETURN: + * derived_handler if possible + * NULL in other case + ***********************************************************/ +void check_walk(const Item* item, void* arg) +{ + bool* unsupported_feature = static_cast(arg); + if ( *unsupported_feature ) + return; + switch (item->type()) + { + case Item::FUNC_ITEM: + { + const Item_func* ifp = static_cast(item); + + if ( ifp->functype() != Item_func::EQ_FUNC ) // NON-equi JOIN + { + if ( ifp->argument_count() == 2 && + ifp->arguments()[0]->type() == Item::FIELD_ITEM && + ifp->arguments()[1]->type() == Item::FIELD_ITEM ) + { + Item_field* left= static_cast(ifp->arguments()[0]); + Item_field* right= static_cast(ifp->arguments()[1]); + + if ( left->field->table != right->field->table ) + { + *unsupported_feature = true; + return; + } + } + else // IN + correlated subquery + { + if ( ifp->functype() == Item_func::NOT_FUNC + && ifp->arguments()[0]->type() == Item::EXPR_CACHE_ITEM ) + { + check_walk(ifp->arguments()[0], arg); + } + } + } + break; + } + + case Item::EXPR_CACHE_ITEM: // IN + correlated subquery + { + const Item_cache_wrapper* icw = static_cast(item); + if ( icw->get_orig_item()->type() == Item::FUNC_ITEM ) + { + const Item_func *ifp = static_cast(icw->get_orig_item()); + if ( ifp->argument_count() == 2 && + ( ifp->arguments()[0]->type() == Item::Item::SUBSELECT_ITEM + || ifp->arguments()[1]->type() == Item::Item::SUBSELECT_ITEM )) + { + *unsupported_feature = true; + return; + } + } + break; + } + + case Item::COND_ITEM: // OR in JOIN conds is unsupported yet + { + Item_cond* icp = (Item_cond*)item; + if ( is_cond_or(icp) ) + { + *unsupported_feature = true; + } + break; + } + default: + { + break; + } + } +} + +/*@brief create_calpont_group_by_handler- Creates handler*/ +/*********************************************************** + * DESCRIPTION: + * Creates a group_by pushdown handler if there is no: + * non-equi JOIN, e.g * t1.c1 > t2.c2 + * logical OR in the filter predicates + * Impossible WHERE + * Impossible HAVING + * and there is either GROUP BY or aggregation function + * exists at the top level. + * Valid queries with the last two crashes the server if + * processed. + * Details are in server/sql/group_by_handler.h + * PARAMETERS: + * thd - THD pointer + * query - Query structure LFM in group_by_handler.h + * RETURN: + * group_by_handler if success + * NULL in other case + ***********************************************************/ +static group_by_handler* +create_calpont_group_by_handler(THD* thd, Query* query) +{ + ha_calpont_group_by_handler* handler = NULL; + + // same as thd->lex->current_select + SELECT_LEX *select_lex = query->from->select_lex; + + // MCOL-2178 Disable SP support in the group_by_handler for now + // Check the session variable value to enable/disable use of + // group_by_handler. There is no GBH if SH works for the query. + if (select_lex->select_h || !get_group_by_handler(thd) || (thd->lex)->sphead) + { + return handler; + } + + // Create a handler if query is valid. See comments for details. + if ( query->group_by || select_lex->with_sum_func ) + { + bool unsupported_feature = false; + // revisit SELECT_LEX for all units + for(TABLE_LIST* tl = query->from; !unsupported_feature && tl; tl = tl->next_global) + { + select_lex = tl->select_lex; + // Correlation subquery. Comming soon so fail on this yet. + unsupported_feature = select_lex->is_correlated; + + // Impossible HAVING or WHERE + if ( ( !unsupported_feature && select_lex->having_value == Item::COND_FALSE ) + || ( select_lex->cond_count > 0 + && select_lex->cond_value == Item::COND_FALSE ) ) + { + unsupported_feature = true; + } + + // Unsupported JOIN conditions + if ( !unsupported_feature ) + { + JOIN *join = select_lex->join; + Item_cond *icp = 0; + + if (join != 0) + icp = reinterpret_cast(join->conds); + + if ( unsupported_feature == false + && icp ) + { + icp->traverse_cond(check_walk, &unsupported_feature, Item::POSTFIX); + } + + // Optimizer could move some join conditions into where + if (select_lex->where != 0) + icp = reinterpret_cast(select_lex->where); + + if ( unsupported_feature == false + && icp ) + { + icp->traverse_cond(check_walk, &unsupported_feature, Item::POSTFIX); + } + + } + } // unsupported features check ends here + + if ( !unsupported_feature ) + { + handler = new ha_calpont_group_by_handler(thd, query); + + // Notify the server, that CS handles GROUP BY, ORDER BY and HAVING clauses. + query->group_by = NULL; + query->order_by = NULL; + query->having = NULL; + } + } + + return handler; +} + +/*@brief create_columnstore_derived_handler- Creates handler*/ +/************************************************************ + * DESCRIPTION: + * Creates a derived handler if there is no non-equi JOIN, e.g + * t1.c1 > t2.c2 and logical OR in the filter predicates. + * More details in server/sql/derived_handler.h + * PARAMETERS: + * thd - THD pointer. + * derived - TABLE_LIST* to work with. + * RETURN: + * derived_handler if possible + * NULL in other case + ***********************************************************/ +static derived_handler* +create_columnstore_derived_handler(THD* thd, TABLE_LIST *derived) +{ + ha_columnstore_derived_handler* handler = NULL; + + // MCOL-2178 Disable SP support in the derived_handler for now + // Check the session variable value to enable/disable use of + // derived_handler + if (!get_derived_handler(thd) || (thd->lex)->sphead) + { + return handler; + } + + SELECT_LEX_UNIT *unit= derived->derived; + + bool unsupported_feature = false; + { + SELECT_LEX select_lex = *unit->first_select(); + JOIN* join = select_lex.join; + Item_cond* icp = 0; + + if (join != 0) + icp = reinterpret_cast(join->conds); + + if (!join) + { + icp = reinterpret_cast(select_lex.where); + } + + if ( icp ) + { + //icp->traverse_cond(check_walk, &unsupported_feature, Item::POSTFIX); + } + } + + if ( !unsupported_feature ) + handler= new ha_columnstore_derived_handler(thd, derived); + + return handler; +} + +/*********************************************************** + * DESCRIPTION: + * derived_handler constructor + * PARAMETERS: + * thd - THD pointer. + * tbl - tables involved. + ***********************************************************/ +ha_columnstore_derived_handler::ha_columnstore_derived_handler(THD *thd, + TABLE_LIST *dt) + : derived_handler(thd, mcs_hton) +{ + derived = dt; +} + +/*********************************************************** + * DESCRIPTION: + * derived_handler destructor + ***********************************************************/ +ha_columnstore_derived_handler::~ha_columnstore_derived_handler() +{} + +/*@brief Initiate the query for derived_handler */ +/*********************************************************** + * DESCRIPTION: + * Execute the query and saves derived table query. + * PARAMETERS: + * + * RETURN: + * rc as int + ***********************************************************/ +int ha_columnstore_derived_handler::init_scan() +{ + char query_buff[4096]; + + DBUG_ENTER("ha_columnstore_derived_handler::init_scan"); + + // Save query for logging + String derived_query(query_buff, sizeof(query_buff), thd->charset()); + derived_query.length(0); + derived->derived->print(&derived_query, QT_ORDINARY); + + mcs_handler_info mhi = mcs_handler_info(static_cast(this), DERIVED); + // this::table is the place for the result set + int rc = ha_cs_impl_pushdown_init(&mhi, table); + + DBUG_RETURN(rc); +} + +/*@brief Fetch next row for derived_handler */ +/*********************************************************** + * DESCRIPTION: + * Fetches next row and saves it in the temp table + * PARAMETERS: + * + * RETURN: + * rc as int + * + ***********************************************************/ +int ha_columnstore_derived_handler::next_row() +{ + DBUG_ENTER("ha_columnstore_derived_handler::next_row"); + + int rc = ha_calpont_impl_rnd_next(table->record[0], table); + + DBUG_RETURN(rc); +} + +/*@brief Finishes the scan and clean it up */ +/*********************************************************** + * DESCRIPTION: + * Finishes the scan for derived handler + * PARAMETERS: + * + * RETURN: + * rc as int + * + ***********************************************************/ +int ha_columnstore_derived_handler::end_scan() +{ + DBUG_ENTER("ha_columnstore_derived_handler::end_scan"); + + int rc = ha_calpont_impl_rnd_end(table, true); + + DBUG_RETURN(rc); +} + +void ha_columnstore_derived_handler::print_error(int, unsigned long) +{ +} + +/*********************************************************** + * DESCRIPTION: + * GROUP BY handler constructor + * PARAMETERS: + * thd - THD pointer. + * query - Query describing structure + ***********************************************************/ +ha_calpont_group_by_handler::ha_calpont_group_by_handler(THD* thd_arg, Query* query) + : group_by_handler(thd_arg, mcs_hton), + select(query->select), + table_list(query->from), + distinct(query->distinct), + where(query->where), + group_by(query->group_by), + order_by(query->order_by), + having(query->having) +{ +} + +/*********************************************************** + * DESCRIPTION: + * GROUP BY destructor + ***********************************************************/ +ha_calpont_group_by_handler::~ha_calpont_group_by_handler() +{ +} + +/*********************************************************** + * DESCRIPTION: + * Makes the plan and prepares the data + * RETURN: + * int rc + ***********************************************************/ +int ha_calpont_group_by_handler::init_scan() +{ + DBUG_ENTER("ha_calpont_group_by_handler::init_scan"); + + int rc = ha_calpont_impl_group_by_init(this, table); + + DBUG_RETURN(rc); +} + +/*********************************************************** + * DESCRIPTION: + * Fetches a row and saves it to a temporary table. + * RETURN: + * int rc + ***********************************************************/ +int ha_calpont_group_by_handler::next_row() +{ + DBUG_ENTER("ha_calpont_group_by_handler::next_row"); + int rc = ha_calpont_impl_group_by_next(this, table); + + DBUG_RETURN(rc); +} + +/*********************************************************** + * DESCRIPTION: + * Shuts the scan down. + * RETURN: + * int rc + ***********************************************************/ +int ha_calpont_group_by_handler::end_scan() +{ + DBUG_ENTER("ha_calpont_group_by_handler::end_scan"); + + int rc = ha_calpont_impl_group_by_end(this, table); + + DBUG_RETURN(rc); +} + +/*@brief create_columnstore_select_handler- Creates handler*/ +/************************************************************ + * DESCRIPTION: + * Creates a select handler if there is no non-equi JOIN, e.g + * t1.c1 > t2.c2 and logical OR in the filter predicates. + * More details in server/sql/select_handler.h + * PARAMETERS: + * thd - THD pointer. + * sel - SELECT_LEX* that describes the query. + * RETURN: + * select_handler if possible + * NULL in other case + ***********************************************************/ +static select_handler* +create_columnstore_select_handler(THD* thd, SELECT_LEX* select_lex) +{ + ha_columnstore_select_handler* handler = NULL; + + // MCOL-2178 Disable SP support in the select_handler for now. + // Check the session variable value to enable/disable use of + // select_handler + if (!get_select_handler(thd) || (thd->lex)->sphead) + { + return handler; + } + + bool unsupported_feature = false; + // Select_handler use the short-cut that effectively disables + // INSERT..SELECT and LDI + if ( (thd->lex)->sql_command == SQLCOM_INSERT_SELECT + || (thd->lex)->sql_command == SQLCOM_CREATE_TABLE ) + + { + unsupported_feature = true; + } + + // Impossible HAVING or WHERE + // TODO replace with function call + if ( unsupported_feature + || select_lex->having_value == Item::COND_FALSE + || select_lex->cond_value == Item::COND_FALSE ) + { + unsupported_feature = true; + } + + // Unsupported query check. + if ( !unsupported_feature ) + { + // JOIN expression from WHERE, ON expressions + JOIN* join = select_lex->join; + Item_cond* where_icp = 0; + Item_cond* on_icp = 0; + + if (join != 0) + { + where_icp = reinterpret_cast(join->conds); + } + + if ( where_icp ) + { + //where_icp->traverse_cond(check_walk, &unsupported_feature, Item::POSTFIX); + } + + // Looking for JOIN with ON expression through + // TABLE_LIST in FROM until CS meets unsupported feature + TABLE_LIST* table_ptr = select_lex->get_table_list(); + for (; !unsupported_feature && table_ptr; table_ptr = table_ptr->next_global) + { + if(table_ptr->on_expr) + { + on_icp = reinterpret_cast(table_ptr->on_expr); + //on_icp->traverse_cond(check_walk, &unsupported_feature, Item::POSTFIX); + } + } + + // CROSS JOIN w/o conditions isn't supported until MCOL-301 + // is ready. + if (join && join->table_count >= 2 && ( !where_icp && !on_icp )) + { + unsupported_feature = true; + } + } + + if (!unsupported_feature) + { + handler = new ha_columnstore_select_handler(thd, select_lex); + mutate_optimizer_flags(thd); + } + + return handler; +} + +/*********************************************************** + * DESCRIPTION: + * select_handler constructor + * PARAMETERS: + * thd - THD pointer. + * select_lex - sematic tree for the query. + ***********************************************************/ +ha_columnstore_select_handler::ha_columnstore_select_handler(THD *thd, + SELECT_LEX* select_lex) + : select_handler(thd, mcs_hton) +{ + select = select_lex; +} + +/*********************************************************** + * DESCRIPTION: + * select_handler constructor + ***********************************************************/ +ha_columnstore_select_handler::~ha_columnstore_select_handler() +{ +} + +/*@brief Initiate the query for select_handler */ +/*********************************************************** + * DESCRIPTION: + * Execute the query and saves select table query. + * PARAMETERS: + * + * RETURN: + * rc as int + ***********************************************************/ +int ha_columnstore_select_handler::init_scan() +{ + char query_buff[4096]; + + DBUG_ENTER("ha_columnstore_select_handler::init_scan"); + + // Save query for logging + String select_query(query_buff, sizeof(query_buff), thd->charset()); + select_query.length(0); + select->print(thd, &select_query, QT_ORDINARY); + + mcs_handler_info mhi = mcs_handler_info(static_cast(this), SELECT); + // this::table is the place for the result set + int rc = ha_cs_impl_pushdown_init(&mhi, table); + + DBUG_RETURN(rc); +} + +/*@brief Fetch next row for select_handler */ +/*********************************************************** + * DESCRIPTION: + * Fetches next row and saves it in the temp table + * PARAMETERS: + * + * RETURN: + * rc as int + * + ***********************************************************/ +int ha_columnstore_select_handler::next_row() +{ + DBUG_ENTER("ha_columnstore_select_handler::next_row"); + + int rc = ha_calpont_impl_rnd_next(table->record[0], table); + + DBUG_RETURN(rc); +} + +/*@brief Finishes the scan and clean it up */ +/*********************************************************** + * DESCRIPTION: + * Finishes the scan for select handler + * PARAMETERS: + * + * RETURN: + * rc as int + * + ***********************************************************/ +int ha_columnstore_select_handler::end_scan() +{ + DBUG_ENTER("ha_columnstore_select_handler::end_scan"); + + int rc = ha_calpont_impl_rnd_end(table, true); + + DBUG_RETURN(rc); +} + +void ha_columnstore_select_handler::print_error(int, unsigned long) +{} diff --git a/dbcon/mysql/ha_mcs_pushdown.h b/dbcon/mysql/ha_mcs_pushdown.h new file mode 100644 index 000000000..2ca4d5826 --- /dev/null +++ b/dbcon/mysql/ha_mcs_pushdown.h @@ -0,0 +1,145 @@ +/* + Copyright (c) 2019 MariaDB + + 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 St, Fifth Floor, Boston, MA 02110-1301 USA */ + + +#ifndef HA_MCS_PUSH +#define HA_MCS_PUSH + +#include "idb_mysql.h" +#include "ha_calpont.h" + +void mutate_optimizer_flags(THD *thd_); +void restore_optimizer_flags(THD *thd_); + +enum mcs_handler_types_t +{ + SELECT, + DERIVED, + GROUP_BY, + LEGACY +}; + +struct mcs_handler_info +{ + mcs_handler_info() : hndl_ptr(NULL), hndl_type(LEGACY) { }; + mcs_handler_info(mcs_handler_types_t type) : hndl_ptr(NULL), hndl_type(type) { }; + mcs_handler_info(void* ptr, mcs_handler_types_t type) : hndl_ptr(ptr), hndl_type(type) { }; + ~mcs_handler_info() { }; + void* hndl_ptr; + mcs_handler_types_t hndl_type; +}; + +/*@brief group_by_handler class*/ +/*********************************************************** + * DESCRIPTION: + * Provides server with group_by_handler API methods. + * One should read comments in server/sql/group_by_handler.h + * Attributes: + * select - attribute contains all GROUP BY, HAVING, ORDER items and calls it + * an extended SELECT list according to comments in + * server/sql/group_handler.cc. + * So the temporary table for + * select count(*) from b group by a having a > 3 order by a + * will have 4 columns not 1. + * However server ignores all NULLs used in + * GROUP BY, HAVING, ORDER. + * select_list_descr - contains Item description returned by Item->print() + * that is used in lookup for corresponding columns in + * extended SELECT list. + * table_list - contains all tables involved. Must be CS tables only. + * distinct - looks like a useless thing for now. Couldn't get it set by server. + * where - where items. + * group_by - group by ORDER items. + * order_by - order by ORDER items. + * having - having Item. + * Methods: + * init_scan - get plan and send it to ExeMgr. Get the execution result. + * next_row - get a row back from sm. + * end_scan - finish and clean the things up. + ***********************************************************/ +class ha_calpont_group_by_handler: public group_by_handler +{ +public: + ha_calpont_group_by_handler(THD* thd_arg, Query* query); + ~ha_calpont_group_by_handler(); + int init_scan(); + int next_row(); + int end_scan(); + + List* select; + TABLE_LIST* table_list; + bool distinct; + Item* where; + ORDER* group_by; + ORDER* order_by; + Item* having; +}; + +/*@brief derived_handler class*/ +/*********************************************************** + * DESCRIPTION: + * derived_handler API methods. Could be used by the server + * tp process sub-queries. + * More details in server/sql/dervied_handler.h + * COLUMNSTORE_SHARE* hton share + * tbl in the constructor is the list of the tables involved. + * Methods: + * init_scan - get plan and send it to ExeMgr. Get the execution result. + * next_row - get a row back from sm. + * end_scan - finish and clean the things up. + ***********************************************************/ +class ha_columnstore_derived_handler: public derived_handler +{ +private: + COLUMNSTORE_SHARE *share; + +public: + ha_columnstore_derived_handler(THD* thd_arg, TABLE_LIST *tbl); + ~ha_columnstore_derived_handler(); + int init_scan(); + int next_row(); + int end_scan(); + void print_error(int, unsigned long); +}; + +/*@brief select_handler class*/ +/*********************************************************** + * DESCRIPTION: + * select_handler API methods. Could be used by the server + * tp pushdown the whole query described by SELECT_LEX. + * More details in server/sql/select_handler.h + * COLUMNSTORE_SHARE* hton share + * sel in the constructor is the semantic tree for the query. + * Methods: + * init_scan - get plan and send it to ExeMgr. Get the execution result. + * next_row - get a row back from sm. + * end_scan - finish and clean the things up. + ***********************************************************/ +class ha_columnstore_select_handler: public select_handler +{ +private: + COLUMNSTORE_SHARE *share; + +public: + ha_columnstore_select_handler(THD* thd_arg, SELECT_LEX* sel); + ~ha_columnstore_select_handler(); + int init_scan(); + int next_row(); + int end_scan(); + void print_error(int, unsigned long); +}; + +#endif diff --git a/dbcon/mysql/ha_mcs_sysvars.cpp b/dbcon/mysql/ha_mcs_sysvars.cpp index ff6943fa4..b0fc0bb0b 100644 --- a/dbcon/mysql/ha_mcs_sysvars.cpp +++ b/dbcon/mysql/ha_mcs_sysvars.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -58,6 +58,48 @@ static MYSQL_THDVAR_ULONGLONG( 1 ); +// optimizer flags vault +static MYSQL_THDVAR_ULONGLONG( + original_optimizer_flags, + PLUGIN_VAR_NOSYSVAR | PLUGIN_VAR_NOCMDOPT, + "Vault for original optimizer flags. For internal usage.", + NULL, + NULL, + 0, + 0, + ~0U, + 1 +); + +static MYSQL_THDVAR_BOOL( + select_handler, + PLUGIN_VAR_NOCMDARG, + "Enable/Disable the MCS select_handler", + NULL, + NULL, + 1 +); + +static MYSQL_THDVAR_BOOL( + derived_handler, + PLUGIN_VAR_NOCMDARG, + "Enable/Disable the MCS derived_handler", + NULL, + NULL, + 1 +); + +static MYSQL_THDVAR_BOOL( + group_by_handler, + PLUGIN_VAR_NOCMDARG, + "Enable/Disable the MCS group_by_handler", + NULL, + NULL, + 1 +); + + + // legacy system variables static MYSQL_THDVAR_ULONG( decimal_scale, @@ -92,7 +134,7 @@ static MYSQL_THDVAR_BOOL( static MYSQL_THDVAR_BOOL( double_for_decimal_math, PLUGIN_VAR_NOCMDARG, - "Enable/disable the InfiniDB to replace DECIMAL with DOUBLE in arithmetic operation.", + "Enable/disable for ColumnStore to replace DECIMAL with DOUBLE in arithmetic operation.", NULL, NULL, 0 @@ -185,7 +227,7 @@ static MYSQL_THDVAR_ULONG( static MYSQL_THDVAR_ULONG( local_query, PLUGIN_VAR_RQCMDARG, - "Enable/disable the Infinidb local PM query only feature.", + "Enable/disable the ColumnStore local PM query only feature.", NULL, NULL, 0, @@ -240,6 +282,10 @@ st_mysql_sys_var* mcs_system_variables[] = { MYSQL_SYSVAR(compression_type), MYSQL_SYSVAR(fe_conn_info_ptr), + MYSQL_SYSVAR(original_optimizer_flags), + MYSQL_SYSVAR(select_handler), + MYSQL_SYSVAR(derived_handler), + MYSQL_SYSVAR(group_by_handler), MYSQL_SYSVAR(decimal_scale), MYSQL_SYSVAR(use_decimal_scale), MYSQL_SYSVAR(ordered_only), @@ -275,14 +321,47 @@ void set_fe_conn_info_ptr(void* ptr, THD* thd) THDVAR(current_thd, fe_conn_info_ptr) = (uint64_t)(ptr); } -bool get_use_legacy_sysvars(THD* thd) +ulonglong get_original_optimizer_flags(THD* thd) { - return ( thd == NULL ) ? false : THDVAR(thd, use_legacy_sysvars); + return ( current_thd == NULL && thd == NULL ) ? NULL : + THDVAR(current_thd, original_optimizer_flags); } -void set_use_legacy_sysvars(THD* thd, bool value) +void set_original_optimizer_flags(ulonglong ptr, THD* thd) { - THDVAR(thd, use_legacy_sysvars) = value; + if ( current_thd == NULL && thd == NULL) + { + return; + } + + THDVAR(current_thd, original_optimizer_flags) = (uint64_t)(ptr); +} + +bool get_select_handler(THD* thd) +{ + return ( thd == NULL ) ? false : THDVAR(thd, select_handler); +} +void set_select_handler(THD* thd, bool value) +{ + THDVAR(thd, select_handler) = value; +} + +bool get_derived_handler(THD* thd) +{ + return ( thd == NULL ) ? false : THDVAR(thd, derived_handler); +} +void set_derived_handler(THD* thd, bool value) +{ + THDVAR(thd, derived_handler) = value; +} + +bool get_group_by_handler(THD* thd) +{ + return ( thd == NULL ) ? false : THDVAR(thd, group_by_handler); +} +void set_group_by_handler(THD* thd, bool value) +{ + THDVAR(thd, group_by_handler) = value; } void set_compression_type(THD* thd, ulong value) @@ -296,225 +375,135 @@ mcs_compression_type_t get_compression_type(THD* thd) { bool get_use_decimal_scale(THD* thd) { - if(get_use_legacy_sysvars(thd)) - return ( thd == NULL ) ? false : thd->variables.infinidb_use_decimal_scale; - else - return ( thd == NULL ) ? false : THDVAR(thd, use_decimal_scale); + return ( thd == NULL ) ? false : THDVAR(thd, use_decimal_scale); } void set_use_decimal_scale(THD* thd, bool value) { - if(get_use_legacy_sysvars(thd)) - thd->variables.infinidb_use_decimal_scale = value; - else - THDVAR(thd, use_decimal_scale) = value; + THDVAR(thd, use_decimal_scale) = value; } ulong get_decimal_scale(THD* thd) { - if(get_use_legacy_sysvars(thd)) - return ( thd == NULL ) ? 0 : thd->variables.infinidb_decimal_scale; - else - return ( thd == NULL ) ? 0 : THDVAR(thd, decimal_scale); + return ( thd == NULL ) ? 0 : THDVAR(thd, decimal_scale); } void set_decimal_scale(THD* thd, ulong value) { - if(get_use_legacy_sysvars(thd)) - thd->variables.infinidb_decimal_scale = value; - else - THDVAR(thd, decimal_scale) = value; + THDVAR(thd, decimal_scale) = value; } bool get_ordered_only(THD* thd) { - if(get_use_legacy_sysvars(thd)) - return ( thd == NULL ) ? false : thd->variables.infinidb_ordered_only; - else - return ( thd == NULL ) ? false : THDVAR(thd, ordered_only); + return ( thd == NULL ) ? false : THDVAR(thd, ordered_only); } void set_ordered_only(THD* thd, bool value) { - if(get_use_legacy_sysvars(thd)) - thd->variables.infinidb_ordered_only = value; - else - THDVAR(thd, ordered_only) = value; + THDVAR(thd, ordered_only) = value; } ulong get_string_scan_threshold(THD* thd) { - if(get_use_legacy_sysvars(thd)) - return ( thd == NULL ) ? 0 : thd->variables.infinidb_string_scan_threshold; - else - return ( thd == NULL ) ? 0 : THDVAR(thd, string_scan_threshold); + return ( thd == NULL ) ? 0 : THDVAR(thd, string_scan_threshold); } void set_string_scan_threshold(THD* thd, ulong value) { - if(get_use_legacy_sysvars(thd)) - thd->variables.infinidb_string_scan_threshold = value; - else - THDVAR(thd, string_scan_threshold) = value; + THDVAR(thd, string_scan_threshold) = value; } ulong get_stringtable_threshold(THD* thd) { - if(get_use_legacy_sysvars(thd)) - return ( thd == NULL ) ? 0 : thd->variables.infinidb_stringtable_threshold; - else - return ( thd == NULL ) ? 0 : THDVAR(thd, stringtable_threshold); + return ( thd == NULL ) ? 0 : THDVAR(thd, stringtable_threshold); } void set_stringtable_threshold(THD* thd, ulong value) { - if(get_use_legacy_sysvars(thd)) - thd->variables.infinidb_stringtable_threshold = value; - else - THDVAR(thd, stringtable_threshold) = value; + THDVAR(thd, stringtable_threshold) = value; } ulong get_diskjoin_smallsidelimit(THD* thd) { - if(get_use_legacy_sysvars(thd)) - return ( thd == NULL ) ? 0 : thd->variables.infinidb_diskjoin_smallsidelimit; - else - return ( thd == NULL ) ? 0 : THDVAR(thd, diskjoin_smallsidelimit); + return ( thd == NULL ) ? 0 : THDVAR(thd, diskjoin_smallsidelimit); } void set_diskjoin_smallsidelimit(THD* thd, ulong value) { - if(get_use_legacy_sysvars(thd)) - thd->variables.infinidb_diskjoin_smallsidelimit = value; - else - THDVAR(thd, diskjoin_smallsidelimit) = value; + THDVAR(thd, diskjoin_smallsidelimit) = value; } ulong get_diskjoin_largesidelimit(THD* thd) { - if(get_use_legacy_sysvars(thd)) - return ( thd == NULL ) ? 0 : thd->variables.infinidb_diskjoin_largesidelimit; - else - return ( thd == NULL ) ? 0 : THDVAR(thd, diskjoin_largesidelimit); + return ( thd == NULL ) ? 0 : THDVAR(thd, diskjoin_largesidelimit); } void set_diskjoin_largesidelimit(THD* thd, ulong value) { - if(get_use_legacy_sysvars(thd)) - thd->variables.infinidb_diskjoin_largesidelimit = value; - else - THDVAR(thd, diskjoin_largesidelimit) = value; + THDVAR(thd, diskjoin_largesidelimit) = value; } ulong get_diskjoin_bucketsize(THD* thd) { - if(get_use_legacy_sysvars(thd)) - return ( thd == NULL ) ? 0 : thd->variables.infinidb_diskjoin_bucketsize; - else - return ( thd == NULL ) ? 0 : THDVAR(thd, diskjoin_bucketsize); + return ( thd == NULL ) ? 0 : THDVAR(thd, diskjoin_bucketsize); } void set_diskjoin_bucketsize(THD* thd, ulong value) { - if(get_use_legacy_sysvars(thd)) - thd->variables.infinidb_diskjoin_bucketsize = value; - else - THDVAR(thd, diskjoin_bucketsize) = value; + THDVAR(thd, diskjoin_bucketsize) = value; } ulong get_um_mem_limit(THD* thd) { - if(get_use_legacy_sysvars(thd)) - return ( thd == NULL ) ? 0 : thd->variables.infinidb_um_mem_limit; - else - return ( thd == NULL ) ? 0 : THDVAR(thd, um_mem_limit); + return ( thd == NULL ) ? 0 : THDVAR(thd, um_mem_limit); } void set_um_mem_limit(THD* thd, ulong value) { - if(get_use_legacy_sysvars(thd)) - thd->variables.infinidb_um_mem_limit = value; - else - THDVAR(thd, um_mem_limit) = value; + THDVAR(thd, um_mem_limit) = value; } bool get_varbin_always_hex(THD* thd) { - if(get_use_legacy_sysvars(thd)) - return ( thd == NULL ) ? false : thd->variables.infinidb_varbin_always_hex; - else - return ( thd == NULL ) ? false : THDVAR(thd, varbin_always_hex); + return ( thd == NULL ) ? false : THDVAR(thd, varbin_always_hex); } void set_varbin_always_hex(THD* thd, bool value) { - if(get_use_legacy_sysvars(thd)) - thd->variables.infinidb_varbin_always_hex = value; - else - THDVAR(thd, varbin_always_hex) = value; + THDVAR(thd, varbin_always_hex) = value; } bool get_double_for_decimal_math(THD* thd) { - if(get_use_legacy_sysvars(thd)) - return ( thd == NULL ) ? false : thd->variables.infinidb_double_for_decimal_math; - else - return ( thd == NULL ) ? false : THDVAR(thd, double_for_decimal_math); + return ( thd == NULL ) ? false : THDVAR(thd, double_for_decimal_math); } void set_double_for_decimal_math(THD* thd, bool value) { - if(get_use_legacy_sysvars(thd)) - thd->variables.infinidb_double_for_decimal_math = value; - else - THDVAR(thd, double_for_decimal_math) = value; + THDVAR(thd, double_for_decimal_math) = value; } ulong get_local_query(THD* thd) { - if(get_use_legacy_sysvars(thd)) - return ( thd == NULL ) ? 0 : thd->variables.infinidb_local_query; - else - return ( thd == NULL ) ? 0 : THDVAR(thd, local_query); + return ( thd == NULL ) ? 0 : THDVAR(thd, local_query); } void set_local_query(THD* thd, ulong value) { - if(get_use_legacy_sysvars(thd)) - thd->variables.infinidb_local_query = value; - else - THDVAR(thd, local_query) = value; + THDVAR(thd, local_query) = value; } bool get_use_import_for_batchinsert(THD* thd) { - if(get_use_legacy_sysvars(thd)) - return ( thd == NULL ) ? false : thd->variables.infinidb_use_import_for_batchinsert; - else - return ( thd == NULL ) ? false : THDVAR(thd, use_import_for_batchinsert); + return ( thd == NULL ) ? false : THDVAR(thd, use_import_for_batchinsert); } void set_use_import_for_batchinsert(THD* thd, bool value) { - if(get_use_legacy_sysvars(thd)) - thd->variables.infinidb_use_import_for_batchinsert = value; - else - THDVAR(thd, use_import_for_batchinsert) = value; + THDVAR(thd, use_import_for_batchinsert) = value; } ulong get_import_for_batchinsert_delimiter(THD* thd) { - if(get_use_legacy_sysvars(thd)) - return ( thd == NULL ) ? 0 : thd->variables.infinidb_import_for_batchinsert_delimiter; - else - return ( thd == NULL ) ? 0 : THDVAR(thd, import_for_batchinsert_delimiter); + return ( thd == NULL ) ? 0 : THDVAR(thd, import_for_batchinsert_delimiter); } void set_import_for_batchinsert_delimiter(THD* thd, ulong value) { - if(get_use_legacy_sysvars(thd)) - thd->variables.infinidb_import_for_batchinsert_delimiter = value; - else - THDVAR(thd, import_for_batchinsert_delimiter) = value; + THDVAR(thd, import_for_batchinsert_delimiter) = value; } ulong get_import_for_batchinsert_enclosed_by(THD* thd) { - if(get_use_legacy_sysvars(thd)) - return ( thd == NULL ) ? 0 : thd->variables.infinidb_import_for_batchinsert_enclosed_by; - else - return ( thd == NULL ) ? 0 : THDVAR(thd, import_for_batchinsert_enclosed_by); + return ( thd == NULL ) ? 0 : THDVAR(thd, import_for_batchinsert_enclosed_by); } void set_import_for_batchinsert_enclosed_by(THD* thd, ulong value) { - if(get_use_legacy_sysvars(thd)) - thd->variables.infinidb_import_for_batchinsert_enclosed_by = value; - else - THDVAR(thd, import_for_batchinsert_enclosed_by) = value; + THDVAR(thd, import_for_batchinsert_enclosed_by) = value; } diff --git a/dbcon/mysql/ha_mcs_sysvars.h b/dbcon/mysql/ha_mcs_sysvars.h index eae31b0ea..38ed294cf 100644 --- a/dbcon/mysql/ha_mcs_sysvars.h +++ b/dbcon/mysql/ha_mcs_sysvars.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -40,8 +40,17 @@ void set_compression_type(THD* thd, ulong value); void* get_fe_conn_info_ptr(THD* thd = NULL); void set_fe_conn_info_ptr(void* ptr, THD* thd = NULL); -bool get_use_legacy_sysvars(THD* thd); -void set_use_legacy_sysvars(THD* thd, bool value); +ulonglong get_original_optimizer_flags(THD* thd = NULL); +void set_original_optimizer_flags(ulonglong ptr, THD* thd = NULL); + +bool get_select_handler(THD* thd); +void set_select_handler(THD* thd, bool value); + +bool get_derived_handler(THD* thd); +void set_derived_handler(THD* thd, bool value); + +bool get_group_by_handler(THD* thd); +void set_group_by_handler(THD* thd, bool value); bool get_use_decimal_scale(THD* thd); void set_use_decimal_scale(THD* thd, bool value); diff --git a/dbcon/mysql/ha_pseudocolumn.cpp b/dbcon/mysql/ha_pseudocolumn.cpp index 57683b9bf..943d492ae 100644 --- a/dbcon/mysql/ha_pseudocolumn.cpp +++ b/dbcon/mysql/ha_pseudocolumn.cpp @@ -540,7 +540,7 @@ execplan::ReturnedColumn* buildPseudoColumn(Item* item, { SRCP srcp(sc); gwi.columnMap.insert(CalpontSelectExecutionPlan::ColumnMap::value_type(sc->columnName(), srcp)); - gwi.tableMap[make_aliastable(sc->schemaName(), sc->tableName(), sc->tableAlias(), sc->isInfiniDB())] = + gwi.tableMap[make_aliastable(sc->schemaName(), sc->tableName(), sc->tableAlias(), sc->isColumnStore())] = make_pair(1, field->cached_table); } else if (!gwi.rcWorkStack.empty()) diff --git a/dbcon/mysql/ha_scalar_sub.cpp b/dbcon/mysql/ha_scalar_sub.cpp index 8669303f9..debd777f0 100644 --- a/dbcon/mysql/ha_scalar_sub.cpp +++ b/dbcon/mysql/ha_scalar_sub.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/mysql/ha_select_sub.cpp b/dbcon/mysql/ha_select_sub.cpp index 54124b0f9..0b003b664 100644 --- a/dbcon/mysql/ha_select_sub.cpp +++ b/dbcon/mysql/ha_select_sub.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/mysql/ha_subquery.h b/dbcon/mysql/ha_subquery.h index b008b4fcd..d5e1df5a4 100644 --- a/dbcon/mysql/ha_subquery.h +++ b/dbcon/mysql/ha_subquery.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -45,7 +45,10 @@ namespace cal_impl_if class SubQuery { public: - SubQuery(gp_walk_info& gwip) : fGwip(gwip), fCorrelated(false) {} + SubQuery(gp_walk_info& gwip) : + fGwip(gwip), + fCorrelated(false) + {} virtual ~SubQuery() {} virtual gp_walk_info& gwip() const { @@ -178,7 +181,7 @@ class FromSubQuery : public SubQuery { public: FromSubQuery(gp_walk_info&); - FromSubQuery(gp_walk_info&, SELECT_LEX* fromSub); + FromSubQuery(gp_walk_info&, SELECT_LEX* fromSub, bool isPushdownHand=false); ~FromSubQuery(); const SELECT_LEX* fromSub() const { @@ -200,6 +203,7 @@ public: private: SELECT_LEX* fFromSub; std::string fAlias; + bool fPushdownHand; }; class SelectSubQuery : public SubQuery diff --git a/dbcon/mysql/ha_view.cpp b/dbcon/mysql/ha_view.cpp index 764c2c5c5..65707e4c7 100644 --- a/dbcon/mysql/ha_view.cpp +++ b/dbcon/mysql/ha_view.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -102,14 +102,17 @@ void View::transform() CalpontSystemCatalog::TableAliasName tn = make_aliasview("", "", alias, viewName); gwi.tbList.push_back(tn); gwi.tableMap[tn] = make_pair(0, table_ptr); - gwi.thd->infinidb_vtable.isUnion = true; //by-pass the 2nd pass of rnd_init + // TODO MCOL-2178 isUnion member only assigned, never used + // MIGR::infinidb_vtable.isUnion = true; //by-pass the 2nd pass of rnd_init } else if (table_ptr->view) { // for nested view, the view name is vout.vin... format CalpontSystemCatalog::TableAliasName tn = make_aliasview(table_ptr->db.str, table_ptr->table_name.str, table_ptr->alias.str, viewName); gwi.viewName = make_aliastable(table_ptr->db.str, table_ptr->table_name.str, viewName); - View* view = new View(table_ptr->view->select_lex, &gwi); + // WIP MCOL-2178 CS could mess with the SELECT_LEX unit so better + // use a copy. + View* view = new View(*table_ptr->view->first_select_lex(), &gwi); view->viewName(gwi.viewName); gwi.viewList.push_back(view); view->transform(); @@ -117,13 +120,13 @@ void View::transform() else { // check foreign engine tables - bool infiniDB = (table_ptr->table ? isInfiniDB(table_ptr->table) : true); + bool columnStore = (table_ptr->table ? isMCSTable(table_ptr->table) : true); // trigger system catalog cache - if (infiniDB) + if (columnStore) csc->columnRIDs(make_table(table_ptr->db.str, table_ptr->table_name.str), true); - CalpontSystemCatalog::TableAliasName tn = make_aliasview(table_ptr->db.str, table_ptr->table_name.str, table_ptr->alias.str, viewName, infiniDB); + CalpontSystemCatalog::TableAliasName tn = make_aliasview(table_ptr->db.str, table_ptr->table_name.str, table_ptr->alias.str, viewName, columnStore); gwi.tbList.push_back(tn); gwi.tableMap[tn] = make_pair(0, table_ptr); fParentGwip->tableMap[tn] = make_pair(0, table_ptr); diff --git a/dbcon/mysql/ha_window_function.cpp b/dbcon/mysql/ha_window_function.cpp index eb02b77a3..6a8117707 100644 --- a/dbcon/mysql/ha_window_function.cpp +++ b/dbcon/mysql/ha_window_function.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/dbcon/mysql/idb_mysql.h b/dbcon/mysql/idb_mysql.h index 25f3effcf..cb842d740 100644 --- a/dbcon/mysql/idb_mysql.h +++ b/dbcon/mysql/idb_mysql.h @@ -70,6 +70,8 @@ template bool isnan(T); #include "item_windowfunc.h" #include "sql_cte.h" #include "tztime.h" +#include "derived_handler.h" +#include "select_handler.h" // Now clean up the pollution as best we can... #undef min diff --git a/dbcon/mysql/install_calpont_mysql.sh b/dbcon/mysql/install_calpont_mysql.sh index 2a7c79883..d6fc8fb4d 100755 --- a/dbcon/mysql/install_calpont_mysql.sh +++ b/dbcon/mysql/install_calpont_mysql.sh @@ -28,7 +28,6 @@ df=$installdir/mysql/my.cnf $installdir/mysql/bin/mysql --defaults-extra-file=$df --force --user=root mysql 2> ${tmpdir}/mysql_install.log <tableid; SMDEBUGLOG << endl; -#endif delete ntplh; // determine end of result set and end of statement execution @@ -391,57 +390,60 @@ tpl_close ( cpsm_tplh_t* ntplh, { // Get the query stats ByteStream bs; - ByteStream::quadbyte qb = 3; - bs << qb; - hndl->write(bs); - + // Ask for a stats only if a user explicitly asks + if(ask_4_stats) + { + ByteStream::quadbyte qb = 3; + bs << qb; + hndl->write(bs); + } // MCOL-1601 Dispose of unused empty RowGroup if (clear_scan_ctx) { + std::cout << "tpl_close() clear_scan_ctx read" << std::endl; bs = hndl->exeMgr->read(); } -#if IDB_SM_DEBUG SMDEBUGLOG << "tpl_close hndl->exeMgr: " << hndl->exeMgr << endl; -#endif //keep reading until we get a string - //TODO: really need to fix this! Why is ExeMgr sending other stuff? - for (int tries = 0; tries < 10; tries++) + // Ask for a stats only if a user explicitly asks + if(ask_4_stats) { - bs = hndl->exeMgr->read(); + for (int tries = 0; tries < 10; tries++) + { + bs = hndl->exeMgr->read(); - if (bs.length() == 0) break; + if (bs.length() == 0) break; - try - { - bs >> hndl->queryStats; - bs >> hndl->extendedStats; - bs >> hndl->miniStats; - stats.unserialize(bs); - stats.setEndTime(); - stats.insert(); - break; + try + { + bs >> hndl->queryStats; + bs >> hndl->extendedStats; + bs >> hndl->miniStats; + stats.unserialize(bs); + stats.setEndTime(); + stats.insert(); + break; + } + catch (IDBExcept&) + { + // @bug4732 + end_query(hndl); + throw; + } + catch (...) + { + // querystats messed up. close connection. + // no need to throw for querystats protocol error, like for tablemode. + SMDEBUGLOG << "tpl_close() exception whilst getting stats" << endl; + end_query(hndl); + sm_cleanup(hndl); + *conn_hdl = 0; + return STATUS_OK; + //throw runtime_error(string("tbl_close catch exception: ") + e.what()); + } } - catch (IDBExcept&) - { - // @bug4732 - end_query(hndl); - throw; - } - catch (...) - { - // querystats messed up. close connection. - // no need to throw for querystats protocol error, like for tablemode. -#if IDB_SM_DEBUG - SMDEBUGLOG << "tpl_close() exception whilst getting stats" << endl; -#endif - end_query(hndl); - sm_cleanup(hndl); - *conn_hdl = 0; - return STATUS_OK; - //throw runtime_error(string("tbl_close catch exception: ") + e.what()); - } - } + } //stats end_query(hndl); } @@ -452,7 +454,7 @@ tpl_close ( cpsm_tplh_t* ntplh, status_t sm_init ( uint32_t sid, cpsm_conhdl_t** conn_hdl, - uint32_t infinidb_local_query) + uint32_t columnstore_local_query) { // clear file content #if IDB_SM_DEBUG @@ -463,7 +465,7 @@ sm_init ( uint32_t sid, // @bug5660 Connection changes related to the local pm setting /** - * when local PM is detected, or infinidb_local_query is set: + * when local PM is detected, or columnstore_local_query is set: * 1. SELECT query connect to local ExeMgr 127.0.0.1:8601; * 2. DML/DDL is disallowed. * once local connection is determined, no need to check @@ -472,14 +474,14 @@ sm_init ( uint32_t sid, if (*conn_hdl) { // existing connection is local, ok. - if ((*conn_hdl)->exeMgr->localQuery() || ! infinidb_local_query) + if ((*conn_hdl)->exeMgr->localQuery() || ! columnstore_local_query) return STATUS_OK; // if session variable changes to local, re-establish the connection to loopback. else sm_cleanup(*conn_hdl); } - cpsm_conhdl_t* hndl = new cpsm_conhdl_t(time(0), sid, infinidb_local_query); + cpsm_conhdl_t* hndl = new cpsm_conhdl_t(time(0), sid, columnstore_local_query); *conn_hdl = hndl; hndl->sessionID = sid; diff --git a/dbcon/mysql/sm.h b/dbcon/mysql/sm.h index dafa64419..43da05ee1 100644 --- a/dbcon/mysql/sm.h +++ b/dbcon/mysql/sm.h @@ -198,9 +198,9 @@ typedef boost::shared_ptr sp_cpsm_tplsch_t; class cpsm_conhdl_t { public: - cpsm_conhdl_t(time_t v, const uint32_t sid, bool infinidb_local_query) : + cpsm_conhdl_t(time_t v, const uint32_t sid, bool columnstore_local_query) : value(v), sessionID(sid), queryState (NO_QUERY), - exeMgr( new execplan::ClientRotator(sid, "ExeMgr", infinidb_local_query)), + exeMgr( new execplan::ClientRotator(sid, "ExeMgr", columnstore_local_query)), tblinfo_idx(0), idxinfo_idx(0), curFetchTb (0) { } @@ -275,14 +275,14 @@ struct cpsm_tid_t int value; }; -extern status_t sm_init(uint32_t, cpsm_conhdl_t**, uint32_t infinidb_local_query = false); +extern status_t sm_init(uint32_t, cpsm_conhdl_t**, uint32_t columnstore_local_query = false); extern status_t sm_cleanup(cpsm_conhdl_t*); extern status_t tpl_open(tableid_t, cpsm_tplh_t*, cpsm_conhdl_t*); extern status_t tpl_scan_open(tableid_t, sp_cpsm_tplsch_t&, cpsm_conhdl_t*); extern status_t tpl_scan_fetch(sp_cpsm_tplsch_t&, cpsm_conhdl_t*, int* k = 0); extern status_t tpl_scan_close(sp_cpsm_tplsch_t&); -extern status_t tpl_close(cpsm_tplh_t*, cpsm_conhdl_t**, querystats::QueryStats& stats, bool clear_scan_ctx = false); +extern status_t tpl_close(cpsm_tplh_t*, cpsm_conhdl_t**, querystats::QueryStats& stats, bool ask_4_stats, bool clear_scan_ctx = false); } diff --git a/dbcon/mysql/syscatalog_mysql.sql b/dbcon/mysql/syscatalog_mysql.sql index 9996fddfd..7444f1fa2 100644 --- a/dbcon/mysql/syscatalog_mysql.sql +++ b/dbcon/mysql/syscatalog_mysql.sql @@ -3,6 +3,9 @@ create database if not exists calpontsys; use calpontsys; +drop table if exists systable restrict; +drop table if exists syscolumn restrict; + create table if not exists systable (tablename varchar(128), `schema` varchar(128), objectid int, @@ -13,7 +16,7 @@ create table if not exists systable (tablename varchar(128), numofrows int, avgrowlen int, numofblocks int, - autoincrement int) engine=infinidb comment='SCHEMA SYNC ONLY'; + autoincrement int) engine=columnstore comment='SCHEMA SYNC ONLY'; -- SYSCOLUMN create table if not exists syscolumn (`schema` varchar(128), @@ -37,4 +40,4 @@ create table if not exists syscolumn (`schema` varchar(128), minvalue varchar(64), `maxvalue` varchar(64), compressiontype integer, - nextvalue bigint) engine=infinidb comment='SCHEMA SYNC ONLY'; + nextvalue bigint) engine=columnstore comment='SCHEMA SYNC ONLY'; diff --git a/dmlproc/dmlproc.cpp b/dmlproc/dmlproc.cpp index a3e6fa713..09e5b9128 100644 --- a/dmlproc/dmlproc.cpp +++ b/dmlproc/dmlproc.cpp @@ -86,6 +86,8 @@ using namespace joblist; namespace fs = boost::filesystem; +threadpool::ThreadPool DMLServer::fDmlPackagepool(10, 0); + namespace { DistributedEngineComm* Dec; @@ -605,7 +607,7 @@ int main(int argc, char* argv[]) int temp; int serverThreads = 10; - int serverQueueSize = 50; + int serverQueueSize = 0; const string DMLProc("DMLProc"); temp = toInt(cf->getConfig(DMLProc, "ServerThreads")); @@ -613,10 +615,9 @@ int main(int argc, char* argv[]) if (temp > 0) serverThreads = temp; - temp = toInt(cf->getConfig(DMLProc, "ServerQueueSize")); - - if (temp > 0) - serverQueueSize = temp; +// temp = toInt(cf->getConfig(DMLProc, "ServerQueueSize")); +// if (temp > 0) +// serverQueueSize = temp; //read and cleanup port before trying to use try @@ -656,6 +657,8 @@ int main(int argc, char* argv[]) { JobStep::jobstepThreadPool.setDebug(true); JobStep::jobstepThreadPool.invoke(threadpool::ThreadPoolMonitor(&JobStep::jobstepThreadPool)); + DMLServer::fDmlPackagepool.setDebug(true); + DMLServer::fDmlPackagepool.invoke(threadpool::ThreadPoolMonitor(&DMLServer::fDmlPackagepool)); } //set ACTIVE state diff --git a/dmlproc/dmlprocessor.cpp b/dmlproc/dmlprocessor.cpp index 861198d45..9e1601a36 100644 --- a/dmlproc/dmlprocessor.cpp +++ b/dmlproc/dmlprocessor.cpp @@ -349,7 +349,7 @@ PackageHandler::~PackageHandler() // Rollback will most likely be next. // // A tranasaction for one fTableOid is not blocked by a txn for a different fTableOid. -int PackageHandler::synchTableAccess() +int PackageHandler::synchTableAccess(dmlpackage::CalpontDMLPackage* dmlPackage) { // MCOL-140 Wait for any other DML using this table. std::map::iterator it; @@ -393,10 +393,27 @@ int PackageHandler::synchTableAccess() // tableOidQueue here is the queue holding the waitng transactions for this fTableOid while (true) { + // Log something that we're waiting + LoggingID logid(21, fSessionID, fTxnid); + logging::Message::Args args1; + logging::Message msg(1); + ostringstream oss; + oss << "Txn is waiting for" << tableOidQueue.front() << " " << dmlPackage->get_SQLStatement() << "; |" << dmlPackage->get_SchemaName() <<"|"; + args1.add(oss.str()); + args1.add((uint64_t)fTableOid); + msg.format(args1); + logging::Logger logger(logid.fSubsysID); + logger.logMessage(LOG_TYPE_DEBUG, msg, logid); + tableOidCond.wait(lock); - + // In case of CTRL+C, the tableOidQueue could be invalidated + if ((tableOidMap.find(fTableOid))->second != tableOidQueue) + { + break; + } if (tableOidQueue.front() == fTxnid) { + // We're up next. Let's go do stuff. break; } @@ -439,7 +456,6 @@ int PackageHandler::releaseTableAccess() if (fTableOid == 0 || (it = tableOidMap.find(fTableOid)) == tableOidMap.end()) { - // This will happen for DML_COMMAND, as we never got the tableoid or called synchTableAccess return 2; // For now, return codes are not used } @@ -461,7 +477,8 @@ int PackageHandler::releaseTableAccess() } else { - tableOidQueue.pop(); // Get off the waiting list. + if (!tableOidQueue.empty()) + tableOidQueue.pop(); // Get off the waiting list. if (tableOidQueue.empty()) { @@ -477,7 +494,7 @@ int PackageHandler::releaseTableAccess() int PackageHandler::forceReleaseTableAccess() { - // By removing the tcnid from the queue, the logic after the wait in + // By removing the txnid from the queue, the logic after the wait in // synchTableAccess() will release the thread and clean up if needed. std::map::iterator it; boost::lock_guard lock(tableOidMutex); @@ -490,6 +507,11 @@ int PackageHandler::forceReleaseTableAccess() PackageHandler::tableAccessQueue_t& tableOidQueue = it->second; tableOidQueue.erase(fTxnid); + if (tableOidQueue.empty()) + { + // remove the queue from the map. + tableOidMap.erase(fTableOid); + } // release the condition tableOidCond.notify_all(); return 1; @@ -513,7 +535,8 @@ void PackageHandler::run() std::string stmt; unsigned DMLLoggingId = 21; oam::OamCache* oamCache = oam::OamCache::makeOamCache(); - + SynchTable synchTable; + try { switch ( fPackageType ) @@ -542,8 +565,7 @@ void PackageHandler::run() CalpontSystemCatalog::ROPair roPair = fcsc->tableRID(tableName); fTableOid = roPair.objnum; } - - synchTableAccess(); // Blocks if another DML thread is using this fTableOid + synchTable.setPackage(this, &insertPkg); // Blocks if another DML thread is using this fTableOid } #endif @@ -921,8 +943,7 @@ void PackageHandler::run() CalpontSystemCatalog::ROPair roPair = fcsc->tableRID(tableName); fTableOid = roPair.objnum; } - - synchTableAccess(); // Blocks if another DML thread is using this fTableOid + synchTable.setPackage(this, updatePkg.get()); // Blocks if another DML thread is using this fTableOid } #endif @@ -981,8 +1002,7 @@ void PackageHandler::run() CalpontSystemCatalog::ROPair roPair = fcsc->tableRID(tableName); fTableOid = roPair.objnum; } - - synchTableAccess(); // Blocks if another DML thread is using this fTableOid + synchTable.setPackage(this, deletePkg.get()); // Blocks if another DML thread is using this fTableOid } #endif @@ -1049,15 +1069,8 @@ void PackageHandler::run() break; } -#ifdef MCOL_140 - if (fConcurrentSupport) - { - // MCOL-140 We're done. release the next waiting txn for this fTableOid - releaseTableAccess(); - } -#endif //Log errors if ( (result.result != dmlpackageprocessor::DMLPackageProcessor::NO_ERROR) @@ -1080,15 +1093,8 @@ void PackageHandler::run() } catch (std::exception& e) { -#ifdef MCOL_140 - if (fConcurrentSupport) - { - // MCOL-140 We're done. release the next waiting txn for this fTableOid - releaseTableAccess(); - } -#endif cout << "dmlprocessor.cpp PackageHandler::run() package type(" << fPackageType << ") exception: " << e.what() << endl; logging::LoggingID lid(21); @@ -1105,15 +1111,8 @@ void PackageHandler::run() } catch (...) { -#ifdef MCOL_140 - if (fConcurrentSupport) - { - // MCOL-140 We're done. release the next waiting txn for this fTableOid - releaseTableAccess(); - } -#endif logging::LoggingID lid(21); logging::MessageLog ml(lid); logging::Message::Args args; @@ -1157,9 +1156,17 @@ void PackageHandler::run() void PackageHandler::rollbackPending() { + if (fProcessor.get() == NULL) + { + // This happens when batch insert + return; + } + + fProcessor->setRollbackPending(true); + // Force a release of the processing from MCOL-140 #ifdef MCOL_140 - if (fConcurrentSupport) + if (fConcurrentSupport) { // MCOL-140 We're not necessarily the next in line. // This forces this thread to be released anyway. @@ -1168,14 +1175,6 @@ void PackageHandler::rollbackPending() #endif - if (fProcessor.get() == NULL) - { - // This happens when batch insert - return; - } - - fProcessor->setRollbackPending(true); - ostringstream oss; oss << "PackageHandler::rollbackPending: Processing DMLPackage."; DMLProcessor::log(oss.str(), logging::LOG_TYPE_DEBUG); diff --git a/dmlproc/dmlprocessor.h b/dmlproc/dmlprocessor.h index 60ba8a14b..6a18493b1 100644 --- a/dmlproc/dmlprocessor.h +++ b/dmlproc/dmlprocessor.h @@ -151,15 +151,16 @@ private: DMLServer(const DMLServer& rhs); DMLServer& operator=(const DMLServer& rhs); - /** @brief the thread pool for processing dml packages - */ - threadpool::ThreadPool fDmlPackagepool; - int fPackageMaxThreads; /** @brief max number of threads to process dml packages */ int fPackageWorkQueueSize; /** @brief max number of packages waiting in the work queue */ boost::scoped_ptr fMqServer; BRM::DBRM* fDbrm; + +public: + /** @brief the thread pool for processing dml packages + */ + static threadpool::ThreadPool fDmlPackagepool; }; /** @brief Thread to process a single dml package. @@ -207,12 +208,12 @@ private: // Used to serialize operations because the VSS can't handle inserts // or updates on the same block. // When an Insert, Update or Delete command arrives, we look here - // for the table oid. If found, wait until it is no onger here. + // for the table oid. If found, wait until it is no longer here. // If this transactionID (SCN) is < the transactionID in the table, don't delay // and hope for the best, as we're already out of order. // When the VSS is engineered to handle transactions out of order, all MCOL-140 // code is to be removed. - int synchTableAccess(); + int synchTableAccess(dmlpackage::CalpontDMLPackage* dmlPackage); int releaseTableAccess(); int forceReleaseTableAccess(); typedef iterable_queue tableAccessQueue_t; @@ -221,6 +222,35 @@ private: static boost::mutex tableOidMutex; public: static int clearTableAccess(); + + // MCOL-3296 Add a class to call synchTableAccess on creation and + // releaseTableAccess on destuction for exception safeness. + class SynchTable + { + public: + SynchTable() : fphp(NULL) {}; + SynchTable(PackageHandler* php, dmlpackage::CalpontDMLPackage* dmlPackage) + { + setPackage(php, dmlPackage); + } + ~SynchTable() + { + if (fphp) + fphp->releaseTableAccess(); + } + bool setPackage(PackageHandler* php, dmlpackage::CalpontDMLPackage* dmlPackage) + { + if (fphp) + fphp->releaseTableAccess(); + fphp = php; + if (fphp) + fphp->synchTableAccess(dmlPackage); + return true; + } + private: + PackageHandler* fphp; + }; + }; /** @brief processes dml packages as they arrive diff --git a/exemgr/main.cpp b/exemgr/main.cpp index e66d7783e..4b43f71bc 100644 --- a/exemgr/main.cpp +++ b/exemgr/main.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/oam/install_scripts/myCnf-include-args.text b/oam/install_scripts/myCnf-include-args.text index 40545c7ed..e6d2cd768 100644 --- a/oam/install_scripts/myCnf-include-args.text +++ b/oam/install_scripts/myCnf-include-args.text @@ -1,6 +1,6 @@ # List of my.cnf arguments that should be checked and saved during upgrade install # -infinidb_local_query +columnstore_local_query log-bin server-id max_length_for_sort_data @@ -15,4 +15,4 @@ collation-server init-connect binlog_format secure-auth -port \ No newline at end of file +port diff --git a/oam/oamcpp/liboamcpp.cpp b/oam/oamcpp/liboamcpp.cpp index f0429b588..8777e1589 100644 --- a/oam/oamcpp/liboamcpp.cpp +++ b/oam/oamcpp/liboamcpp.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/oam/oamcpp/liboamcpp.h b/oam/oamcpp/liboamcpp.h index 5d5a09c6c..04276081d 100644 --- a/oam/oamcpp/liboamcpp.h +++ b/oam/oamcpp/liboamcpp.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/oam/oamcpp/oamcache.cpp b/oam/oamcpp/oamcache.cpp index d8035bbf3..b25a72938 100644 --- a/oam/oamcpp/oamcache.cpp +++ b/oam/oamcpp/oamcache.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/oam/oamcpp/oamcache.h b/oam/oamcpp/oamcache.h index 1f64fbec8..013dcf85a 100644 --- a/oam/oamcpp/oamcache.h +++ b/oam/oamcpp/oamcache.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/oam/replaytxnlog/replaytxnlog.cpp b/oam/replaytxnlog/replaytxnlog.cpp index 0a1cdc9cc..78f4617d7 100644 --- a/oam/replaytxnlog/replaytxnlog.cpp +++ b/oam/replaytxnlog/replaytxnlog.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/oamapps/alarmmanager/alarmglobal.h b/oamapps/alarmmanager/alarmglobal.h index 343be54a7..554f71e5e 100644 --- a/oamapps/alarmmanager/alarmglobal.h +++ b/oamapps/alarmmanager/alarmglobal.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016 MariaDB Corporaton +/* Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/oamapps/mcsadmin/mcsadmin.cpp b/oamapps/mcsadmin/mcsadmin.cpp index 4f5d37cd9..b54e5e1b2 100644 --- a/oamapps/mcsadmin/mcsadmin.cpp +++ b/oamapps/mcsadmin/mcsadmin.cpp @@ -906,9 +906,9 @@ int processCommand(string* arguments) SendToWES(oam, bs); } #if _MSC_VER - if (_strnicmp(arguments[1].c_str(), "stop", 4) == 0)) + else if (_strnicmp(arguments[1].c_str(), "stop", 4) == 0)) #else - if (strncasecmp(arguments[1].c_str(), "stop", 4) == 0) + else if (strncasecmp(arguments[1].c_str(), "stop", 4) == 0) #endif { ByteStream bs; @@ -920,9 +920,9 @@ int processCommand(string* arguments) SendToWES(oam, bs); } #if _MSC_VER - if (_strnicmp(arguments[1].c_str(), "status", 6) == 0)) + else if (_strnicmp(arguments[1].c_str(), "status", 6) == 0)) #else - if (strncasecmp(arguments[1].c_str(), "status", 6) == 0) + else if (strncasecmp(arguments[1].c_str(), "status", 6) == 0) #endif { ByteStream bs; diff --git a/oamapps/mcsadmin/mcsadmin.h b/oamapps/mcsadmin/mcsadmin.h index 2843090b8..66fda95c8 100644 --- a/oamapps/mcsadmin/mcsadmin.h +++ b/oamapps/mcsadmin/mcsadmin.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/oamapps/postConfigure/amazonInstaller.cpp b/oamapps/postConfigure/amazonInstaller.cpp index ac46261c5..a4988b966 100644 --- a/oamapps/postConfigure/amazonInstaller.cpp +++ b/oamapps/postConfigure/amazonInstaller.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/oamapps/postConfigure/helpers.h b/oamapps/postConfigure/helpers.h index 8eb23bce0..ff5c6f82e 100644 --- a/oamapps/postConfigure/helpers.h +++ b/oamapps/postConfigure/helpers.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/oamapps/postConfigure/installer.cpp b/oamapps/postConfigure/installer.cpp index a0395bb57..85c8a30fa 100644 --- a/oamapps/postConfigure/installer.cpp +++ b/oamapps/postConfigure/installer.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/oamapps/postConfigure/mycnfUpgrade.cpp b/oamapps/postConfigure/mycnfUpgrade.cpp index 745da6179..53cb0ce3c 100644 --- a/oamapps/postConfigure/mycnfUpgrade.cpp +++ b/oamapps/postConfigure/mycnfUpgrade.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/oamapps/postConfigure/patchInstaller.cpp b/oamapps/postConfigure/patchInstaller.cpp index 9f36658c7..dd6d9ed35 100644 --- a/oamapps/postConfigure/patchInstaller.cpp +++ b/oamapps/postConfigure/patchInstaller.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/oamapps/postConfigure/postConfigure.cpp b/oamapps/postConfigure/postConfigure.cpp index 888db94f3..c23917b5a 100644 --- a/oamapps/postConfigure/postConfigure.cpp +++ b/oamapps/postConfigure/postConfigure.cpp @@ -215,13 +215,11 @@ typedef struct _thread_data_t int main(int argc, char* argv[]) { - // print a warning if this is a developer build #ifdef SKIP_OAM_INIT cout << "SKIP_OAM_INIT is set" << endl; sleep(2); #endif - Oam oam; string parentOAMModuleHostName; ChildModuleList childmodulelist; @@ -5397,7 +5395,7 @@ bool storageSetup(bool amazonInstall) if ( (glusterInstalled == "y" && singleServerInstall != "1") && hadoopInstalled == "y" ) { - cout << "There are 4 options when configuring the storage: internal, external, DataRedundancy, or hdfs" << endl << endl; + cout << "There are 5 options when configuring the storage: internal, external, DataRedundancy, or hdfs" << endl << endl; prompt = "Select the type of Data Storage [1=internal, 2=external, 3=DataRedundancy, 4=hdfs] (" + storageType + ") > "; } diff --git a/oamapps/resourceMonitor/resourceMonitor.cpp b/oamapps/resourceMonitor/resourceMonitor.cpp index dcda9940d..054e86c4c 100644 --- a/oamapps/resourceMonitor/resourceMonitor.cpp +++ b/oamapps/resourceMonitor/resourceMonitor.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/oamapps/serverMonitor/cpuMonitor.cpp b/oamapps/serverMonitor/cpuMonitor.cpp index 1f1d6b3b3..3d0c53a5f 100644 --- a/oamapps/serverMonitor/cpuMonitor.cpp +++ b/oamapps/serverMonitor/cpuMonitor.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/oamapps/serverMonitor/dbhealthMonitor.cpp b/oamapps/serverMonitor/dbhealthMonitor.cpp index fc1899b1f..3863b4964 100644 --- a/oamapps/serverMonitor/dbhealthMonitor.cpp +++ b/oamapps/serverMonitor/dbhealthMonitor.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/oamapps/serverMonitor/diskMonitor.cpp b/oamapps/serverMonitor/diskMonitor.cpp index b86a4837b..90c99e56d 100644 --- a/oamapps/serverMonitor/diskMonitor.cpp +++ b/oamapps/serverMonitor/diskMonitor.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -267,7 +267,7 @@ void diskMonitor() blksize = buf.f_bsize; blocks = buf.f_blocks; - freeblks = buf.f_bfree; + freeblks = buf.f_bavail; totalBlocks = blocks * blksize; free = freeblks * blksize; @@ -396,7 +396,7 @@ void diskMonitor() blksize = buf.f_bsize; blocks = buf.f_blocks; - freeblks = buf.f_bfree; + freeblks = buf.f_bavail; totalBlocks = blocks * blksize; free = freeblks * blksize; diff --git a/oamapps/serverMonitor/memoryMonitor.cpp b/oamapps/serverMonitor/memoryMonitor.cpp index b72d17e64..d96217d56 100644 --- a/oamapps/serverMonitor/memoryMonitor.cpp +++ b/oamapps/serverMonitor/memoryMonitor.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/oamapps/serverMonitor/msgProcessor.cpp b/oamapps/serverMonitor/msgProcessor.cpp index 1c7b928ee..fe330547e 100644 --- a/oamapps/serverMonitor/msgProcessor.cpp +++ b/oamapps/serverMonitor/msgProcessor.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/primitives/blockcache/blockrequestprocessor.cpp b/primitives/blockcache/blockrequestprocessor.cpp index 063d513f4..5463005ed 100644 --- a/primitives/blockcache/blockrequestprocessor.cpp +++ b/primitives/blockcache/blockrequestprocessor.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/primitives/blockcache/filebuffermgr.cpp b/primitives/blockcache/filebuffermgr.cpp index 013ef7603..fa7071942 100644 --- a/primitives/blockcache/filebuffermgr.cpp +++ b/primitives/blockcache/filebuffermgr.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/primitives/blockcache/iomanager.cpp b/primitives/blockcache/iomanager.cpp index 2bf4526e5..716b0b69d 100644 --- a/primitives/blockcache/iomanager.cpp +++ b/primitives/blockcache/iomanager.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/primitives/blockcache/stats.cpp b/primitives/blockcache/stats.cpp index 2d31016b2..3e74f9ad4 100644 --- a/primitives/blockcache/stats.cpp +++ b/primitives/blockcache/stats.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/primitives/primproc/batchprimitiveprocessor.cpp b/primitives/primproc/batchprimitiveprocessor.cpp index bd7c7b406..8a664bd16 100644 --- a/primitives/primproc/batchprimitiveprocessor.cpp +++ b/primitives/primproc/batchprimitiveprocessor.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016, 2017 MariaDB Corporaton + Copyright (C) 2016, 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/primitives/primproc/bppseeder.cpp b/primitives/primproc/bppseeder.cpp index 4b94d0c5c..aca03af25 100644 --- a/primitives/primproc/bppseeder.cpp +++ b/primitives/primproc/bppseeder.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/primitives/primproc/dictstep.cpp b/primitives/primproc/dictstep.cpp index 47bfeac25..abd99ada3 100644 --- a/primitives/primproc/dictstep.cpp +++ b/primitives/primproc/dictstep.cpp @@ -30,7 +30,6 @@ #include #include -#include #include "bpp.h" #include "primitiveserver.h" @@ -94,7 +93,6 @@ void DictStep::createCommand(ByteStream& bs) for (uint32_t i = 0; i < filterCount; i++) { bs >> strTmp; - boost::trim_right_if(strTmp, boost::is_any_of(" ")); //cout << " " << strTmp << endl; eqFilter->insert(strTmp); } diff --git a/primitives/primproc/primitiveserver.cpp b/primitives/primproc/primitiveserver.cpp index 54f4b7fb6..f64e38a4a 100644 --- a/primitives/primproc/primitiveserver.cpp +++ b/primitives/primproc/primitiveserver.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -28,7 +28,6 @@ #include #include #include -#include //#define NDEBUG #include #include @@ -1778,7 +1777,6 @@ private: for (i = 0; i < count; i++) { *bs >> str; - boost::trim_right_if(str, boost::is_any_of(" ")); filter->insert(str); } diff --git a/primitives/primproc/primitiveserver.h b/primitives/primproc/primitiveserver.h index f212fd9fd..69f0afe11 100644 --- a/primitives/primproc/primitiveserver.h +++ b/primitives/primproc/primitiveserver.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/primitives/primproc/primproc.cpp b/primitives/primproc/primproc.cpp index 79222f216..46d6cb03e 100644 --- a/primitives/primproc/primproc.cpp +++ b/primitives/primproc/primproc.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/procmgr/main.cpp b/procmgr/main.cpp index f27cce2f8..043528817 100644 --- a/procmgr/main.cpp +++ b/procmgr/main.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/procmgr/processmanager.cpp b/procmgr/processmanager.cpp index f4376e6cd..3c531359f 100644 --- a/procmgr/processmanager.cpp +++ b/procmgr/processmanager.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/procmgr/processmanager.h b/procmgr/processmanager.h index 8dc39a540..bb0766881 100644 --- a/procmgr/processmanager.h +++ b/procmgr/processmanager.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/procmon/main.cpp b/procmon/main.cpp index 7b6b02473..7387c4512 100644 --- a/procmon/main.cpp +++ b/procmon/main.cpp @@ -394,12 +394,12 @@ int main(int argc, char** argv) // check if standby never replied, if so, shutdown if ( count >= 120 ) { - log.writeLog(__LINE__, "Standby PM not responding, infinidb shutting down", LOG_TYPE_CRITICAL); + log.writeLog(__LINE__, "Standby PM not responding, ColumnStore shutting down", LOG_TYPE_CRITICAL); //Set the alarm // aMonitor.sendAlarm(config.moduleName().c_str(), STARTUP_DIAGNOTICS_FAILURE, SET); // sleep (1); - string cmd = startup::StartUp::installDir() + "/bin/infinidb stop > /dev/null 2>&1"; + string cmd = startup::StartUp::installDir() + "/bin/columnstore stop > /dev/null 2>&1"; system(cmd.c_str()); } diff --git a/procmon/processmonitor.cpp b/procmon/processmonitor.cpp index 010ad1d3d..421f23690 100644 --- a/procmon/processmonitor.cpp +++ b/procmon/processmonitor.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -5185,11 +5185,11 @@ int ProcessMonitor::changeMyCnf(std::string type) // set local query flag if on pm if ( (PMwithUM == "y") && config.moduleType() == "pm" ) { - pos = buf.find("infinidb_local_query", 0); + pos = buf.find("columnstore_local_query", 0); if ( pos != string::npos ) { - buf = "infinidb_local_query=1"; + buf = "columnstore_local_query=1"; string command = "SET GLOBAL " + buf + ";"; @@ -5205,11 +5205,11 @@ int ProcessMonitor::changeMyCnf(std::string type) else { // disable, if needed - pos = buf.find("infinidb_local_query", 0); + pos = buf.find("columnstore_local_query", 0); if ( pos != string::npos ) { - buf = "infinidb_local_query=0"; + buf = "columnstore_local_query=0"; string command = "SET GLOBAL " + buf + ";"; int ret = runMariaDBCommandLine(command); diff --git a/tools/clearShm/main.cpp b/tools/clearShm/main.cpp index 4ab97c2d6..cf3a7e92b 100644 --- a/tools/clearShm/main.cpp +++ b/tools/clearShm/main.cpp @@ -123,9 +123,9 @@ void semDoit(key_t sem_key, const string& label) void usage() { cout << "usage: clearShm [-cvnh]" << endl; - cout << " delete all InfiniDB shared memory data" << endl; + cout << " delete all ColumnStore shared memory data" << endl; cout << " -h display this help" << endl; - cout << " -c only clear InfiniDB Engine data, leave OAM intact" << endl; + cout << " -c only clear ColumnStore Engine data, leave OAM intact" << endl; cout << " -v verbose output" << endl; cout << " -n don't actually delete anything (implies -v)" << endl; } diff --git a/tools/cleartablelock/cleartablelock.cpp b/tools/cleartablelock/cleartablelock.cpp index df660ec5d..3a332be22 100644 --- a/tools/cleartablelock/cleartablelock.cpp +++ b/tools/cleartablelock/cleartablelock.cpp @@ -509,7 +509,7 @@ int main(int argc, char** argv) if (brm.getSystemReady() < 1) { - std::cout << "System is not ready. Verify that InfiniDB " + std::cout << "System is not ready. Verify that ColumnStore " "is up and ready before running this program" << std::endl; return 1; } diff --git a/tools/configMgt/autoConfigure.cpp b/tools/configMgt/autoConfigure.cpp index 10d7318ee..7e910904b 100644 --- a/tools/configMgt/autoConfigure.cpp +++ b/tools/configMgt/autoConfigure.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -360,7 +360,19 @@ int main(int argc, char* argv[]) exit(-1); } - //setup System Language + // WaitPeriod + try + { + string waitPeriod = sysConfigOld->getConfig(SystemSection, "WaitPeriod"); + if (waitPeriod.length() > 0) + { + sysConfigNew->setConfig(SystemSection, "WaitPeriod", waitPeriod); + } + } + catch (...) + { } + + //setup System Language string systemLang = "C"; try diff --git a/tools/configMgt/autoInstaller.cpp b/tools/configMgt/autoInstaller.cpp index 7dfb934e9..74f697af7 100644 --- a/tools/configMgt/autoInstaller.cpp +++ b/tools/configMgt/autoInstaller.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/tools/configMgt/configure.cpp b/tools/configMgt/configure.cpp index 22c4ea0c4..7c600c2bb 100644 --- a/tools/configMgt/configure.cpp +++ b/tools/configMgt/configure.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/tools/dbloadxml/colxml.cpp b/tools/dbloadxml/colxml.cpp index 1ac41d7bf..778d095e7 100644 --- a/tools/dbloadxml/colxml.cpp +++ b/tools/dbloadxml/colxml.cpp @@ -146,7 +146,7 @@ int main(int argc, char** argv) if (dbrm.getSystemReady() < 1) { std::string errMsg( - "System is not ready. Verify that InfiniDB is up and ready " + "System is not ready. Verify that ColumnStore is up and ready " "before running colxml."); if (bUseLogFile) diff --git a/utils/common/crashtrace.cpp b/utils/common/crashtrace.cpp index 2b39ed07c..afa593d38 100644 --- a/utils/common/crashtrace.cpp +++ b/utils/common/crashtrace.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 MariaDB Corporaton +/* Copyright (C) 2018 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/common/crashtrace.h b/utils/common/crashtrace.h index 3b9cb4036..230640185 100644 --- a/utils/common/crashtrace.h +++ b/utils/common/crashtrace.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 MariaDB Corporaton +/* Copyright (C) 2018 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/common/nullvaluemanip.cpp b/utils/common/nullvaluemanip.cpp index 44ee2273a..3b4255dea 100644 --- a/utils/common/nullvaluemanip.cpp +++ b/utils/common/nullvaluemanip.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/common/threadnaming.cpp b/utils/common/threadnaming.cpp index 2f4dda91f..65498ab61 100644 --- a/utils/common/threadnaming.cpp +++ b/utils/common/threadnaming.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 MariaDB Corporaton +/* Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/common/threadnaming.h b/utils/common/threadnaming.h index 1682b7045..4cdf28d20 100644 --- a/utils/common/threadnaming.h +++ b/utils/common/threadnaming.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 MariaDB Corporaton +/* Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/dataconvert/dataconvert.cpp b/utils/dataconvert/dataconvert.cpp index b17b430fb..d9b0543e6 100644 --- a/utils/dataconvert/dataconvert.cpp +++ b/utils/dataconvert/dataconvert.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -53,7 +53,7 @@ using namespace logging; namespace { -const int64_t infinidb_precision[19] = +const int64_t columnstore_precision[19] = { 0, 9, @@ -415,7 +415,7 @@ int64_t number_int_value(const string& data, (ct.colDataType == CalpontSystemCatalog::UDECIMAL) || (ct.scale > 0)) { - int64_t rangeUp = infinidb_precision[ct.precision]; + int64_t rangeUp = columnstore_precision[ct.precision]; int64_t rangeLow = -rangeUp; if (intVal > rangeUp) diff --git a/utils/funcexp/func_abs.cpp b/utils/funcexp/func_abs.cpp index 4cef9a791..7b04408ba 100644 --- a/utils/funcexp/func_abs.cpp +++ b/utils/funcexp/func_abs.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/func_between.cpp b/utils/funcexp/func_between.cpp index 44908ad4b..8330c4fc0 100644 --- a/utils/funcexp/func_between.cpp +++ b/utils/funcexp/func_between.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/func_case.cpp b/utils/funcexp/func_case.cpp index 22705cdd0..5c429a669 100644 --- a/utils/funcexp/func_case.cpp +++ b/utils/funcexp/func_case.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/func_cast.cpp b/utils/funcexp/func_cast.cpp index d2db69144..18a9b19aa 100644 --- a/utils/funcexp/func_cast.cpp +++ b/utils/funcexp/func_cast.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -1168,7 +1168,7 @@ IDB_Decimal Func_cast_decimal::getDecimalVal(Row& row, int32_t decimals = parm[1]->data()->getIntVal(row, isNull); int64_t max_length = parm[2]->data()->getIntVal(row, isNull); - // As of 2.0, max length infiniDB can support is 18 + // As of 2.0, max length columnStore can support is 18 // decimal(0,0) is valid, and no limit on integer number if (max_length > 18 || max_length <= 0) max_length = 18; diff --git a/utils/funcexp/func_ceil.cpp b/utils/funcexp/func_ceil.cpp index cd76df3e3..b1f886166 100644 --- a/utils/funcexp/func_ceil.cpp +++ b/utils/funcexp/func_ceil.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/func_coalesce.cpp b/utils/funcexp/func_coalesce.cpp index 4c3faca85..1f46a15b3 100644 --- a/utils/funcexp/func_coalesce.cpp +++ b/utils/funcexp/func_coalesce.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/func_exp.cpp b/utils/funcexp/func_exp.cpp index 6decbe652..217102daf 100644 --- a/utils/funcexp/func_exp.cpp +++ b/utils/funcexp/func_exp.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/func_floor.cpp b/utils/funcexp/func_floor.cpp index 2ec854b8c..50dd3d919 100644 --- a/utils/funcexp/func_floor.cpp +++ b/utils/funcexp/func_floor.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/func_from_unixtime.cpp b/utils/funcexp/func_from_unixtime.cpp index 18dba41c8..8f5f3d051 100644 --- a/utils/funcexp/func_from_unixtime.cpp +++ b/utils/funcexp/func_from_unixtime.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/func_greatest.cpp b/utils/funcexp/func_greatest.cpp index 388a35f20..e064eacb3 100644 --- a/utils/funcexp/func_greatest.cpp +++ b/utils/funcexp/func_greatest.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/func_hex.cpp b/utils/funcexp/func_hex.cpp index 7f7c7eff9..42e6b04d2 100644 --- a/utils/funcexp/func_hex.cpp +++ b/utils/funcexp/func_hex.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/func_if.cpp b/utils/funcexp/func_if.cpp index cc46f4a27..b17ad7317 100644 --- a/utils/funcexp/func_if.cpp +++ b/utils/funcexp/func_if.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/func_ifnull.cpp b/utils/funcexp/func_ifnull.cpp index 6309171fd..e479ba69c 100644 --- a/utils/funcexp/func_ifnull.cpp +++ b/utils/funcexp/func_ifnull.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/func_in.cpp b/utils/funcexp/func_in.cpp index 5b1aa015c..ab691ed1f 100644 --- a/utils/funcexp/func_in.cpp +++ b/utils/funcexp/func_in.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/func_isnull.cpp b/utils/funcexp/func_isnull.cpp index ebe1c2d88..ffda2415d 100644 --- a/utils/funcexp/func_isnull.cpp +++ b/utils/funcexp/func_isnull.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/func_least.cpp b/utils/funcexp/func_least.cpp index 3675e940d..5f97ee892 100644 --- a/utils/funcexp/func_least.cpp +++ b/utils/funcexp/func_least.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/func_math.cpp b/utils/funcexp/func_math.cpp index ff4d908da..6ef3868c2 100644 --- a/utils/funcexp/func_math.cpp +++ b/utils/funcexp/func_math.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/func_mod.cpp b/utils/funcexp/func_mod.cpp index 4cbdf23af..23e4df008 100644 --- a/utils/funcexp/func_mod.cpp +++ b/utils/funcexp/func_mod.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/func_nullif.cpp b/utils/funcexp/func_nullif.cpp index 224c2d435..a81b439dc 100644 --- a/utils/funcexp/func_nullif.cpp +++ b/utils/funcexp/func_nullif.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/func_pow.cpp b/utils/funcexp/func_pow.cpp index f94432b6d..4e07c8410 100644 --- a/utils/funcexp/func_pow.cpp +++ b/utils/funcexp/func_pow.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/func_round.cpp b/utils/funcexp/func_round.cpp index c57dda167..805f87e56 100644 --- a/utils/funcexp/func_round.cpp +++ b/utils/funcexp/func_round.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/func_substring_index.cpp b/utils/funcexp/func_substring_index.cpp index 04d4d9b12..a3b5c342e 100644 --- a/utils/funcexp/func_substring_index.cpp +++ b/utils/funcexp/func_substring_index.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/func_timediff.cpp b/utils/funcexp/func_timediff.cpp index 1254f2d1b..0e16e3a4f 100644 --- a/utils/funcexp/func_timediff.cpp +++ b/utils/funcexp/func_timediff.cpp @@ -118,7 +118,10 @@ string Func_timediff::getStrVal(rowgroup::Row& row, case execplan::CalpontSystemCatalog::TIME: case execplan::CalpontSystemCatalog::DATETIME: - if (type1 != type2) + // Diff between time and datetime returns NULL in MariaDB + if ((type2 == execplan::CalpontSystemCatalog::TIME || + type2 == execplan::CalpontSystemCatalog::DATETIME) && + type1 != type2) { isNull = true; break; diff --git a/utils/funcexp/func_truncate.cpp b/utils/funcexp/func_truncate.cpp index a2f73753a..441047f74 100644 --- a/utils/funcexp/func_truncate.cpp +++ b/utils/funcexp/func_truncate.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/funcexp.cpp b/utils/funcexp/funcexp.cpp index c119dc549..e92bbcbcc 100644 --- a/utils/funcexp/funcexp.cpp +++ b/utils/funcexp/funcexp.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/funchelpers.h b/utils/funcexp/funchelpers.h index e1290d230..e579ebb57 100644 --- a/utils/funcexp/funchelpers.h +++ b/utils/funcexp/funchelpers.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/functor.cpp b/utils/funcexp/functor.cpp index 28fd64cbe..06999c9fd 100644 --- a/utils/funcexp/functor.cpp +++ b/utils/funcexp/functor.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/functor.h b/utils/funcexp/functor.h index 8eb494313..357d8639d 100644 --- a/utils/funcexp/functor.h +++ b/utils/funcexp/functor.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/functor_all.h b/utils/funcexp/functor_all.h index a1daa0687..155e00656 100644 --- a/utils/funcexp/functor_all.h +++ b/utils/funcexp/functor_all.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/functor_dtm.h b/utils/funcexp/functor_dtm.h index fddd0a002..f9b61ee80 100644 --- a/utils/funcexp/functor_dtm.h +++ b/utils/funcexp/functor_dtm.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/functor_export.h b/utils/funcexp/functor_export.h index af7ca6cee..3d7405cc2 100644 --- a/utils/funcexp/functor_export.h +++ b/utils/funcexp/functor_export.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/functor_int.h b/utils/funcexp/functor_int.h index e5b0093a9..78655a892 100644 --- a/utils/funcexp/functor_int.h +++ b/utils/funcexp/functor_int.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/functor_real.h b/utils/funcexp/functor_real.h index a5ae4d317..717e2208e 100644 --- a/utils/funcexp/functor_real.h +++ b/utils/funcexp/functor_real.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/funcexp/functor_str.h b/utils/funcexp/functor_str.h index 2f772974a..24337aab9 100644 --- a/utils/funcexp/functor_str.h +++ b/utils/funcexp/functor_str.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/joiner/joinpartition.cpp b/utils/joiner/joinpartition.cpp index 4982ed750..e3b763120 100644 --- a/utils/joiner/joinpartition.cpp +++ b/utils/joiner/joinpartition.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/joiner/tuplejoiner.cpp b/utils/joiner/tuplejoiner.cpp index ff64b8283..f8ac47b98 100644 --- a/utils/joiner/tuplejoiner.cpp +++ b/utils/joiner/tuplejoiner.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/joiner/tuplejoiner.h b/utils/joiner/tuplejoiner.h index 7302876e0..83d68dfca 100644 --- a/utils/joiner/tuplejoiner.h +++ b/utils/joiner/tuplejoiner.h @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/loggingcpp/ErrorMessage.txt b/utils/loggingcpp/ErrorMessage.txt index a6dd3b6e0..814a51310 100755 --- a/utils/loggingcpp/ErrorMessage.txt +++ b/utils/loggingcpp/ErrorMessage.txt @@ -86,13 +86,13 @@ 2045 ERR_PRIMPROC_DOWN At least one PrimProc closed the connection unexpectedly. 2046 ERR_READ_INPUT_DATALIST Input datalist read error. -2047 ERR_LOCAL_QUERY_UM Query attempted on UM (no PM) with infinidb_local_query set. +2047 ERR_LOCAL_QUERY_UM Query attempted on UM (no PM) with columnstore_local_query set. # disk-based join runtime errors from supported queries 2048 ERR_DBJ_FILE_IO_ERROR There was an IO error doing a disk-based join. 2049 ERR_DBJ_UNKNOWN_ERROR An unknown error error occured doing a disk-based join. Check the error log & contact support. -2050 ERR_DBJ_DISK_USAGE_LIMIT This query exceeded the temp disk usage limit. Raise infinidb_diskjoin_smallsidelimit if possible and try again. -2051 ERR_DBJ_DATA_DISTRIBUTION The data distribution in this query overflowed a disk-based join bucket. If possible, raise infinidb_diskjoin_bucketsize and try again. +2050 ERR_DBJ_DISK_USAGE_LIMIT This query exceeded the temp disk usage limit. Raise columnstore_diskjoin_smallsidelimit if possible and try again. +2051 ERR_DBJ_DATA_DISTRIBUTION The data distribution in this query overflowed a disk-based join bucket. If possible, raise columnstore_diskjoin_bucketsize and try again. 2052 INFO_SWITCHING_TO_DJS Out of UM memory, switching to disk-based join. 2053 ERR_FUNC_OUT_OF_RANGE_RESULT The result is out of range for function %1% using value(s): %2% %3% @@ -141,7 +141,7 @@ 4014 ERR_CONSTRAINTS Constraints are currently not supported in Columnstore. 4015 ERR_NOT_NULL_CONSTRAINTS Column '%1%' cannot be null. 4016 ERR_DML_DDL_SLAVE DML and DDL statements for Columnstore tables can only be run from the replication master. -4017 ERR_DML_DDL_LOCAL DML and DDL statements are not allowed when infinidb_local_query is greater than 0. +4017 ERR_DML_DDL_LOCAL DML and DDL statements are not allowed when columnstore_local_query is greater than 0. 4018 ERR_NON_SUPPORT_SYNTAX The statement is not supported in Columnstore. # UDF diff --git a/utils/loggingcpp/messagelog.cpp b/utils/loggingcpp/messagelog.cpp index a1dd850e2..6ddda51dd 100644 --- a/utils/loggingcpp/messagelog.cpp +++ b/utils/loggingcpp/messagelog.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/loggingcpp/tdriver.cpp b/utils/loggingcpp/tdriver.cpp index 16b98c5da..3e1342afa 100644 --- a/utils/loggingcpp/tdriver.cpp +++ b/utils/loggingcpp/tdriver.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/messageqcpp/bytestream.cpp b/utils/messageqcpp/bytestream.cpp index 003c35fd4..6ecbf625d 100644 --- a/utils/messageqcpp/bytestream.cpp +++ b/utils/messageqcpp/bytestream.cpp @@ -1,6 +1,6 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/messageqcpp/bytestream.h b/utils/messageqcpp/bytestream.h index 80185f524..316d9b0a1 100644 --- a/utils/messageqcpp/bytestream.h +++ b/utils/messageqcpp/bytestream.h @@ -1,6 +1,6 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2019 MariaDB Corporaton + Copyright (C) 2019 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/messageqcpp/messagequeuepool.cpp b/utils/messageqcpp/messagequeuepool.cpp index f986f734f..f3cbcb2bc 100644 --- a/utils/messageqcpp/messagequeuepool.cpp +++ b/utils/messageqcpp/messagequeuepool.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/messageqcpp/messagequeuepool.h b/utils/messageqcpp/messagequeuepool.h index db49d8e5c..553328e7b 100644 --- a/utils/messageqcpp/messagequeuepool.h +++ b/utils/messageqcpp/messagequeuepool.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/regr/corr.cpp b/utils/regr/corr.cpp index ac69357df..ac8c090bf 100644 --- a/utils/regr/corr.cpp +++ b/utils/regr/corr.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/regr/corr.h b/utils/regr/corr.h index 389b61195..850690da4 100644 --- a/utils/regr/corr.h +++ b/utils/regr/corr.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/regr/covar_pop.cpp b/utils/regr/covar_pop.cpp index 672da9d75..f3794f89e 100644 --- a/utils/regr/covar_pop.cpp +++ b/utils/regr/covar_pop.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/regr/covar_pop.h b/utils/regr/covar_pop.h index c3f6dde4a..dd675c7fa 100644 --- a/utils/regr/covar_pop.h +++ b/utils/regr/covar_pop.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/regr/covar_samp.cpp b/utils/regr/covar_samp.cpp index 81e9fc212..98fa99fe9 100644 --- a/utils/regr/covar_samp.cpp +++ b/utils/regr/covar_samp.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/regr/covar_samp.h b/utils/regr/covar_samp.h index fe0352fe8..f1511a364 100644 --- a/utils/regr/covar_samp.h +++ b/utils/regr/covar_samp.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/regr/regr_avgx.cpp b/utils/regr/regr_avgx.cpp index c27d075ad..bec098116 100644 --- a/utils/regr/regr_avgx.cpp +++ b/utils/regr/regr_avgx.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/regr/regr_avgx.h b/utils/regr/regr_avgx.h index e76ecf56c..58138eff3 100644 --- a/utils/regr/regr_avgx.h +++ b/utils/regr/regr_avgx.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/regr/regr_avgy.cpp b/utils/regr/regr_avgy.cpp index f22959354..512e3e48d 100644 --- a/utils/regr/regr_avgy.cpp +++ b/utils/regr/regr_avgy.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/regr/regr_avgy.h b/utils/regr/regr_avgy.h index 9e425a7bd..957becdd7 100644 --- a/utils/regr/regr_avgy.h +++ b/utils/regr/regr_avgy.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/regr/regr_count.cpp b/utils/regr/regr_count.cpp index 8b5993d33..7d893e16f 100644 --- a/utils/regr/regr_count.cpp +++ b/utils/regr/regr_count.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/regr/regr_count.h b/utils/regr/regr_count.h index 0fa140d56..b63a2d582 100644 --- a/utils/regr/regr_count.h +++ b/utils/regr/regr_count.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/regr/regr_intercept.cpp b/utils/regr/regr_intercept.cpp index 9b457243c..5e05eea19 100644 --- a/utils/regr/regr_intercept.cpp +++ b/utils/regr/regr_intercept.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/regr/regr_intercept.h b/utils/regr/regr_intercept.h index 50c7fbdd9..2ccd272f5 100644 --- a/utils/regr/regr_intercept.h +++ b/utils/regr/regr_intercept.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/regr/regr_r2.cpp b/utils/regr/regr_r2.cpp index 60bcad65c..2f28afe3e 100644 --- a/utils/regr/regr_r2.cpp +++ b/utils/regr/regr_r2.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/regr/regr_r2.h b/utils/regr/regr_r2.h index fac04eac8..26082d979 100644 --- a/utils/regr/regr_r2.h +++ b/utils/regr/regr_r2.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/regr/regr_slope.cpp b/utils/regr/regr_slope.cpp index 17e662f2c..2a3445da4 100644 --- a/utils/regr/regr_slope.cpp +++ b/utils/regr/regr_slope.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/regr/regr_slope.h b/utils/regr/regr_slope.h index d32223ae9..d14639cf1 100644 --- a/utils/regr/regr_slope.h +++ b/utils/regr/regr_slope.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/regr/regr_sxx.cpp b/utils/regr/regr_sxx.cpp index 2338d4436..0903148dc 100644 --- a/utils/regr/regr_sxx.cpp +++ b/utils/regr/regr_sxx.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/regr/regr_sxx.h b/utils/regr/regr_sxx.h index 82ec7e154..2f180483c 100644 --- a/utils/regr/regr_sxx.h +++ b/utils/regr/regr_sxx.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/regr/regr_sxy.cpp b/utils/regr/regr_sxy.cpp index daef4333e..092d3c375 100644 --- a/utils/regr/regr_sxy.cpp +++ b/utils/regr/regr_sxy.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/regr/regr_sxy.h b/utils/regr/regr_sxy.h index 47e6c30e6..83517e113 100644 --- a/utils/regr/regr_sxy.h +++ b/utils/regr/regr_sxy.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/regr/regr_syy.cpp b/utils/regr/regr_syy.cpp index 6d803d992..0fc3102ed 100644 --- a/utils/regr/regr_syy.cpp +++ b/utils/regr/regr_syy.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/regr/regr_syy.h b/utils/regr/regr_syy.h index 26c8cc1e7..05d7e5f8f 100644 --- a/utils/regr/regr_syy.h +++ b/utils/regr/regr_syy.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/rowgroup/rowgroup.cpp b/utils/rowgroup/rowgroup.cpp index e16f12c30..27d530343 100644 --- a/utils/rowgroup/rowgroup.cpp +++ b/utils/rowgroup/rowgroup.cpp @@ -1591,6 +1591,7 @@ RowGroup& RowGroup::operator+=(const RowGroup& rhs) } hasLongStringField = rhs.hasLongStringField || hasLongStringField; + useStringTable = rhs.useStringTable || useStringTable; offsets = (useStringTable ? &stOffsets[0] : &oldOffsets[0]); return *this; diff --git a/utils/rowgroup/rowgroup.h b/utils/rowgroup/rowgroup.h index d496cbcb0..0990384cb 100644 --- a/utils/rowgroup/rowgroup.h +++ b/utils/rowgroup/rowgroup.h @@ -1771,7 +1771,8 @@ inline void copyRow(const Row& in, Row* out, uint32_t colCount) { if (UNLIKELY(in.getColTypes()[i] == execplan::CalpontSystemCatalog::VARBINARY || in.getColTypes()[i] == execplan::CalpontSystemCatalog::BLOB || - in.getColTypes()[i] == execplan::CalpontSystemCatalog::TEXT)) + in.getColTypes()[i] == execplan::CalpontSystemCatalog::TEXT || + in.getColTypes()[i] == execplan::CalpontSystemCatalog::CLOB)) out->setVarBinaryField(in.getVarBinaryStringField(i), i); else if (UNLIKELY(in.isLongString(i))) //out->setStringField(in.getStringField(i), i); diff --git a/utils/startup/installdir.cpp b/utils/startup/installdir.cpp index 5a15a651b..b49bbc743 100644 --- a/utils/startup/installdir.cpp +++ b/utils/startup/installdir.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/testbc/stats.cpp b/utils/testbc/stats.cpp index ff1886233..1dd2442e3 100644 --- a/utils/testbc/stats.cpp +++ b/utils/testbc/stats.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/threadpool/threadpool.cpp b/utils/threadpool/threadpool.cpp index 589fb6dcc..e62de7769 100644 --- a/utils/threadpool/threadpool.cpp +++ b/utils/threadpool/threadpool.cpp @@ -409,6 +409,24 @@ void ThreadPool::beginThread() throw() --fIssued; --waitingFunctorsSize; fWaitingFunctors.erase(todo); + if (fDebug) + { + ostringstream oss; + oss << "Ending thread " << " on " << fName + << " max " << fMaxThreads + << " queue " << fQueueSize + << " threads " << fThreadCount + << " running " << fIssued + << " waiting " << (waitingFunctorsSize - fIssued) + << " total " << waitingFunctorsSize; + logging::Message::Args args; + logging::Message message(0); + args.add(oss.str()); + message.format( args ); + logging::LoggingID lid(22); + logging::MessageLog ml(lid); + ml.logWarningMessage( message ); + } } timeout = boost::get_system_time() + boost::posix_time::minutes(10); @@ -536,6 +554,8 @@ void ThreadPoolMonitor::operator()() << setw(4) << tv.tv_usec / 100 << " Name " << fPool->fName << " Active " << fPool->waitingFunctorsSize + << " running " << fPool->fIssued + << " waiting " << (fPool->waitingFunctorsSize - fPool->fIssued) << " ThdCnt " << fPool->fThreadCount << " Max " << fPool->fMaxThreads << " Q " << fPool->fQueueSize diff --git a/utils/udfsdk/allnull.cpp b/utils/udfsdk/allnull.cpp index ee6669789..79f978124 100644 --- a/utils/udfsdk/allnull.cpp +++ b/utils/udfsdk/allnull.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/udfsdk/allnull.h b/utils/udfsdk/allnull.h index 40e5ce709..203bfbbaf 100644 --- a/utils/udfsdk/allnull.h +++ b/utils/udfsdk/allnull.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/udfsdk/avg_mode.cpp b/utils/udfsdk/avg_mode.cpp index 317ccce93..87b2d6b2e 100644 --- a/utils/udfsdk/avg_mode.cpp +++ b/utils/udfsdk/avg_mode.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/udfsdk/avg_mode.h b/utils/udfsdk/avg_mode.h index d37c3b83b..da0962c7f 100644 --- a/utils/udfsdk/avg_mode.h +++ b/utils/udfsdk/avg_mode.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/udfsdk/avgx.cpp b/utils/udfsdk/avgx.cpp index a7ee4eb75..b0c666541 100644 --- a/utils/udfsdk/avgx.cpp +++ b/utils/udfsdk/avgx.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/udfsdk/avgx.h b/utils/udfsdk/avgx.h index 0268df021..61d3d02b6 100644 --- a/utils/udfsdk/avgx.h +++ b/utils/udfsdk/avgx.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/udfsdk/distinct_count.cpp b/utils/udfsdk/distinct_count.cpp index 11c2ce776..e622bf324 100644 --- a/utils/udfsdk/distinct_count.cpp +++ b/utils/udfsdk/distinct_count.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/udfsdk/distinct_count.h b/utils/udfsdk/distinct_count.h index 7ad43f952..5e0fa84ac 100644 --- a/utils/udfsdk/distinct_count.h +++ b/utils/udfsdk/distinct_count.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/udfsdk/mcsv1_udaf.cpp b/utils/udfsdk/mcsv1_udaf.cpp index 4dc30a3ef..b16036e05 100644 --- a/utils/udfsdk/mcsv1_udaf.cpp +++ b/utils/udfsdk/mcsv1_udaf.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/udfsdk/mcsv1_udaf.h b/utils/udfsdk/mcsv1_udaf.h index d55002c49..79d40ccf5 100644 --- a/utils/udfsdk/mcsv1_udaf.h +++ b/utils/udfsdk/mcsv1_udaf.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/udfsdk/median.cpp b/utils/udfsdk/median.cpp index 2d4750e4d..3ef7a0187 100644 --- a/utils/udfsdk/median.cpp +++ b/utils/udfsdk/median.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/udfsdk/median.h b/utils/udfsdk/median.h index ead9eede4..5ae3025dd 100644 --- a/utils/udfsdk/median.h +++ b/utils/udfsdk/median.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/udfsdk/ssq.cpp b/utils/udfsdk/ssq.cpp index 4886acdb1..9b4c411aa 100644 --- a/utils/udfsdk/ssq.cpp +++ b/utils/udfsdk/ssq.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/utils/udfsdk/ssq.h b/utils/udfsdk/ssq.h index 58d42084b..c291d7fd1 100644 --- a/utils/udfsdk/ssq.h +++ b/utils/udfsdk/ssq.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 MariaDB Corporaton +/* Copyright (C) 2017 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/versioning/BRM/reset_locks.cpp b/versioning/BRM/reset_locks.cpp index 390942ca3..293e512b1 100644 --- a/versioning/BRM/reset_locks.cpp +++ b/versioning/BRM/reset_locks.cpp @@ -53,7 +53,7 @@ bool sFlg; void usage() { cout << "usage: reset_locks [-vnh]" << endl; - cout << " reset all InfiniDB shared memory locks" << endl; + cout << " reset all ColumnStore shared memory locks" << endl; cout << " -h display this help" << endl; cout << " -v verbose output" << endl; cout << " -s skip session mgr resets" << endl; diff --git a/versioning/BRM/slavecomm.cpp b/versioning/BRM/slavecomm.cpp index 278b214f7..d2106d0dd 100644 --- a/versioning/BRM/slavecomm.cpp +++ b/versioning/BRM/slavecomm.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/versioning/BRM/tracer.cpp b/versioning/BRM/tracer.cpp index d2cd35ccc..869b82197 100644 --- a/versioning/BRM/tracer.cpp +++ b/versioning/BRM/tracer.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/writeengine/bulk/cpimport.cpp b/writeengine/bulk/cpimport.cpp index edf1a8aa7..129ab0beb 100644 --- a/writeengine/bulk/cpimport.cpp +++ b/writeengine/bulk/cpimport.cpp @@ -1165,7 +1165,7 @@ int main(int argc, char** argv) if (!BRMWrapper::getInstance()->isSystemReady()) { startupError( std::string( - "System is not ready. Verify that InfiniDB is up and ready " + "System is not ready. Verify that ColumnStore is up and ready " "before running cpimport."), false ); } diff --git a/writeengine/bulk/we_bulkloadbuffer.cpp b/writeengine/bulk/we_bulkloadbuffer.cpp index 86124a783..fe0eaa70f 100644 --- a/writeengine/bulk/we_bulkloadbuffer.cpp +++ b/writeengine/bulk/we_bulkloadbuffer.cpp @@ -570,14 +570,16 @@ void BulkLoadBuffer::convert(char* field, int fieldLength, } // Swap byte order before comparing character string - int64_t binChar = static_cast( uint64ToStr( - *(reinterpret_cast(charTmpBuf)) ) ); + // Compare must be unsigned + uint64_t compChar = uint64ToStr( *(reinterpret_cast(charTmpBuf)) ); + int64_t binChar = static_cast( compChar ); // Update min/max range - if (binChar < bufStats.minBufferVal) + uint64_t minVal = static_cast( bufStats.minBufferVal ); + uint64_t maxVal = static_cast( bufStats.maxBufferVal ); + if (compChar < minVal) bufStats.minBufferVal = binChar; - - if (binChar > bufStats.maxBufferVal) + if (compChar > maxVal) bufStats.maxBufferVal = binChar; pVal = charTmpBuf; diff --git a/writeengine/dictionary/we_dctnry.cpp b/writeengine/dictionary/we_dctnry.cpp index 460a48191..40d48f8f2 100644 --- a/writeengine/dictionary/we_dctnry.cpp +++ b/writeengine/dictionary/we_dctnry.cpp @@ -423,8 +423,7 @@ int Dctnry::closeDctnry(bool realClose) return rc; //cout <<"Init called! m_dctnryOID =" << m_dctnryOID << endl; - if (realClose) - freeStringCache( ); + freeStringCache( ); return NO_ERROR; } diff --git a/writeengine/redistribute/we_redistributecontrol.cpp b/writeengine/redistribute/we_redistributecontrol.cpp index c28ebfef5..c0c975cb3 100644 --- a/writeengine/redistribute/we_redistributecontrol.cpp +++ b/writeengine/redistribute/we_redistributecontrol.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/writeengine/redistribute/we_redistributecontrolthread.cpp b/writeengine/redistribute/we_redistributecontrolthread.cpp index 70b5d1e2d..90f4fbaf9 100644 --- a/writeengine/redistribute/we_redistributecontrolthread.cpp +++ b/writeengine/redistribute/we_redistributecontrolthread.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/writeengine/splitter/we_cmdargs.cpp b/writeengine/splitter/we_cmdargs.cpp index 7ed626f26..8c520924d 100644 --- a/writeengine/splitter/we_cmdargs.cpp +++ b/writeengine/splitter/we_cmdargs.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/writeengine/wrapper/tdriver.cpp b/writeengine/wrapper/tdriver.cpp index ecabe1a10..f2044e3e8 100644 --- a/writeengine/wrapper/tdriver.cpp +++ b/writeengine/wrapper/tdriver.cpp @@ -1,5 +1,5 @@ /* Copyright (C) 2014 InfiniDB, Inc. - Copyright (C) 2016 MariaDB Corporaton + Copyright (C) 2016 MariaDB Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/writeengine/xml/we_xmljob.cpp b/writeengine/xml/we_xmljob.cpp index 4cc4c90eb..863e5cbef 100644 --- a/writeengine/xml/we_xmljob.cpp +++ b/writeengine/xml/we_xmljob.cpp @@ -48,7 +48,7 @@ using namespace execplan; namespace WriteEngine { // Maximum saturation value for DECIMAL types based on precision -const long long infinidb_precision[19] = +const long long columnstore_precision[19] = { 0, 9, @@ -759,14 +759,14 @@ void XMLJob::initSatLimits( JobColumn& curColumn ) const else if ( curColumn.typeName == ColDataTypeStr[CalpontSystemCatalog::DECIMAL] ) { - curColumn.fMinIntSat = -infinidb_precision[curColumn.precision]; - curColumn.fMaxIntSat = infinidb_precision[curColumn.precision]; + curColumn.fMinIntSat = -columnstore_precision[curColumn.precision]; + curColumn.fMaxIntSat = columnstore_precision[curColumn.precision]; } else if ( curColumn.typeName == ColDataTypeStr[CalpontSystemCatalog::UDECIMAL] ) { curColumn.fMinIntSat = 0; - curColumn.fMaxIntSat = infinidb_precision[curColumn.precision]; + curColumn.fMaxIntSat = columnstore_precision[curColumn.precision]; } else if ( curColumn.typeName == ColDataTypeStr[CalpontSystemCatalog::FLOAT] )