1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-01 06:21:41 +03:00
Files
mariadb-columnstore-engine/dbcon/execplan/mcsanalyzetableexecutionplan.h
Gagan Goel 973e5024d8 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.
2022-02-14 14:12:27 -05:00

268 lines
5.1 KiB
C++

/* Copyright (C) 2021 MariaDB Corporation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2 of
the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
#pragma once
#include <vector>
#include <map>
#include <iosfwd>
#include <boost/uuid/uuid.hpp>
#include "exp_templates.h"
#include "calpontexecutionplan.h"
#include "calpontselectexecutionplan.h"
#include "returnedcolumn.h"
#include "filter.h"
#include "expressionparser.h"
#include "calpontsystemcatalog.h"
#include "brmtypes.h"
#include "objectreader.h"
#include <boost/algorithm/string/case_conv.hpp>
/**
* Namespace
*/
namespace execplan
{
class MCSAnalyzeTableExecutionPlan : public CalpontExecutionPlan
{
public:
typedef std::vector<SRCP> ReturnedColumnList;
typedef std::multimap<std::string, SRCP> ColumnMap;
typedef std::vector<RMParam> RMParmVec;
MCSAnalyzeTableExecutionPlan() : fTraceFlags(TRACE_NONE)
{
}
MCSAnalyzeTableExecutionPlan(const ReturnedColumnList& returnedCols, const ColumnMap& columnMap)
: fReturnedCols(returnedCols), fColumnMap(columnMap), fTraceFlags(TRACE_NONE)
{
}
virtual ~MCSAnalyzeTableExecutionPlan() = default;
const ReturnedColumnList& returnedCols() const
{
return fReturnedCols;
}
ReturnedColumnList& returnedCols()
{
return fReturnedCols;
}
void returnedCols(const ReturnedColumnList& returnedCols)
{
fReturnedCols = returnedCols;
}
const ColumnMap& columnMap() const
{
return fColumnMap;
}
ColumnMap& columnMap()
{
return fColumnMap;
}
void columnMap(const ColumnMap& columnMap)
{
fColumnMap = columnMap;
}
const std::string data() const
{
return fData;
}
void data(const std::string data)
{
fData = data;
}
uint32_t sessionID() const
{
return fSessionID;
}
void sessionID(const uint32_t sessionID)
{
fSessionID = sessionID;
}
int txnID() const
{
return fTxnID;
}
void txnID(const int txnID)
{
fTxnID = txnID;
}
const BRM::QueryContext verID() const
{
return fVerID;
}
void verID(const BRM::QueryContext verID)
{
fVerID = verID;
}
inline std::string& schemaName()
{
return fSchemaName;
}
inline void schemaName(const std::string& schemaName, int lower_case_table_names)
{
fSchemaName = schemaName;
if (lower_case_table_names)
boost::algorithm::to_lower(fSchemaName);
}
inline std::string& tableName()
{
return fTableName;
}
inline void tableName(const std::string& tableName, int lower_case_table_names)
{
fTableName = tableName;
if (lower_case_table_names)
boost::algorithm::to_lower(fTableName);
}
uint32_t statementID() const
{
return fStatementID;
}
void statementID(const uint32_t statementID)
{
fStatementID = statementID;
}
void uuid(const boost::uuids::uuid& uuid)
{
fUuid = uuid;
}
const boost::uuids::uuid& uuid() const
{
return fUuid;
}
void timeZone(long timezone)
{
fTimeZone = timezone;
}
long timeZone() const
{
return fTimeZone;
}
void priority(uint32_t p)
{
fPriority = p;
}
uint32_t priority() const
{
return fPriority;
}
const RMParmVec& rmParms()
{
return frmParms;
}
void rmParms(const RMParmVec& parms)
{
frmParms.clear();
frmParms.assign(parms.begin(), parms.end());
}
uint32_t localQuery() const
{
return fLocalQuery;
}
void localQuery(const uint32_t localQuery)
{
fLocalQuery = localQuery;
}
inline bool traceOn() const
{
return (traceFlags() & TRACE_LOG);
}
inline uint32_t traceFlags() const
{
return fTraceFlags;
}
inline void traceFlags(uint32_t traceFlags)
{
fTraceFlags = traceFlags;
}
virtual std::string toString() const;
virtual bool isInternal() const
{
return ((fSessionID & 0x80000000) != 0);
}
virtual void serialize(messageqcpp::ByteStream& bs) const;
virtual void unserialize(messageqcpp::ByteStream& bs);
// TODO: Why do we need this?
virtual bool operator==(const CalpontExecutionPlan* t) const
{
return false;
}
virtual bool operator!=(const CalpontExecutionPlan* t) const
{
return false;
}
private:
ReturnedColumnList fReturnedCols;
ColumnMap fColumnMap;
uint32_t fSessionID;
int fTxnID;
BRM::QueryContext fVerID;
std::string fSchemaName;
std::string fTableName;
uint32_t fTraceFlags;
boost::uuids::uuid fUuid;
long fTimeZone;
uint32_t fStatementID;
uint64_t fStringScanThreshold;
std::string fData;
RMParmVec frmParms;
uint32_t fPriority;
uint32_t fLocalQuery;
};
} // namespace execplan