You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-30 19:23:07 +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:
@ -1193,7 +1193,7 @@ bool stringToTimeStruct(const string& data, Time& dtime, long decimals)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool stringToTimestampStruct(const string& data, TimeStamp& timeStamp, const string& timeZone)
|
||||
bool stringToTimestampStruct(const string& data, TimeStamp& timeStamp, long timeZone)
|
||||
{
|
||||
// special handling for 0000-00-00 00:00:00
|
||||
// "0" is sent by the server when checking for default value
|
||||
@ -1879,10 +1879,11 @@ int64_t DataConvert::convertColumnDatetime(const char* dataOrg, CalpontDateTimeF
|
||||
// Most of this code is taken from DataConvert::convertColumnDatetime
|
||||
//------------------------------------------------------------------------------
|
||||
int64_t DataConvert::convertColumnTimestamp(const char* dataOrg, CalpontDateTimeFormat datetimeFormat,
|
||||
int& status, unsigned int dataOrgLen, const std::string& timeZone)
|
||||
int& status, unsigned int dataOrgLen, long timeZone)
|
||||
{
|
||||
char tmbuf[64];
|
||||
std::string dataOrgTemp = dataOrg;
|
||||
status = 0;
|
||||
if (dataOrgTemp.substr(0, 19) == "0000-00-00 00:00:00")
|
||||
{
|
||||
return 0;
|
||||
@ -1902,7 +1903,6 @@ int64_t DataConvert::convertColumnTimestamp(const char* dataOrg, CalpontDateTime
|
||||
dataOrgLen = strlen(tmbuf);
|
||||
}
|
||||
|
||||
status = 0;
|
||||
const char* p;
|
||||
p = dataOrg;
|
||||
char fld[10];
|
||||
@ -2258,8 +2258,7 @@ std::string DataConvert::datetimeToString(long long datetimevalue, long decimals
|
||||
return buf;
|
||||
}
|
||||
|
||||
std::string DataConvert::timestampToString(long long timestampvalue, const std::string& timezone,
|
||||
long decimals)
|
||||
std::string DataConvert::timestampToString(long long timestampvalue, long timezone, long decimals)
|
||||
{
|
||||
// 10 is default which means we don't need microseconds
|
||||
if (decimals > 6 || decimals < 0)
|
||||
@ -2343,7 +2342,7 @@ std::string DataConvert::datetimeToString1(long long datetimevalue)
|
||||
return buf;
|
||||
}
|
||||
|
||||
std::string DataConvert::timestampToString1(long long timestampvalue, const std::string& timezone)
|
||||
std::string DataConvert::timestampToString1(long long timestampvalue, long timezone)
|
||||
{
|
||||
const int TIMESTAMPTOSTRING1_LEN = 22; // YYYYMMDDHHMMSSmmmmmm\0
|
||||
char buf[TIMESTAMPTOSTRING1_LEN];
|
||||
@ -2381,7 +2380,7 @@ int64_t DataConvert::datetimeToInt(const string& datetime)
|
||||
return stringToDatetime(datetime);
|
||||
}
|
||||
|
||||
int64_t DataConvert::timestampToInt(const string& timestamp, const string& timeZone)
|
||||
int64_t DataConvert::timestampToInt(const string& timestamp, long timeZone)
|
||||
{
|
||||
return stringToTimestamp(timestamp, timeZone);
|
||||
}
|
||||
@ -2414,7 +2413,7 @@ int64_t DataConvert::stringToDatetime(const string& data, bool* date)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int64_t DataConvert::stringToTimestamp(const string& data, const string& timeZone)
|
||||
int64_t DataConvert::stringToTimestamp(const string& data, long timeZone)
|
||||
{
|
||||
TimeStamp aTimestamp;
|
||||
|
||||
|
Reference in New Issue
Block a user