mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-04-18 21:44:02 +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.
229 lines
5.6 KiB
C++
229 lines
5.6 KiB
C++
/* Copyright (C) 2014 InfiniDB, Inc.
|
|
|
|
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: deletedmlpackage.cpp 9210 2013-01-21 14:10:42Z rdempsey $
|
|
*
|
|
*
|
|
***********************************************************************/
|
|
#include <stdexcept>
|
|
#include <iostream>
|
|
#include <boost/tokenizer.hpp>
|
|
#include <string>
|
|
#include <cstdlib>
|
|
using namespace std;
|
|
#define DELETEDMLPKG_DLLEXPORT
|
|
#include "deletedmlpackage.h"
|
|
#undef DELETEDMLPKG_DLLEXPORT
|
|
|
|
namespace dmlpackage
|
|
{
|
|
DeleteDMLPackage::DeleteDMLPackage()
|
|
{
|
|
}
|
|
|
|
DeleteDMLPackage::DeleteDMLPackage(std::string schemaName, std::string tableName, std::string dmlStatement,
|
|
int sessionID)
|
|
: CalpontDMLPackage(schemaName, tableName, dmlStatement, sessionID)
|
|
{
|
|
}
|
|
|
|
DeleteDMLPackage::~DeleteDMLPackage()
|
|
{
|
|
}
|
|
|
|
int DeleteDMLPackage::write(messageqcpp::ByteStream& bytestream)
|
|
{
|
|
int retval = 1;
|
|
|
|
messageqcpp::ByteStream::byte package_type = DML_DELETE;
|
|
bytestream << package_type;
|
|
|
|
messageqcpp::ByteStream::quadbyte session_id = fSessionID;
|
|
bytestream << session_id;
|
|
|
|
/* if(fPlan != 0)
|
|
fHasFilter = true;
|
|
else
|
|
fHasFilter = false;
|
|
*/
|
|
messageqcpp::ByteStream::quadbyte hasFilter = fHasFilter;
|
|
bytestream << hasFilter;
|
|
|
|
bytestream << fUuid;
|
|
|
|
bytestream << fDMLStatement;
|
|
bytestream << fSQLStatement;
|
|
bytestream << fSchemaName;
|
|
messageqcpp::ByteStream::octbyte timeZone = fTimeZone;
|
|
bytestream << timeZone;
|
|
|
|
if (fTable != 0)
|
|
{
|
|
retval = fTable->write(bytestream);
|
|
}
|
|
|
|
if (fHasFilter)
|
|
{
|
|
bytestream += *(fPlan.get());
|
|
}
|
|
|
|
return retval;
|
|
}
|
|
/**
|
|
*
|
|
*/
|
|
int DeleteDMLPackage::read(messageqcpp::ByteStream& bytestream)
|
|
{
|
|
int retval = 1;
|
|
|
|
messageqcpp::ByteStream::quadbyte session_id;
|
|
messageqcpp::ByteStream::quadbyte hasFilter;
|
|
|
|
bytestream >> session_id;
|
|
fSessionID = session_id;
|
|
|
|
bytestream >> hasFilter;
|
|
fHasFilter = (hasFilter != 0);
|
|
|
|
bytestream >> fUuid;
|
|
|
|
std::string dmlStatement;
|
|
bytestream >> fDMLStatement;
|
|
bytestream >> fSQLStatement;
|
|
bytestream >> fSchemaName;
|
|
messageqcpp::ByteStream::octbyte timeZone;
|
|
bytestream >> timeZone;
|
|
fTimeZone = timeZone;
|
|
|
|
fTable = new DMLTable();
|
|
retval = fTable->read(bytestream);
|
|
|
|
if (fHasFilter)
|
|
{
|
|
fPlan.reset(new messageqcpp::ByteStream(bytestream));
|
|
}
|
|
|
|
return retval;
|
|
}
|
|
|
|
int DeleteDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement)
|
|
{
|
|
int retval = 1;
|
|
|
|
DeleteSqlStatement& deleteStmt = dynamic_cast<DeleteSqlStatement&>(sqlStatement);
|
|
|
|
initializeTable();
|
|
|
|
if (0 != deleteStmt.fWhereClausePtr)
|
|
{
|
|
fHasFilter = true;
|
|
fQueryString = deleteStmt.getQueryString();
|
|
}
|
|
|
|
// else all rows are deleted
|
|
|
|
return retval;
|
|
}
|
|
|
|
/**
|
|
*
|
|
*/
|
|
int DeleteDMLPackage::buildFromBuffer(std::string& buffer, int columns, int rows)
|
|
{
|
|
#ifdef DML_PACKAGE_DEBUG
|
|
// cout << "The data buffer received: " << buffer << endl;
|
|
#endif
|
|
|
|
int retval = 1;
|
|
|
|
initializeTable();
|
|
|
|
std::vector<std::string> dataList;
|
|
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
|
|
boost::char_separator<char> sep(":");
|
|
tokenizer tokens(buffer, sep);
|
|
|
|
for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter)
|
|
{
|
|
dataList.push_back(StripLeadingWhitespace(*tok_iter));
|
|
}
|
|
|
|
int n = 0;
|
|
|
|
for (int i = 0; i < rows; i++)
|
|
{
|
|
// get a new row
|
|
Row aRow;
|
|
// Row *aRowPtr = new Row();
|
|
// std::string colName;
|
|
// std::string colValue;
|
|
// get row ID from the buffer
|
|
std::string rowid = dataList[n++];
|
|
aRow.set_RowID(atoll(rowid.c_str()));
|
|
// aRowPtr->set_RowID(atol(rowid.c_str()));
|
|
#ifdef DML_PACKAGE_DEBUG
|
|
|
|
// cout << "The row ID is " << rowid << endl;
|
|
#endif
|
|
/*
|
|
for (int j = 0; j < columns; j++)
|
|
{
|
|
//Build a column list
|
|
colName = dataList[n++];
|
|
colValue = dataList[n++];
|
|
#ifdef DML_PACKAGE_DEBUG
|
|
cout << "The column data: " << colName << " " << colValue << endl;
|
|
#endif
|
|
DMLColumn* aColumn = new DMLColumn(colName, colValue);
|
|
(aRowPtr->get_ColumnList()).push_back(aColumn);
|
|
}
|
|
//build a row list for a table
|
|
fTable->get_RowList().push_back(aRowPtr);
|
|
*/
|
|
}
|
|
|
|
return retval;
|
|
}
|
|
|
|
int DeleteDMLPackage::buildFromMysqlBuffer(ColNameList& colNameList, TableValuesMap& tableValuesMap,
|
|
int columns, int rows, NullValuesBitset& nullValues)
|
|
{
|
|
int retval = 1;
|
|
|
|
initializeTable();
|
|
// The row already built from MySql parser.
|
|
/* Row *aRowPtr = new Row();
|
|
std::string colName;
|
|
std::vector<std::string> colValList;
|
|
for (int j = 0; j < columns; j++)
|
|
{
|
|
//Build a column list
|
|
colName = colNameList[j];
|
|
|
|
colValList = tableValuesMap[j];
|
|
|
|
DMLColumn* aColumn = new DMLColumn(colName, colValList, false);
|
|
(aRowPtr->get_ColumnList()).push_back(aColumn);
|
|
}
|
|
//build a row list for a table
|
|
fTable->get_RowList().push_back(aRowPtr); */
|
|
return retval;
|
|
}
|
|
|
|
} // namespace dmlpackage
|