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:
@ -592,7 +592,7 @@ string TypeHandlerDatetime::format(const SimpleValue& v, const SystemCatalog::Ty
|
||||
|
||||
string TypeHandlerTimestamp::format(const SimpleValue& v, const SystemCatalog::TypeAttributesStd& attr) const
|
||||
{
|
||||
return DataConvert::timestampToString(v.toSInt64(), v.tzname());
|
||||
return DataConvert::timestampToString(v.toSInt64(), v.timeZone());
|
||||
}
|
||||
|
||||
string TypeHandlerTime::format(const SimpleValue& v, const SystemCatalog::TypeAttributesStd& attr) const
|
||||
@ -893,8 +893,8 @@ class SimpleConverter : public boost::any
|
||||
public:
|
||||
SimpleConverter(const SessionParam& sp, const TypeHandler* h, const SystemCatalog::TypeAttributesStd& attr,
|
||||
const char* str)
|
||||
: boost::any(
|
||||
h->convertFromString(attr, ConvertFromStringParam(sp.tzname(), true, false), str, initPushWarning()))
|
||||
: boost::any(h->convertFromString(attr, ConvertFromStringParam(sp.timeZone(), true, false), str,
|
||||
initPushWarning()))
|
||||
{
|
||||
}
|
||||
round_style_t roundStyle() const
|
||||
@ -1059,7 +1059,7 @@ SimpleValue TypeHandlerTimestamp::toSimpleValue(const SessionParam& sp,
|
||||
{
|
||||
idbassert(attr.colWidth <= SystemCatalog::EIGHT_BYTE);
|
||||
SimpleConverter anyVal(sp, this, attr, str);
|
||||
return SimpleValueTimestamp(anyVal.to_uint64(), sp.tzname());
|
||||
return SimpleValueTimestamp(anyVal.to_uint64(), sp.timeZone());
|
||||
}
|
||||
|
||||
SimpleValue TypeHandlerTime::toSimpleValue(const SessionParam& sp,
|
||||
|
@ -561,30 +561,30 @@ enum class round_style_t : uint8_t
|
||||
|
||||
class SessionParam
|
||||
{
|
||||
const char* m_tzname;
|
||||
long m_timeZone;
|
||||
|
||||
public:
|
||||
SessionParam(const char* tzname) : m_tzname(tzname)
|
||||
SessionParam(long timeZone) : m_timeZone(timeZone)
|
||||
{
|
||||
}
|
||||
const char* tzname() const
|
||||
long timeZone() const
|
||||
{
|
||||
return m_tzname;
|
||||
return m_timeZone;
|
||||
}
|
||||
};
|
||||
|
||||
class ConvertFromStringParam
|
||||
{
|
||||
const std::string& m_timeZone;
|
||||
const long m_timeZone;
|
||||
const bool m_noRoundup;
|
||||
const bool m_isUpdate;
|
||||
|
||||
public:
|
||||
ConvertFromStringParam(const std::string& timeZone, bool noRoundup, bool isUpdate)
|
||||
ConvertFromStringParam(long timeZone, bool noRoundup, bool isUpdate)
|
||||
: m_timeZone(timeZone), m_noRoundup(noRoundup), m_isUpdate(isUpdate)
|
||||
{
|
||||
}
|
||||
const std::string& timeZone() const
|
||||
long timeZone() const
|
||||
{
|
||||
return m_timeZone;
|
||||
}
|
||||
@ -602,14 +602,14 @@ class SimpleValue
|
||||
{
|
||||
int64_t m_sint64;
|
||||
int128_t m_sint128;
|
||||
const char* m_tzname;
|
||||
long m_timeZone;
|
||||
|
||||
public:
|
||||
SimpleValue(const int64_t sint64, const int128_t& sint128, const char* tzname)
|
||||
: m_sint64(sint64), m_sint128(sint128), m_tzname(tzname)
|
||||
SimpleValue(const int64_t sint64, const int128_t& sint128, long timeZone)
|
||||
: m_sint64(sint64), m_sint128(sint128), m_timeZone(timeZone)
|
||||
{
|
||||
}
|
||||
SimpleValue() : m_sint64(0), m_sint128(0), m_tzname(0)
|
||||
SimpleValue() : m_sint64(0), m_sint128(0), m_timeZone(0)
|
||||
{
|
||||
}
|
||||
int64_t toSInt64() const
|
||||
@ -624,16 +624,16 @@ class SimpleValue
|
||||
{
|
||||
return m_sint128;
|
||||
}
|
||||
const char* tzname() const
|
||||
long timeZone() const
|
||||
{
|
||||
return m_tzname;
|
||||
return m_timeZone;
|
||||
}
|
||||
};
|
||||
|
||||
class SimpleValueSInt64 : public SimpleValue
|
||||
{
|
||||
public:
|
||||
SimpleValueSInt64(int64_t value) : SimpleValue(value, 0, NULL)
|
||||
SimpleValueSInt64(int64_t value) : SimpleValue(value, 0, 0)
|
||||
{
|
||||
}
|
||||
};
|
||||
@ -641,7 +641,7 @@ class SimpleValueSInt64 : public SimpleValue
|
||||
class SimpleValueUInt64 : public SimpleValue
|
||||
{
|
||||
public:
|
||||
SimpleValueUInt64(uint64_t value) : SimpleValue(static_cast<int64_t>(value), 0, NULL)
|
||||
SimpleValueUInt64(uint64_t value) : SimpleValue(static_cast<int64_t>(value), 0, 0)
|
||||
{
|
||||
}
|
||||
};
|
||||
@ -649,7 +649,7 @@ class SimpleValueUInt64 : public SimpleValue
|
||||
class SimpleValueSInt128 : public SimpleValue
|
||||
{
|
||||
public:
|
||||
SimpleValueSInt128(int128_t value) : SimpleValue(0, value, NULL)
|
||||
SimpleValueSInt128(int128_t value) : SimpleValue(0, value, 0)
|
||||
{
|
||||
}
|
||||
};
|
||||
@ -657,8 +657,7 @@ class SimpleValueSInt128 : public SimpleValue
|
||||
class SimpleValueTimestamp : public SimpleValue
|
||||
{
|
||||
public:
|
||||
SimpleValueTimestamp(uint64_t value, const char* tzname)
|
||||
: SimpleValue(static_cast<int64_t>(value), 0, tzname)
|
||||
SimpleValueTimestamp(uint64_t value, long timeZone) : SimpleValue(static_cast<int64_t>(value), 0, timeZone)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user