You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-01 06:21:41 +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:
@ -295,7 +295,8 @@ bool onlyOneTableinTM(cal_impl_if::cal_connection_info* ci)
|
||||
return true;
|
||||
}
|
||||
|
||||
int fetchNextRow(uchar* buf, cal_table_info& ti, cal_connection_info* ci, bool handler_flag = false)
|
||||
int fetchNextRow(uchar* buf, cal_table_info& ti, cal_connection_info* ci, long timeZone,
|
||||
bool handler_flag = false)
|
||||
{
|
||||
int rc = HA_ERR_END_OF_FILE;
|
||||
int num_attr = ti.msTablePtr->s->fields;
|
||||
@ -436,7 +437,7 @@ int fetchNextRow(uchar* buf, cal_table_info& ti, cal_connection_info* ci, bool h
|
||||
{
|
||||
// fetch and store data
|
||||
(*f)->set_notnull();
|
||||
datatypes::StoreFieldMariaDB mf(*f, colType);
|
||||
datatypes::StoreFieldMariaDB mf(*f, colType, timeZone);
|
||||
h->storeValueToField(row, s, &mf);
|
||||
}
|
||||
}
|
||||
@ -891,6 +892,10 @@ uint32_t doUpdateDelete(THD* thd, gp_walk_info& gwi, const std::vector<COND*>& c
|
||||
bool isFromSameTable = true;
|
||||
execplan::SCSEP updateCP(new execplan::CalpontSelectExecutionPlan());
|
||||
|
||||
const char* timeZone = thd->variables.time_zone->get_name()->ptr();
|
||||
long timeZoneOffset;
|
||||
dataconvert::timeZoneToOffset(timeZone, strlen(timeZone), &timeZoneOffset);
|
||||
|
||||
updateCP->isDML(true);
|
||||
|
||||
//@Bug 2753. the memory already freed by destructor of UpdateSqlStatement
|
||||
@ -1014,9 +1019,9 @@ uint32_t doUpdateDelete(THD* thd, gp_walk_info& gwi, const std::vector<COND*>& c
|
||||
// sysdate() etc.
|
||||
if (!hasNonSupportItem && !cal_impl_if::nonConstFunc(ifp) && tmpVec.size() == 0)
|
||||
{
|
||||
gp_walk_info gwi;
|
||||
gwi.thd = thd;
|
||||
SRCP srcp(buildReturnedColumn(value, gwi, gwi.fatalParseError));
|
||||
gp_walk_info gwi2(gwi.timeZone);
|
||||
gwi2.thd = thd;
|
||||
SRCP srcp(buildReturnedColumn(value, gwi2, gwi2.fatalParseError));
|
||||
ConstantColumn* constCol = dynamic_cast<ConstantColumn*>(srcp.get());
|
||||
|
||||
if (constCol)
|
||||
@ -1163,7 +1168,7 @@ uint32_t doUpdateDelete(THD* thd, gp_walk_info& gwi, const std::vector<COND*>& c
|
||||
char buf[64];
|
||||
gettimeofday(&tv, 0);
|
||||
MySQLTime time;
|
||||
gmtSecToMySQLTime(tv.tv_sec, time, thd->variables.time_zone->get_name()->ptr());
|
||||
gmtSecToMySQLTime(tv.tv_sec, time, timeZoneOffset);
|
||||
sprintf(buf, "%04d-%02d-%02d %02d:%02d:%02d.%06ld", time.year, time.month, time.day, time.hour,
|
||||
time.minute, time.second, tv.tv_usec);
|
||||
columnAssignmentPtr->fScalarExpression = buf;
|
||||
@ -1314,7 +1319,7 @@ uint32_t doUpdateDelete(THD* thd, gp_walk_info& gwi, const std::vector<COND*>& c
|
||||
pDMLPackage->set_TableName(tableName);
|
||||
|
||||
pDMLPackage->set_SchemaName(schemaName);
|
||||
pDMLPackage->set_TimeZone(thd->variables.time_zone->get_name()->ptr());
|
||||
pDMLPackage->set_TimeZone(timeZoneOffset);
|
||||
|
||||
pDMLPackage->set_IsFromCol(true);
|
||||
// cout << " setting isFromCol to " << isFromCol << endl;
|
||||
@ -1516,7 +1521,7 @@ uint32_t doUpdateDelete(THD* thd, gp_walk_info& gwi, const std::vector<COND*>& c
|
||||
CalpontSystemCatalog::TableColName tcn = csc->colName(colrids[minWidthColOffset].objnum);
|
||||
SimpleColumn* sc = new SimpleColumn(tcn.schema, tcn.table, tcn.column, csc->sessionID());
|
||||
sc->tableAlias(aliasName);
|
||||
sc->timeZone(thd->variables.time_zone->get_name()->ptr());
|
||||
sc->timeZone(timeZoneOffset);
|
||||
sc->resultType(csc->colType(colrids[minWidthColOffset].objnum));
|
||||
SRCP srcp;
|
||||
srcp.reset(sc);
|
||||
@ -1660,7 +1665,7 @@ uint32_t doUpdateDelete(THD* thd, gp_walk_info& gwi, const std::vector<COND*>& c
|
||||
// << endl;
|
||||
VendorDMLStatement cmdStmt("CTRL+C", DML_COMMAND, sessionID);
|
||||
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackageFromMysqlBuffer(cmdStmt);
|
||||
pDMLPackage->set_TimeZone(thd->variables.time_zone->get_name()->ptr());
|
||||
pDMLPackage->set_TimeZone(timeZoneOffset);
|
||||
ByteStream bytestream;
|
||||
bytestream << static_cast<uint32_t>(sessionID);
|
||||
pDMLPackage->write(bytestream);
|
||||
@ -1783,7 +1788,7 @@ uint32_t doUpdateDelete(THD* thd, gp_walk_info& gwi, const std::vector<COND*>& c
|
||||
{
|
||||
VendorDMLStatement cmdStmt(command, DML_COMMAND, sessionID);
|
||||
CalpontDMLPackage* pDMLPackage = CalpontDMLFactory::makeCalpontDMLPackageFromMysqlBuffer(cmdStmt);
|
||||
pDMLPackage->set_TimeZone(thd->variables.time_zone->get_name()->ptr());
|
||||
pDMLPackage->set_TimeZone(timeZoneOffset);
|
||||
pDMLPackage->setTableOid(ci->tableOid);
|
||||
ByteStream bytestream;
|
||||
bytestream << static_cast<uint32_t>(sessionID);
|
||||
@ -2008,6 +2013,10 @@ int ha_mcs_impl_analyze(THD* thd, TABLE* table)
|
||||
execplan::MCSAnalyzeTableExecutionPlan::ReturnedColumnList returnedColumnList;
|
||||
execplan::MCSAnalyzeTableExecutionPlan::ColumnMap columnMap;
|
||||
|
||||
const char* timeZone = thd->variables.time_zone->get_name()->ptr();
|
||||
long timeZoneOffset;
|
||||
dataconvert::timeZoneToOffset(timeZone, strlen(timeZone), &timeZoneOffset);
|
||||
|
||||
// Iterate over table oid list and create a `SimpleColumn` for every column with supported type.
|
||||
for (uint32_t i = 0, e = oidlist.size(); i < e; ++i)
|
||||
{
|
||||
@ -2026,7 +2035,7 @@ int ha_mcs_impl_analyze(THD* thd, TABLE* table)
|
||||
simpleColumn->oid(objNum);
|
||||
simpleColumn->alias(tableColName.column);
|
||||
simpleColumn->resultType(colType);
|
||||
simpleColumn->timeZone(thd->variables.time_zone->get_name()->ptr());
|
||||
simpleColumn->timeZone(timeZoneOffset);
|
||||
|
||||
returnedColumn.reset(simpleColumn);
|
||||
returnedColumnList.push_back(returnedColumn);
|
||||
@ -2040,7 +2049,7 @@ int ha_mcs_impl_analyze(THD* thd, TABLE* table)
|
||||
|
||||
caep->schemaName(table->s->db.str, lower_case_table_names);
|
||||
caep->tableName(table->s->table_name.str, lower_case_table_names);
|
||||
caep->timeZone(thd->variables.time_zone->get_name()->ptr());
|
||||
caep->timeZone(timeZoneOffset);
|
||||
|
||||
SessionManager sm;
|
||||
BRM::TxnID txnID;
|
||||
@ -2160,7 +2169,10 @@ int ha_mcs_impl_direct_update_delete_rows(bool execute, ha_rows* affected_rows,
|
||||
const std::vector<COND*>& condStack)
|
||||
{
|
||||
THD* thd = current_thd;
|
||||
cal_impl_if::gp_walk_info gwi;
|
||||
const char* timeZone = thd->variables.time_zone->get_name()->ptr();
|
||||
long timeZoneOffset;
|
||||
dataconvert::timeZoneToOffset(timeZone, strlen(timeZone), &timeZoneOffset);
|
||||
cal_impl_if::gp_walk_info gwi(timeZoneOffset);
|
||||
gwi.thd = thd;
|
||||
int rc = 0;
|
||||
|
||||
@ -2189,8 +2201,10 @@ int ha_mcs::impl_rnd_init(TABLE* table, const std::vector<COND*>& condStack)
|
||||
{
|
||||
IDEBUG(cout << "rnd_init for table " << table->s->table_name.str << endl);
|
||||
THD* thd = current_thd;
|
||||
|
||||
gp_walk_info gwi;
|
||||
const char* timeZone = thd->variables.time_zone->get_name()->ptr();
|
||||
long timeZoneOffset;
|
||||
dataconvert::timeZoneToOffset(timeZone, strlen(timeZone), &timeZoneOffset);
|
||||
gp_walk_info gwi(timeZoneOffset);
|
||||
gwi.thd = thd;
|
||||
|
||||
if (thd->slave_thread && !get_replication_slave(thd) && isDMLStatement(thd->lex->sql_command))
|
||||
@ -2333,7 +2347,7 @@ int ha_mcs::impl_rnd_init(TABLE* table, const std::vector<COND*>& condStack)
|
||||
ti.msTablePtr = table;
|
||||
|
||||
// send plan whenever rnd_init is called
|
||||
cp_get_table_plan(thd, ti.csep, ti);
|
||||
cp_get_table_plan(thd, ti.csep, ti, timeZoneOffset);
|
||||
}
|
||||
|
||||
IDEBUG(cerr << table->s->table_name.str << " send plan:" << endl);
|
||||
@ -2563,7 +2577,7 @@ internal_error:
|
||||
return ER_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
int ha_mcs_impl_rnd_next(uchar* buf, TABLE* table)
|
||||
int ha_mcs_impl_rnd_next(uchar* buf, TABLE* table, long timeZone)
|
||||
{
|
||||
THD* thd = current_thd;
|
||||
|
||||
@ -2606,7 +2620,7 @@ int ha_mcs_impl_rnd_next(uchar* buf, TABLE* table)
|
||||
|
||||
try
|
||||
{
|
||||
rc = fetchNextRow(buf, ti, ci);
|
||||
rc = fetchNextRow(buf, ti, ci, timeZone);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
@ -2846,7 +2860,7 @@ int ha_mcs_impl_delete_table(const char* name)
|
||||
int rc = ha_mcs_impl_delete_table_(dbName, name, *ci);
|
||||
return rc;
|
||||
}
|
||||
int ha_mcs_impl_write_row(const uchar* buf, TABLE* table, uint64_t rows_changed)
|
||||
int ha_mcs_impl_write_row(const uchar* buf, TABLE* table, uint64_t rows_changed, long timeZone)
|
||||
{
|
||||
THD* thd = current_thd;
|
||||
|
||||
@ -2893,7 +2907,7 @@ int ha_mcs_impl_write_row(const uchar* buf, TABLE* table, uint64_t rows_changed)
|
||||
((thd->lex)->sql_command == SQLCOM_LOAD) || ((thd->lex)->sql_command == SQLCOM_INSERT_SELECT) ||
|
||||
ci->isCacheInsert))
|
||||
{
|
||||
rc = ha_mcs_impl_write_batch_row_(buf, table, *ci);
|
||||
rc = ha_mcs_impl_write_batch_row_(buf, table, *ci, timeZone);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -3894,7 +3908,10 @@ COND* ha_mcs_impl_cond_push(COND* cond, TABLE* table, std::vector<COND*>& condSt
|
||||
|
||||
#ifdef DEBUG_WALK_COND
|
||||
{
|
||||
gp_walk_info gwi;
|
||||
const char* timeZone = thd->variables.time_zone->get_name()->ptr();
|
||||
long timeZoneOffset;
|
||||
dataconvert::timeZoneToOffset(timeZone, strlen(timeZone), &timeZoneOffset);
|
||||
gp_walk_info gwi(timeZoneOffset);
|
||||
gwi.condPush = true;
|
||||
gwi.sessionid = tid2sid(thd->thread_id);
|
||||
cout << "------------------ cond push -----------------------" << endl;
|
||||
@ -3906,7 +3923,12 @@ COND* ha_mcs_impl_cond_push(COND* cond, TABLE* table, std::vector<COND*>& condSt
|
||||
if (!ti.csep)
|
||||
{
|
||||
if (!ti.condInfo)
|
||||
ti.condInfo = new gp_walk_info();
|
||||
{
|
||||
const char* timeZone = thd->variables.time_zone->get_name()->ptr();
|
||||
long timeZoneOffset;
|
||||
dataconvert::timeZoneToOffset(timeZone, strlen(timeZone), &timeZoneOffset);
|
||||
ti.condInfo = new gp_walk_info(timeZoneOffset);
|
||||
}
|
||||
|
||||
gp_walk_info* gwi = ti.condInfo;
|
||||
gwi->dropCond = false;
|
||||
@ -4554,7 +4576,7 @@ internal_error:
|
||||
* HA_ERR_END_OF_FILE if the record set has come to an end
|
||||
* others if something went wrong whilst getting the result set
|
||||
***********************************************************/
|
||||
int ha_mcs_impl_group_by_next(TABLE* table)
|
||||
int ha_mcs_impl_group_by_next(TABLE* table, long timeZone)
|
||||
{
|
||||
THD* thd = current_thd;
|
||||
|
||||
@ -4594,7 +4616,7 @@ int ha_mcs_impl_group_by_next(TABLE* table)
|
||||
{
|
||||
// fetchNextRow interface forces to use buf.
|
||||
unsigned char buf;
|
||||
rc = fetchNextRow(&buf, ti, ci, true);
|
||||
rc = fetchNextRow(&buf, ti, ci, timeZone, true);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
@ -4801,7 +4823,10 @@ int ha_mcs_impl_pushdown_init(mcs_handler_info* handler_info, TABLE* table)
|
||||
if (thd->slave_thread && !get_replication_slave(thd) && isDMLStatement(thd->lex->sql_command))
|
||||
return 0;
|
||||
|
||||
gp_walk_info gwi;
|
||||
const char* timeZone = thd->variables.time_zone->get_name()->ptr();
|
||||
long timeZoneOffset;
|
||||
dataconvert::timeZoneToOffset(timeZone, strlen(timeZone), &timeZoneOffset);
|
||||
gp_walk_info gwi(timeZoneOffset);
|
||||
gwi.thd = thd;
|
||||
bool err = false;
|
||||
|
||||
@ -5237,7 +5262,7 @@ internal_error:
|
||||
return ER_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
int ha_mcs_impl_select_next(uchar* buf, TABLE* table)
|
||||
int ha_mcs_impl_select_next(uchar* buf, TABLE* table, long timeZone)
|
||||
{
|
||||
THD* thd = current_thd;
|
||||
|
||||
@ -5336,7 +5361,7 @@ int ha_mcs_impl_select_next(uchar* buf, TABLE* table)
|
||||
|
||||
try
|
||||
{
|
||||
rc = fetchNextRow(buf, ti, ci);
|
||||
rc = fetchNextRow(buf, ti, ci, timeZone);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
|
Reference in New Issue
Block a user