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
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.
265 lines
6.3 KiB
C++
265 lines
6.3 KiB
C++
/* Copyright (C) 2014 InfiniDB, Inc.
|
|
Copyright (C) 2019 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. */
|
|
|
|
/***********************************************************************
|
|
* $Id: windowfunctioncolumn.h 9679 2013-07-11 22:32:03Z zzhu $
|
|
*
|
|
*
|
|
***********************************************************************/
|
|
|
|
/** @file */
|
|
|
|
#pragma once
|
|
#include <string>
|
|
#include <iosfwd>
|
|
#include <vector>
|
|
|
|
#include "returnedcolumn.h"
|
|
#include "functor.h"
|
|
#include "mcsv1_udaf.h"
|
|
#include "wf_frame.h"
|
|
|
|
namespace messageqcpp
|
|
{
|
|
class ByteStream;
|
|
}
|
|
|
|
/**
|
|
* Namespace
|
|
*/
|
|
namespace execplan
|
|
{
|
|
/**
|
|
* @brief A class to represent a functional column
|
|
*
|
|
* This class is a specialization of class ReturnedColumn that
|
|
* handles a window function.
|
|
*/
|
|
class WindowFunctionColumn : public ReturnedColumn
|
|
{
|
|
public:
|
|
WindowFunctionColumn();
|
|
WindowFunctionColumn(const std::string& functionName, const uint32_t sessionID = 0);
|
|
WindowFunctionColumn(const WindowFunctionColumn& rhs, const uint32_t sessionID = 0);
|
|
virtual ~WindowFunctionColumn()
|
|
{
|
|
}
|
|
|
|
/** get function name */
|
|
inline const std::string& functionName() const
|
|
{
|
|
return fFunctionName;
|
|
}
|
|
|
|
/** set function name */
|
|
inline void functionName(const std::string functionName)
|
|
{
|
|
fFunctionName = functionName;
|
|
}
|
|
|
|
/** get function parameters */
|
|
inline const std::vector<SRCP>& functionParms() const
|
|
{
|
|
return fFunctionParms;
|
|
}
|
|
|
|
/** set function parameters*/
|
|
inline void functionParms(const std::vector<SRCP>& functionParms)
|
|
{
|
|
fFunctionParms = functionParms;
|
|
}
|
|
|
|
/** get partition columns */
|
|
inline const std::vector<SRCP>& partitions() const
|
|
{
|
|
return fPartitions;
|
|
}
|
|
|
|
/** set partition columns */
|
|
inline void partitions(const std::vector<SRCP>& partitions)
|
|
{
|
|
fPartitions = partitions;
|
|
}
|
|
|
|
/** get order by clause */
|
|
inline const WF_OrderBy& orderBy() const
|
|
{
|
|
return fOrderBy;
|
|
}
|
|
|
|
/** set order by clause */
|
|
inline void orderBy(const WF_OrderBy& orderBy)
|
|
{
|
|
fOrderBy = orderBy;
|
|
}
|
|
|
|
/** make a clone of this window function */
|
|
inline virtual WindowFunctionColumn* clone() const
|
|
{
|
|
return new WindowFunctionColumn(*this);
|
|
}
|
|
|
|
std::vector<SRCP> getColumnList() const;
|
|
|
|
/** output the function for debug purpose */
|
|
const std::string toString() const;
|
|
|
|
/**
|
|
* The serialization interface
|
|
*/
|
|
virtual void serialize(messageqcpp::ByteStream&) const;
|
|
virtual void unserialize(messageqcpp::ByteStream&);
|
|
|
|
// util function for connector to use.
|
|
void addToPartition(std::vector<SRCP>& groupByList);
|
|
|
|
using ReturnedColumn::hasAggregate;
|
|
virtual bool hasAggregate()
|
|
{
|
|
return false;
|
|
}
|
|
virtual bool hasWindowFunc();
|
|
void adjustResultType();
|
|
|
|
// UDAnF support
|
|
mcsv1sdk::mcsv1Context& getUDAFContext()
|
|
{
|
|
return udafContext;
|
|
}
|
|
const mcsv1sdk::mcsv1Context& getUDAFContext() const
|
|
{
|
|
return udafContext;
|
|
}
|
|
|
|
inline long timeZone() const
|
|
{
|
|
return fTimeZone;
|
|
}
|
|
|
|
inline void timeZone(const long timeZone)
|
|
{
|
|
fTimeZone = timeZone;
|
|
}
|
|
|
|
private:
|
|
/**
|
|
* Fields
|
|
*/
|
|
std::string fFunctionName; /// function name
|
|
std::vector<SRCP> fFunctionParms; /// function arguments
|
|
std::vector<SRCP> fPartitions; /// partition by clause
|
|
WF_OrderBy fOrderBy; /// order by clause
|
|
|
|
// not support for window functions for now.
|
|
virtual bool operator==(const TreeNode* t) const
|
|
{
|
|
return false;
|
|
}
|
|
bool operator==(const WindowFunctionColumn& t) const;
|
|
virtual bool operator!=(const TreeNode* t) const
|
|
{
|
|
return false;
|
|
}
|
|
bool operator!=(const WindowFunctionColumn& t) const;
|
|
|
|
// UDAnF support
|
|
mcsv1sdk::mcsv1Context udafContext;
|
|
|
|
long fTimeZone;
|
|
/***********************************************************
|
|
* F&E framework *
|
|
***********************************************************/
|
|
public:
|
|
virtual const std::string& getStrVal(rowgroup::Row& row, bool& isNull)
|
|
{
|
|
evaluate(row, isNull);
|
|
return TreeNode::getStrVal(fTimeZone);
|
|
}
|
|
|
|
virtual int64_t getIntVal(rowgroup::Row& row, bool& isNull)
|
|
{
|
|
evaluate(row, isNull);
|
|
return TreeNode::getIntVal();
|
|
}
|
|
|
|
virtual uint64_t getUintVal(rowgroup::Row& row, bool& isNull)
|
|
{
|
|
evaluate(row, isNull);
|
|
return TreeNode::getUintVal();
|
|
}
|
|
|
|
virtual float getFloatVal(rowgroup::Row& row, bool& isNull)
|
|
{
|
|
evaluate(row, isNull);
|
|
return TreeNode::getFloatVal();
|
|
}
|
|
|
|
virtual double getDoubleVal(rowgroup::Row& row, bool& isNull)
|
|
{
|
|
evaluate(row, isNull);
|
|
return TreeNode::getDoubleVal();
|
|
}
|
|
|
|
virtual long double getLongDoubleVal(rowgroup::Row& row, bool& isNull)
|
|
{
|
|
evaluate(row, isNull);
|
|
return TreeNode::getLongDoubleVal();
|
|
}
|
|
|
|
virtual IDB_Decimal getDecimalVal(rowgroup::Row& row, bool& isNull)
|
|
{
|
|
evaluate(row, isNull);
|
|
return TreeNode::getDecimalVal();
|
|
}
|
|
virtual int32_t getDateIntVal(rowgroup::Row& row, bool& isNull)
|
|
{
|
|
evaluate(row, isNull);
|
|
return TreeNode::getDateIntVal();
|
|
}
|
|
virtual int64_t getDatetimeIntVal(rowgroup::Row& row, bool& isNull)
|
|
{
|
|
evaluate(row, isNull);
|
|
return TreeNode::getDatetimeIntVal();
|
|
}
|
|
virtual int64_t getTimestampIntVal(rowgroup::Row& row, bool& isNull)
|
|
{
|
|
evaluate(row, isNull);
|
|
return TreeNode::getTimestampIntVal();
|
|
}
|
|
virtual int64_t getTimeIntVal(rowgroup::Row& row, bool& isNull)
|
|
{
|
|
evaluate(row, isNull);
|
|
return TreeNode::getTimeIntVal();
|
|
}
|
|
|
|
private:
|
|
void evaluate(rowgroup::Row& row, bool& isNull);
|
|
};
|
|
|
|
/**
|
|
* ostream operator
|
|
*/
|
|
std::ostream& operator<<(std::ostream& output, const WindowFunctionColumn& rhs);
|
|
|
|
/**
|
|
* utility function to extract all window function columns from a parse tree
|
|
*/
|
|
void getWindowFunctionCols(ParseTree* n, void* obj);
|
|
|
|
} // namespace execplan
|