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:
@ -42,7 +42,7 @@ namespace
|
||||
using namespace funcexp;
|
||||
|
||||
dataconvert::DateTime getDateTime(rowgroup::Row& row, FunctionParm& parm, bool& isNull,
|
||||
CalpontSystemCatalog::ColType& ct, const string& timeZone)
|
||||
CalpontSystemCatalog::ColType& ct, long timeZone)
|
||||
{
|
||||
TimeExtractor extractor;
|
||||
dataconvert::DateTime dateTime;
|
||||
@ -186,7 +186,7 @@ string Func_str_to_date::getStrVal(rowgroup::Row& row, FunctionParm& parm, bool&
|
||||
CalpontSystemCatalog::ColType& ct)
|
||||
{
|
||||
dataconvert::DateTime dateTime;
|
||||
dateTime = getDateTime(row, parm, isNull, ct, timeZone());
|
||||
dateTime = getDateTime(row, parm, isNull, ct, ct.getTimeZone());
|
||||
string convertedDate = dataconvert::DataConvert::datetimeToString(*((long long*)&dateTime));
|
||||
return convertedDate;
|
||||
}
|
||||
@ -195,7 +195,7 @@ int32_t Func_str_to_date::getDateIntVal(rowgroup::Row& row, FunctionParm& parm,
|
||||
CalpontSystemCatalog::ColType& ct)
|
||||
{
|
||||
dataconvert::DateTime dateTime;
|
||||
dateTime = getDateTime(row, parm, isNull, ct, timeZone());
|
||||
dateTime = getDateTime(row, parm, isNull, ct, ct.getTimeZone());
|
||||
int64_t time = *(reinterpret_cast<int64_t*>(&dateTime));
|
||||
return ((((int32_t)(time >> 32)) & 0xFFFFFFC0) | 0x3E);
|
||||
}
|
||||
@ -204,7 +204,7 @@ int64_t Func_str_to_date::getDatetimeIntVal(rowgroup::Row& row, FunctionParm& pa
|
||||
CalpontSystemCatalog::ColType& ct)
|
||||
{
|
||||
dataconvert::DateTime dateTime;
|
||||
dateTime = getDateTime(row, parm, isNull, ct, timeZone());
|
||||
dateTime = getDateTime(row, parm, isNull, ct, ct.getTimeZone());
|
||||
int64_t time = *(reinterpret_cast<int64_t*>(&dateTime));
|
||||
return time;
|
||||
}
|
||||
@ -213,7 +213,7 @@ int64_t Func_str_to_date::getTimestampIntVal(rowgroup::Row& row, FunctionParm& p
|
||||
CalpontSystemCatalog::ColType& ct)
|
||||
{
|
||||
dataconvert::DateTime dateTime;
|
||||
dateTime = getDateTime(row, parm, isNull, ct, timeZone());
|
||||
dateTime = getDateTime(row, parm, isNull, ct, ct.getTimeZone());
|
||||
dataconvert::TimeStamp timestamp;
|
||||
dataconvert::MySQLTime m_time;
|
||||
m_time.year = dateTime.year;
|
||||
@ -223,7 +223,7 @@ int64_t Func_str_to_date::getTimestampIntVal(rowgroup::Row& row, FunctionParm& p
|
||||
m_time.minute = dateTime.minute;
|
||||
m_time.second = dateTime.second;
|
||||
bool isValid = true;
|
||||
int64_t seconds = mySQLTimeToGmtSec(m_time, timeZone(), isValid);
|
||||
int64_t seconds = mySQLTimeToGmtSec(m_time, ct.getTimeZone(), isValid);
|
||||
if (!isValid)
|
||||
{
|
||||
timestamp = -1;
|
||||
@ -243,7 +243,7 @@ int64_t Func_str_to_date::getTimeIntVal(rowgroup::Row& row, FunctionParm& parm,
|
||||
{
|
||||
dataconvert::DateTime dateTime;
|
||||
dataconvert::Time retTime;
|
||||
dateTime = getDateTime(row, parm, isNull, ct, timeZone());
|
||||
dateTime = getDateTime(row, parm, isNull, ct, ct.getTimeZone());
|
||||
retTime.day = 0;
|
||||
retTime.is_neg = false;
|
||||
retTime.hour = dateTime.hour;
|
||||
@ -258,7 +258,7 @@ int64_t Func_str_to_date::getIntVal(rowgroup::Row& row, FunctionParm& parm, bool
|
||||
CalpontSystemCatalog::ColType& ct)
|
||||
{
|
||||
dataconvert::DateTime dateTime;
|
||||
dateTime = getDateTime(row, parm, isNull, ct, timeZone());
|
||||
dateTime = getDateTime(row, parm, isNull, ct, ct.getTimeZone());
|
||||
int64_t time = *(reinterpret_cast<int64_t*>(&dateTime));
|
||||
return time;
|
||||
}
|
||||
|
Reference in New Issue
Block a user