You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-29 08:21:15 +03:00
MCOL-4957 Fix performance slowdown for processing TIMESTAMP columns.
Part 1: As part of MCOL-3776 to address synchronization issue while accessing the fTimeZone member of the Func class, mutex locks were added to the accessor and mutator methods. However, this slows down processing of TIMESTAMP columns in PrimProc significantly as all threads across all concurrently running queries would serialize on the mutex. This is because PrimProc only has a single global object for the functor class (class derived from Func in utils/funcexp/functor.h) for a given function name. To fix this problem: (1) We remove the fTimeZone as a member of the Func derived classes (hence removing the mutexes) and instead use the fOperationType member of the FunctionColumn class to propagate the timezone values down to the individual functor processing functions such as FunctionColumn::getStrVal(), FunctionColumn::getIntVal(), etc. (2) To achieve (1), a timezone member is added to the execplan::CalpontSystemCatalog::ColType class. Part 2: Several functors in the Funcexp code call dataconvert::gmtSecToMySQLTime() and dataconvert::mySQLTimeToGmtSec() functions for conversion between seconds since unix epoch and broken-down representation. These functions in turn call the C library function localtime_r() which currently has a known bug of holding a global lock via a call to __tz_convert. This significantly reduces performance in multi-threaded applications where multiple threads concurrently call localtime_r(). More details on the bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16145 This bug in localtime_r() caused processing of the Functors in PrimProc to slowdown significantly since a query execution causes Functors code to be processed in a multi-threaded manner. As a fix, we remove the calls to localtime_r() from gmtSecToMySQLTime() and mySQLTimeToGmtSec() by performing the timezone-to-offset conversion (done in dataconvert::timeZoneToOffset()) during the execution plan creation in the plugin. Note that localtime_r() is only called when the time_zone system variable is set to "SYSTEM". This fix also required changing the timezone type from a std::string to a long across the system.
This commit is contained in:
@ -165,6 +165,7 @@ struct gp_walk_info
|
||||
bool cs_vtable_impossible_where_on_union;
|
||||
|
||||
bool isGroupByHandler;
|
||||
long timeZone;
|
||||
|
||||
// MCOL-4617 The below 2 fields are used for in-to-exists
|
||||
// predicate creation and injection. See usage in InSub::transform()
|
||||
@ -176,7 +177,7 @@ struct gp_walk_info
|
||||
TableOnExprList tableOnExprList;
|
||||
std::vector<COND*> condList;
|
||||
|
||||
gp_walk_info()
|
||||
gp_walk_info(long timeZone_)
|
||||
: sessionid(0)
|
||||
, fatalParseError(false)
|
||||
, condPush(false)
|
||||
@ -197,6 +198,7 @@ struct gp_walk_info
|
||||
, cs_vtable_is_update_with_derive(false)
|
||||
, cs_vtable_impossible_where_on_union(false)
|
||||
, isGroupByHandler(false)
|
||||
, timeZone(timeZone_)
|
||||
, inSubQueryLHS(nullptr)
|
||||
, inSubQueryLHSItem(nullptr)
|
||||
{
|
||||
@ -391,7 +393,7 @@ const std::string infinidb_err_msg =
|
||||
"distributed syntax or consider changing the MariaDB Columnstore Operating Mode (infinidb_vtable_mode).";
|
||||
|
||||
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_table_plan(THD* thd, execplan::SCSEP& csep, cal_impl_if::cal_table_info& ti, long timeZone);
|
||||
int cp_get_group_plan(THD* thd, execplan::SCSEP& csep, cal_impl_if::cal_group_info& gi);
|
||||
int cs_get_derived_plan(ha_columnstore_derived_handler* handler, THD* thd, execplan::SCSEP& csep,
|
||||
gp_walk_info& gwi);
|
||||
@ -428,14 +430,14 @@ execplan::ReturnedColumn* buildAggregateColumn(Item* item, gp_walk_info& gwi);
|
||||
execplan::ReturnedColumn* buildWindowFunctionColumn(Item* item, gp_walk_info& gwi, bool& nonSupport);
|
||||
execplan::ReturnedColumn* buildPseudoColumn(Item* item, gp_walk_info& gwi, bool& nonSupport,
|
||||
uint32_t pseudoType);
|
||||
void addIntervalArgs(THD* thd, Item_func* ifp, funcexp::FunctionParm& functionParms);
|
||||
void castCharArgs(THD* thd, Item_func* ifp, funcexp::FunctionParm& functionParms);
|
||||
void castDecimalArgs(THD* thd, Item_func* ifp, funcexp::FunctionParm& functionParms);
|
||||
void castTypeArgs(THD* thd, Item_func* ifp, funcexp::FunctionParm& functionParms);
|
||||
void addIntervalArgs(gp_walk_info* gwip, Item_func* ifp, funcexp::FunctionParm& functionParms);
|
||||
void castCharArgs(gp_walk_info* gwip, Item_func* ifp, funcexp::FunctionParm& functionParms);
|
||||
void castDecimalArgs(gp_walk_info* gwip, Item_func* ifp, funcexp::FunctionParm& functionParms);
|
||||
void castTypeArgs(gp_walk_info* gwip, Item_func* ifp, funcexp::FunctionParm& functionParms);
|
||||
// void parse_item (Item* item, std::vector<Item_field*>& field_vec, bool& hasNonSupportItem, uint16&
|
||||
// parseInfo);
|
||||
bool isPredicateFunction(Item* item, gp_walk_info* gwip);
|
||||
execplan::ParseTree* buildRowPredicate(THD* thd, execplan::RowColumn* lhs, execplan::RowColumn* rhs,
|
||||
execplan::ParseTree* buildRowPredicate(gp_walk_info* gwip, execplan::RowColumn* lhs, execplan::RowColumn* rhs,
|
||||
std::string predicateOp);
|
||||
bool buildRowColumnFilter(gp_walk_info* gwip, execplan::RowColumn* rhs, execplan::RowColumn* lhs,
|
||||
Item_func* ifp);
|
||||
@ -448,13 +450,13 @@ std::string getViewName(TABLE_LIST* table_ptr);
|
||||
bool buildConstPredicate(Item_func* ifp, execplan::ReturnedColumn* rhs, gp_walk_info* gwip);
|
||||
execplan::CalpontSystemCatalog::ColType fieldType_MysqlToIDB(const Field* field);
|
||||
execplan::CalpontSystemCatalog::ColType colType_MysqlToIDB(const Item* item);
|
||||
execplan::SPTP getIntervalType(THD* thd, int interval_type);
|
||||
execplan::SPTP getIntervalType(gp_walk_info* gwip, int interval_type);
|
||||
uint32_t isPseudoColumn(std::string funcName);
|
||||
void setDerivedTable(execplan::ParseTree* n);
|
||||
execplan::ParseTree* setDerivedFilter(THD* thd, execplan::ParseTree*& n,
|
||||
execplan::ParseTree* setDerivedFilter(gp_walk_info* gwip, execplan::ParseTree*& n,
|
||||
std::map<std::string, execplan::ParseTree*>& obj,
|
||||
execplan::CalpontSelectExecutionPlan::SelectList& derivedTbList);
|
||||
void derivedTableOptimization(THD* thd, execplan::SCSEP& csep);
|
||||
void derivedTableOptimization(gp_walk_info* gwip, execplan::SCSEP& csep);
|
||||
bool buildEqualityPredicate(execplan::ReturnedColumn* lhs, execplan::ReturnedColumn* rhs, gp_walk_info* gwip,
|
||||
boost::shared_ptr<execplan::Operator>& sop, const Item_func::Functype& funcType,
|
||||
const std::vector<Item*>& itemList, bool isInSubs = false);
|
||||
|
Reference in New Issue
Block a user