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.
181 lines
4.9 KiB
C++
181 lines
4.9 KiB
C++
/* Copyright (C) 2014 InfiniDB, Inc.
|
|
Copyright (C) 2016 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: ha_exists_sub.cpp 6426 2010-03-30 18:46:11Z zzhu $
|
|
*
|
|
*
|
|
***********************************************************************/
|
|
/** @file */
|
|
/** class ExistsSub definition */
|
|
|
|
//#define NDEBUG
|
|
#define PREFER_MY_CONFIG_H
|
|
#include <my_config.h>
|
|
#include <cassert>
|
|
|
|
#include "idb_mysql.h"
|
|
|
|
#include "parsetree.h"
|
|
#include "existsfilter.h"
|
|
#include "simplefilter.h"
|
|
#include "constantcolumn.h"
|
|
using namespace execplan;
|
|
|
|
#include "errorids.h"
|
|
|
|
#include "ha_subquery.h"
|
|
|
|
namespace cal_impl_if
|
|
{
|
|
extern void makeAntiJoin(const ParseTree* n);
|
|
|
|
void checkCorrelation(const ParseTree* n, void* obj)
|
|
{
|
|
ExistsFilter* ef = reinterpret_cast<ExistsFilter*>(obj);
|
|
TreeNode* tn = n->data();
|
|
SimpleFilter* sf = dynamic_cast<SimpleFilter*>(tn);
|
|
|
|
if (!sf)
|
|
return;
|
|
|
|
uint64_t lJoinInfo = sf->lhs()->joinInfo();
|
|
uint64_t rJoinInfo = sf->rhs()->joinInfo();
|
|
|
|
if (lJoinInfo & JOIN_CORRELATED)
|
|
{
|
|
ConstantColumn* cc = dynamic_cast<ConstantColumn*>(sf->rhs());
|
|
|
|
if ((!cc || (cc && sf->op()->op() == OP_EQ)) && !(rJoinInfo & JOIN_CORRELATED))
|
|
ef->correlated(true);
|
|
}
|
|
|
|
if (rJoinInfo & JOIN_CORRELATED)
|
|
{
|
|
ConstantColumn* cc = dynamic_cast<ConstantColumn*>(sf->lhs());
|
|
|
|
if ((!cc || (cc && sf->op()->op() == OP_EQ)) && !(lJoinInfo & JOIN_CORRELATED))
|
|
ef->correlated(true);
|
|
}
|
|
}
|
|
|
|
ExistsSub::ExistsSub(gp_walk_info& gwip) : WhereSubQuery(gwip)
|
|
{
|
|
}
|
|
|
|
ExistsSub::ExistsSub(gp_walk_info& gwip, Item_subselect* sub) : WhereSubQuery(gwip, sub)
|
|
{
|
|
}
|
|
|
|
ExistsSub::~ExistsSub()
|
|
{
|
|
}
|
|
|
|
execplan::ParseTree* ExistsSub::transform()
|
|
{
|
|
idbassert(fSub);
|
|
|
|
SCSEP csep(new CalpontSelectExecutionPlan());
|
|
csep->sessionID(fGwip.sessionid);
|
|
csep->location(CalpontSelectExecutionPlan::WHERE);
|
|
csep->subType(CalpontSelectExecutionPlan::EXISTS_SUBS);
|
|
|
|
// gwi for the sub query
|
|
gp_walk_info gwi(fGwip.timeZone);
|
|
gwi.thd = fGwip.thd;
|
|
gwi.subQuery = this;
|
|
|
|
// @4827 merge table list to gwi in case there is FROM sub to be referenced
|
|
// in the FROM sub
|
|
gwi.derivedTbCnt = fGwip.derivedTbList.size();
|
|
uint32_t tbCnt = fGwip.tbList.size();
|
|
|
|
gwi.tbList.insert(gwi.tbList.begin(), fGwip.tbList.begin(), fGwip.tbList.end());
|
|
gwi.derivedTbList.insert(gwi.derivedTbList.begin(), fGwip.derivedTbList.begin(), fGwip.derivedTbList.end());
|
|
|
|
if (fSub->get_select_lex()->with_sum_func)
|
|
{
|
|
fGwip.fatalParseError = true;
|
|
fGwip.parseErrorText = logging::IDBErrorInfo::instance()->errorMsg(logging::ERR_AGG_EXISTS);
|
|
return NULL;
|
|
}
|
|
|
|
if (getSelectPlan(gwi, *(fSub->get_select_lex()), csep, false) != 0)
|
|
{
|
|
fGwip.fatalParseError = true;
|
|
|
|
if (gwi.fatalParseError && !gwi.parseErrorText.empty())
|
|
fGwip.parseErrorText = gwi.parseErrorText;
|
|
else
|
|
fGwip.parseErrorText = "Error occured in ExistsSub::transform()";
|
|
|
|
return NULL;
|
|
}
|
|
|
|
// remove outer query tables
|
|
CalpontSelectExecutionPlan::TableList tblist;
|
|
|
|
if (csep->tableList().size() >= tbCnt)
|
|
tblist.insert(tblist.begin(), csep->tableList().begin() + tbCnt, csep->tableList().end());
|
|
|
|
CalpontSelectExecutionPlan::SelectList derivedTbList;
|
|
|
|
if (csep->derivedTableList().size() >= gwi.derivedTbCnt)
|
|
derivedTbList.insert(derivedTbList.begin(), csep->derivedTableList().begin() + gwi.derivedTbCnt,
|
|
csep->derivedTableList().end());
|
|
|
|
csep->tableList(tblist);
|
|
csep->derivedTableList(derivedTbList);
|
|
|
|
ExistsFilter* subFilter = new ExistsFilter();
|
|
subFilter->correlated(false);
|
|
subFilter->sub(csep);
|
|
const ParseTree* pt = csep->filters();
|
|
|
|
if (pt)
|
|
pt->walk(checkCorrelation, subFilter);
|
|
|
|
fGwip.subselectList.push_back(csep);
|
|
return new ParseTree(subFilter);
|
|
}
|
|
|
|
/**
|
|
* This is invoked when a NOT function is got. It's usually the case NOT<IN optimizer>
|
|
* This function will simple turn the semi join to anti join
|
|
*
|
|
*/
|
|
void ExistsSub::handleNot()
|
|
{
|
|
ParseTree* pt = fGwip.ptWorkStack.top();
|
|
ExistsFilter* subFilter = dynamic_cast<ExistsFilter*>(pt->data());
|
|
idbassert(subFilter);
|
|
subFilter->notExists(true);
|
|
SCSEP csep = subFilter->sub();
|
|
const ParseTree* ptsub = csep->filters();
|
|
|
|
if (ptsub)
|
|
ptsub->walk(makeAntiJoin);
|
|
|
|
ptsub = csep->having();
|
|
|
|
if (ptsub)
|
|
ptsub->walk(makeAntiJoin);
|
|
}
|
|
|
|
} // namespace cal_impl_if
|