You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-06-13 16:01:32 +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:
@ -145,27 +145,25 @@ ReturnedColumn* buildBoundExp(WF_Boundary& bound, SRCP& order, gp_walk_info& gwi
|
||||
|
||||
// put interval val column to bound
|
||||
(dynamic_cast<FunctionColumn*>(rc))->functionName(funcName);
|
||||
(dynamic_cast<FunctionColumn*>(rc))->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
|
||||
(dynamic_cast<FunctionColumn*>(rc))->timeZone(gwi.timeZone);
|
||||
sptp.reset(new ParseTree(order->clone()));
|
||||
funcParms.push_back(sptp);
|
||||
sptp.reset(new ParseTree(intervalCol->val()->clone()));
|
||||
funcParms.push_back(sptp);
|
||||
funcParms.push_back(getIntervalType(gwi.thd, intervalCol->intervalType()));
|
||||
funcParms.push_back(getIntervalType(&gwi, intervalCol->intervalType()));
|
||||
SRCP srcp(intervalCol->val());
|
||||
bound.fVal = srcp;
|
||||
|
||||
if (addOp)
|
||||
{
|
||||
sptp.reset(new ParseTree(new ConstantColumn("ADD")));
|
||||
(dynamic_cast<ConstantColumn*>(sptp->data()))
|
||||
->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
|
||||
(dynamic_cast<ConstantColumn*>(sptp->data()))->timeZone(gwi.timeZone);
|
||||
funcParms.push_back(sptp);
|
||||
}
|
||||
else
|
||||
{
|
||||
sptp.reset(new ParseTree(new ConstantColumn("SUB")));
|
||||
(dynamic_cast<ConstantColumn*>(sptp->data()))
|
||||
->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
|
||||
(dynamic_cast<ConstantColumn*>(sptp->data()))->timeZone(gwi.timeZone);
|
||||
funcParms.push_back(sptp);
|
||||
}
|
||||
|
||||
@ -187,7 +185,7 @@ ReturnedColumn* buildBoundExp(WF_Boundary& bound, SRCP& order, gp_walk_info& gwi
|
||||
else
|
||||
aop = new ArithmeticOperator("-");
|
||||
|
||||
aop->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
|
||||
aop->timeZone(gwi.timeZone);
|
||||
ParseTree* pt = new ParseTree(aop);
|
||||
ParseTree *lhs = 0, *rhs = 0;
|
||||
lhs = new ParseTree(order->clone());
|
||||
@ -314,7 +312,7 @@ ReturnedColumn* buildWindowFunctionColumn(Item* item, gp_walk_info& gwi, bool& n
|
||||
Item_sum* item_sum = wf->window_func();
|
||||
string funcName = ConvertFuncName(item_sum);
|
||||
WindowFunctionColumn* ac = new WindowFunctionColumn(funcName);
|
||||
ac->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
|
||||
ac->timeZone(gwi.timeZone);
|
||||
ac->distinct(item_sum->has_with_distinct());
|
||||
Window_spec* win_spec = wf->window_spec;
|
||||
SRCP srcp;
|
||||
@ -407,45 +405,45 @@ ReturnedColumn* buildWindowFunctionColumn(Item* item, gp_walk_info& gwi, bool& n
|
||||
sprintf(sRespectNulls, "%lu", bRespectNulls);
|
||||
srcp.reset(new ConstantColumn(sRespectNulls, (uint64_t)bRespectNulls,
|
||||
ConstantColumn::NUM)); // IGNORE/RESPECT NULLS. 1 => RESPECT
|
||||
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
|
||||
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.timeZone);
|
||||
funcParms.push_back(srcp);
|
||||
break;
|
||||
}
|
||||
|
||||
case Item_sum::FIRST_VALUE_FUNC:
|
||||
srcp.reset(new ConstantColumn("1", (uint64_t)1, ConstantColumn::NUM)); // OFFSET (always one)
|
||||
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
|
||||
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.timeZone);
|
||||
funcParms.push_back(srcp);
|
||||
srcp.reset(new ConstantColumn("1", (uint64_t)1, ConstantColumn::NUM)); // FROM_FIRST
|
||||
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
|
||||
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.timeZone);
|
||||
funcParms.push_back(srcp);
|
||||
srcp.reset(
|
||||
new ConstantColumn("1", (uint64_t)1, ConstantColumn::NUM)); // IGNORE/RESPECT NULLS. 1 => RESPECT
|
||||
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
|
||||
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.timeZone);
|
||||
funcParms.push_back(srcp);
|
||||
break;
|
||||
|
||||
case Item_sum::LAST_VALUE_FUNC:
|
||||
srcp.reset(new ConstantColumn("1", (uint64_t)1, ConstantColumn::NUM)); // OFFSET (always one)
|
||||
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
|
||||
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.timeZone);
|
||||
funcParms.push_back(srcp);
|
||||
srcp.reset(new ConstantColumn("0", (uint64_t)0, ConstantColumn::NUM)); // FROM_LAST
|
||||
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
|
||||
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.timeZone);
|
||||
funcParms.push_back(srcp);
|
||||
srcp.reset(
|
||||
new ConstantColumn("1", (uint64_t)1, ConstantColumn::NUM)); // IGNORE/RESPECT NULLS. 1 => RESPECT
|
||||
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
|
||||
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.timeZone);
|
||||
funcParms.push_back(srcp);
|
||||
break;
|
||||
|
||||
case Item_sum::NTH_VALUE_FUNC:
|
||||
// When the front end supports these paramters, this needs modification
|
||||
srcp.reset(new ConstantColumn("1", (uint64_t)1, ConstantColumn::NUM)); // FROM FIRST/LAST 1 => FIRST
|
||||
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
|
||||
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.timeZone);
|
||||
funcParms.push_back(srcp);
|
||||
srcp.reset(
|
||||
new ConstantColumn("1", (uint64_t)1, ConstantColumn::NUM)); // IGNORE/RESPECT NULLS. 1 => RESPECT
|
||||
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
|
||||
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.timeZone);
|
||||
funcParms.push_back(srcp);
|
||||
break;
|
||||
|
||||
@ -453,11 +451,11 @@ ReturnedColumn* buildWindowFunctionColumn(Item* item, gp_walk_info& gwi, bool& n
|
||||
case Item_sum::LAG_FUNC:
|
||||
// When the front end supports these paramters, this needs modification
|
||||
srcp.reset(new ConstantColumn("", ConstantColumn::NULLDATA)); // Default to fill in for NULL values
|
||||
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
|
||||
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.timeZone);
|
||||
funcParms.push_back(srcp);
|
||||
srcp.reset(
|
||||
new ConstantColumn("1", (uint64_t)1, ConstantColumn::NUM)); // IGNORE/RESPECT NULLS. 1 => RESPECT
|
||||
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
|
||||
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.timeZone);
|
||||
funcParms.push_back(srcp);
|
||||
break;
|
||||
|
||||
@ -802,8 +800,7 @@ ReturnedColumn* buildWindowFunctionColumn(Item* item, gp_walk_info& gwi, bool& n
|
||||
bound = 1;
|
||||
|
||||
srcp.reset(new ConstantColumn((int64_t)bound));
|
||||
(dynamic_cast<ConstantColumn*>(srcp.get()))
|
||||
->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
|
||||
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.timeZone);
|
||||
frm.fStart.fVal = srcp;
|
||||
frm.fStart.fBound.reset(buildBoundExp(frm.fStart, srcp, gwi));
|
||||
|
||||
@ -819,8 +816,7 @@ ReturnedColumn* buildWindowFunctionColumn(Item* item, gp_walk_info& gwi, bool& n
|
||||
bound = 1;
|
||||
|
||||
srcp.reset(new ConstantColumn((int64_t)bound));
|
||||
(dynamic_cast<ConstantColumn*>(srcp.get()))
|
||||
->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
|
||||
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.timeZone);
|
||||
frm.fEnd.fVal = srcp;
|
||||
frm.fEnd.fBound.reset(buildBoundExp(frm.fEnd, srcp, gwi));
|
||||
|
||||
|
Reference in New Issue
Block a user