1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-29 08:21:15 +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:
Gagan Goel
2022-02-09 19:03:00 -05:00
parent f67a37bcae
commit 973e5024d8
120 changed files with 1022 additions and 695 deletions

View File

@ -96,7 +96,7 @@ execplan::ParseTree* ExistsSub::transform()
csep->subType(CalpontSelectExecutionPlan::EXISTS_SUBS);
// gwi for the sub query
gp_walk_info gwi;
gp_walk_info gwi(fGwip.timeZone);
gwi.thd = fGwip.thd;
gwi.subQuery = this;

View File

@ -44,7 +44,7 @@ using namespace execplan;
namespace cal_impl_if
{
void derivedTableOptimization(THD* thd, SCSEP& csep)
void derivedTableOptimization(gp_walk_info* gwip, SCSEP& csep)
{
// @bug5634. replace the unused column with ConstantColumn from derived table column list,
// ExeMgr will not project ConstantColumn. Only count for local derived column.
@ -135,8 +135,7 @@ void derivedTableOptimization(THD* thd, SCSEP& csep)
else
{
cols[i].reset(new ConstantColumn(val));
(reinterpret_cast<ConstantColumn*>(cols[i].get()))
->timeZone(thd->variables.time_zone->get_name()->ptr());
(reinterpret_cast<ConstantColumn*>(cols[i].get()))->timeZone(gwip->timeZone);
}
for (uint j = 0; j < unionColVec.size(); j++)
@ -156,8 +155,7 @@ void derivedTableOptimization(THD* thd, SCSEP& csep)
else
{
unionColVec[j][i].reset(new ConstantColumn(val));
(reinterpret_cast<ConstantColumn*>(unionColVec[j][i].get()))
->timeZone(thd->variables.time_zone->get_name()->ptr());
(reinterpret_cast<ConstantColumn*>(unionColVec[j][i].get()))->timeZone(gwip->timeZone);
}
}
}
@ -173,15 +171,13 @@ void derivedTableOptimization(THD* thd, SCSEP& csep)
if (!cols.empty())
{
cols[0].reset(new ConstantColumn(val));
(reinterpret_cast<ConstantColumn*>(cols[0].get()))
->timeZone(thd->variables.time_zone->get_name()->ptr());
(reinterpret_cast<ConstantColumn*>(cols[0].get()))->timeZone(gwip->timeZone);
nonConstCols.push_back(cols[0]);
for (uint j = 0; j < unionColVec.size(); j++)
{
unionColVec[j][0].reset(new ConstantColumn(val));
(reinterpret_cast<ConstantColumn*>(unionColVec[j][0].get()))
->timeZone(thd->variables.time_zone->get_name()->ptr());
(reinterpret_cast<ConstantColumn*>(unionColVec[j][0].get()))->timeZone(gwip->timeZone);
nonConstUnionColVec[j].push_back(unionColVec[j][0]);
}
}
@ -229,7 +225,7 @@ void derivedTableOptimization(THD* thd, SCSEP& csep)
if (horizontalOptimization && pt)
{
pt->walk(setDerivedTable);
setDerivedFilter(thd, pt, derivedTbFilterMap, derivedTbList);
setDerivedFilter(gwip, pt, derivedTbFilterMap, derivedTbList);
csep->filters(pt);
}
@ -301,7 +297,7 @@ void derivedTableOptimization(THD* thd, SCSEP& csep)
for (uint i = 0; i < csep->subSelectList().size(); i++)
{
SCSEP subselect(boost::dynamic_pointer_cast<CalpontSelectExecutionPlan>(csep->subSelectList()[i]));
derivedTableOptimization(thd, subselect);
derivedTableOptimization(gwip, subselect);
}
}
@ -339,7 +335,7 @@ void setDerivedTable(execplan::ParseTree* n)
}
}
ParseTree* setDerivedFilter(THD* thd, ParseTree*& n, map<string, ParseTree*>& filterMap,
ParseTree* setDerivedFilter(gp_walk_info* gwip, ParseTree*& n, map<string, ParseTree*>& filterMap,
CalpontSelectExecutionPlan::SelectList& derivedTbList)
{
if (!(n->derivedTable().empty()))
@ -381,7 +377,7 @@ ParseTree* setDerivedFilter(THD* thd, ParseTree*& n, map<string, ParseTree*>& fi
int64_t val = 1;
n = new ParseTree(new ConstantColumn(val));
(dynamic_cast<ConstantColumn*>(n->data()))->timeZone(thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(n->data()))->timeZone(gwip->timeZone);
}
else
{
@ -397,10 +393,10 @@ ParseTree* setDerivedFilter(THD* thd, ParseTree*& n, map<string, ParseTree*>& fi
ParseTree* rhs = n->right();
if (lhs)
n->left(setDerivedFilter(thd, lhs, filterMap, derivedTbList));
n->left(setDerivedFilter(gwip, lhs, filterMap, derivedTbList));
if (rhs)
n->right(setDerivedFilter(thd, rhs, filterMap, derivedTbList));
n->right(setDerivedFilter(gwip, rhs, filterMap, derivedTbList));
}
}
@ -428,7 +424,7 @@ SCSEP FromSubQuery::transform()
csep->subType(CalpontSelectExecutionPlan::FROM_SUBS);
// gwi for the sub query
gp_walk_info gwi;
gp_walk_info gwi(fGwip.timeZone);
gwi.thd = fGwip.thd;
gwi.subQuery = this;
gwi.viewName = fGwip.viewName;

View File

@ -151,7 +151,7 @@ execplan::ParseTree* InSub::transform()
csep->subType(CalpontSelectExecutionPlan::IN_SUBS);
// gwi for the sub query
gp_walk_info gwi;
gp_walk_info gwi(fGwip.timeZone);
gwi.thd = fGwip.thd;
gwi.subQuery = this;

View File

@ -163,6 +163,8 @@ ha_mcs::ha_mcs(handlerton* hton, TABLE_SHARE* table_arg)
HA_CAN_TABLE_CONDITION_PUSHDOWN | HA_CAN_DIRECT_UPDATE_AND_DELETE)
, m_lock_type(F_UNLCK)
{
const char* timeZone = current_thd->variables.time_zone->get_name()->ptr();
dataconvert::timeZoneToOffset(timeZone, strlen(timeZone), &time_zone);
}
/**
@ -318,7 +320,7 @@ int ha_mcs::write_row(const uchar* buf)
int rc;
try
{
rc = ha_mcs_impl_write_row(buf, table, rows_changed);
rc = ha_mcs_impl_write_row(buf, table, rows_changed, time_zone);
}
catch (std::runtime_error& e)
{
@ -652,7 +654,7 @@ int ha_mcs::rnd_next(uchar* buf)
int rc;
try
{
rc = ha_mcs_impl_rnd_next(buf, table);
rc = ha_mcs_impl_rnd_next(buf, table, time_zone);
}
catch (std::runtime_error& e)
{

View File

@ -51,6 +51,7 @@ class ha_mcs : public handler
// call on Ubuntu18.
std::vector<COND*> condStack;
int m_lock_type;
long time_zone;
int impl_external_lock(THD* thd, TABLE* table, int lock_type);
int impl_rnd_init(TABLE* table, const std::vector<COND*>& condStack);

View File

@ -29,9 +29,11 @@ class StoreFieldMariaDB : public StoreField
{
Field* m_field;
const CalpontSystemCatalog::ColType& m_type;
long m_timeZone;
public:
StoreFieldMariaDB(Field* f, const CalpontSystemCatalog::ColType& type) : m_field(f), m_type(type)
StoreFieldMariaDB(Field* f, const CalpontSystemCatalog::ColType& type, const long timeZone)
: m_field(f), m_type(type), m_timeZone(timeZone)
{
}
@ -76,8 +78,7 @@ class StoreFieldMariaDB : public StoreField
int store_timestamp(int64_t val) override
{
char tmp[256];
DataConvert::timestampToString(val, tmp, sizeof(tmp), current_thd->variables.time_zone->get_name()->ptr(),
m_type.precision);
DataConvert::timestampToString(val, tmp, sizeof(tmp), m_timeZone, m_type.precision);
return store_string(tmp, strlen(tmp));
}
@ -212,8 +213,10 @@ class WriteBatchFieldMariaDB : public WriteBatchField
Field* m_field;
const CalpontSystemCatalog::ColType& m_type;
uint32_t m_mbmaxlen;
WriteBatchFieldMariaDB(Field* field, const CalpontSystemCatalog::ColType& type, uint32_t mbmaxlen)
: m_field(field), m_type(type), m_mbmaxlen(mbmaxlen)
long m_timeZone;
WriteBatchFieldMariaDB(Field* field, const CalpontSystemCatalog::ColType& type, uint32_t mbmaxlen,
const long timeZone)
: m_field(field), m_type(type), m_mbmaxlen(mbmaxlen), m_timeZone(timeZone)
{
}
size_t ColWriteBatchDate(const uchar* buf, bool nullVal, ColBatchWriter& ci) override
@ -325,7 +328,7 @@ class WriteBatchFieldMariaDB : public WriteBatchField
my_timestamp_from_binary(&tm, buf, m_field->decimals());
MySQLTime time;
gmtSecToMySQLTime(tm.tv_sec, time, current_thd->variables.time_zone->get_name()->ptr());
gmtSecToMySQLTime(tm.tv_sec, time, m_timeZone);
if (!tm.tv_usec)
{

View File

@ -649,11 +649,14 @@ bool anyNullInTheColumn(THD* thd, string& schema, string& table, string& columnN
csep.returnedCols(returnedColumnList);
SimpleFilter* sf = new SimpleFilter();
sf->timeZone(thd->variables.time_zone->get_name()->ptr());
const char* timeZone = thd->variables.time_zone->get_name()->ptr();
long timeZoneOffset;
dataconvert::timeZoneToOffset(timeZone, strlen(timeZone), &timeZoneOffset);
sf->timeZone(timeZoneOffset);
boost::shared_ptr<Operator> sop(new PredicateOperator("isnull"));
sf->op(sop);
ConstantColumn* rhs = new ConstantColumn("", ConstantColumn::NULLDATA);
rhs->timeZone(thd->variables.time_zone->get_name()->ptr());
rhs->timeZone(timeZoneOffset);
sf->lhs(col[0]->clone());
sf->rhs(rhs);
@ -799,6 +802,10 @@ int ProcessDDLStatement(string& ddlStatement, string& schema, const string& tabl
if (valConfig.compare("YES") == 0)
isVarbinaryAllowed = true;
const char* timeZone = thd->variables.time_zone->get_name()->ptr();
long timeZoneOffset;
dataconvert::timeZoneToOffset(timeZone, strlen(timeZone), &timeZoneOffset);
//@Bug 1771. error out for not supported feature.
if (typeid(stmt) == typeid(CreateTableStatement))
{
@ -901,9 +908,9 @@ int ProcessDDLStatement(string& ddlStatement, string& schema, const string& tabl
try
{
convertedVal = colType.convertColumnData(
createTable->fTableDef->fColumns[i]->fDefaultValue->fValue, pushWarning,
thd->variables.time_zone->get_name()->ptr(), false, false, false);
convertedVal =
colType.convertColumnData(createTable->fTableDef->fColumns[i]->fDefaultValue->fValue,
pushWarning, timeZoneOffset, false, false, false);
}
catch (std::exception&)
{
@ -1143,7 +1150,7 @@ int ProcessDDLStatement(string& ddlStatement, string& schema, const string& tabl
algorithm::to_lower(alterTable->fTableName->fName);
}
alterTable->fTimeZone.assign(thd->variables.time_zone->get_name()->ptr());
alterTable->setTimeZone(timeZoneOffset);
if (schema.length() == 0)
{
@ -1313,9 +1320,8 @@ int ProcessDDLStatement(string& ddlStatement, string& schema, const string& tabl
try
{
convertedVal = colType.convertColumnData(
addColumnPtr->fColumnDef->fDefaultValue->fValue, pushWarning,
thd->variables.time_zone->get_name()->ptr(), false, false, false);
convertedVal = colType.convertColumnData(addColumnPtr->fColumnDef->fDefaultValue->fValue,
pushWarning, timeZoneOffset, false, false, false);
}
catch (std::exception&)
{
@ -1698,9 +1704,8 @@ int ProcessDDLStatement(string& ddlStatement, string& schema, const string& tabl
try
{
convertedVal = colType.convertColumnData(
addColumnsPtr->fColumns[0]->fDefaultValue->fValue, pushWarning,
thd->variables.time_zone->get_name()->ptr(), false, false, false);
convertedVal = colType.convertColumnData(addColumnsPtr->fColumns[0]->fDefaultValue->fValue,
pushWarning, timeZoneOffset, false, false, false);
}
catch (std::exception&)
{

View File

@ -337,7 +337,10 @@ int doProcessInsertValues(TABLE* table, uint32_t size, cal_connection_info& ci,
pDMLPackage->set_TableName(name);
name = table->s->db.str;
pDMLPackage->set_SchemaName(name);
pDMLPackage->set_TimeZone(thd->variables.time_zone->get_name()->ptr());
const char* timeZone = thd->variables.time_zone->get_name()->ptr();
long timeZoneOffset;
dataconvert::timeZoneToOffset(timeZone, strlen(timeZone), &timeZoneOffset);
pDMLPackage->set_TimeZone(timeZoneOffset);
if (thd->lex->sql_command == SQLCOM_INSERT_SELECT)
pDMLPackage->set_isInsertSelect(true);
@ -676,7 +679,8 @@ int ha_mcs_impl_write_row_(const uchar* buf, TABLE* table, cal_connection_info&
}
}
int ha_mcs_impl_write_batch_row_(const uchar* buf, TABLE* table, cal_impl_if::cal_connection_info& ci)
int ha_mcs_impl_write_batch_row_(const uchar* buf, TABLE* table, cal_impl_if::cal_connection_info& ci,
long timeZone)
{
ByteStream rowData;
int rc = 0;
@ -746,7 +750,7 @@ int ha_mcs_impl_write_batch_row_(const uchar* buf, TABLE* table, cal_impl_if::ca
Field* fieldPtr = table->field[colpos];
uint32_t mbmaxlen =
(fieldPtr->charset() && fieldPtr->charset()->mbmaxlen) ? fieldPtr->charset()->mbmaxlen : 0;
datatypes::WriteBatchFieldMariaDB field(fieldPtr, colType, mbmaxlen);
datatypes::WriteBatchFieldMariaDB field(fieldPtr, colType, mbmaxlen, timeZone);
idbassert(table == table->field[colpos]->table);
buf += h->ColWriteBatch(&field, buf, nullVal, writer);
}

View File

@ -1509,7 +1509,7 @@ uint32_t buildJoin(gp_walk_info& gwi, List<TABLE_LIST>& join_list,
return 0;
}
ParseTree* buildRowPredicate(THD* thd, RowColumn* lhs, RowColumn* rhs, string predicateOp)
ParseTree* buildRowPredicate(gp_walk_info* gwip, RowColumn* lhs, RowColumn* rhs, string predicateOp)
{
PredicateOperator* po = new PredicateOperator(predicateOp);
boost::shared_ptr<Operator> sop(po);
@ -1523,7 +1523,7 @@ ParseTree* buildRowPredicate(THD* thd, RowColumn* lhs, RowColumn* rhs, string pr
ParseTree* pt = new ParseTree(lo);
sop->setOpType(lhs->columnVec()[0]->resultType(), rhs->columnVec()[0]->resultType());
SimpleFilter* sf = new SimpleFilter(sop, lhs->columnVec()[0].get(), rhs->columnVec()[0].get());
sf->timeZone(thd->variables.time_zone->get_name()->ptr());
sf->timeZone(gwip->timeZone);
pt->left(new ParseTree(sf));
for (uint32_t i = 1; i < lhs->columnVec().size(); i++)
@ -1531,7 +1531,7 @@ ParseTree* buildRowPredicate(THD* thd, RowColumn* lhs, RowColumn* rhs, string pr
sop.reset(po->clone());
sop->setOpType(lhs->columnVec()[i]->resultType(), rhs->columnVec()[i]->resultType());
SimpleFilter* sf = new SimpleFilter(sop, lhs->columnVec()[i].get(), rhs->columnVec()[i].get());
sf->timeZone(thd->variables.time_zone->get_name()->ptr());
sf->timeZone(gwip->timeZone);
pt->right(new ParseTree(sf));
if (i + 1 < lhs->columnVec().size())
@ -1551,7 +1551,7 @@ bool buildRowColumnFilter(gp_walk_info* gwip, RowColumn* rhs, RowColumn* lhs, It
{
// (c1,c2,..) = (v1,v2,...) transform to: c1=v1 and c2=v2 and ...
assert(!lhs->columnVec().empty() && lhs->columnVec().size() == rhs->columnVec().size());
gwip->ptWorkStack.push(buildRowPredicate(gwip->thd, rhs, lhs, ifp->func_name()));
gwip->ptWorkStack.push(buildRowPredicate(gwip, rhs, lhs, ifp->func_name()));
}
else if (ifp->functype() == Item_func::IN_FUNC)
{
@ -1595,7 +1595,7 @@ bool buildRowColumnFilter(gp_walk_info* gwip, RowColumn* rhs, RowColumn* lhs, It
RowColumn* vals = dynamic_cast<RowColumn*>(tmpStack.top());
valVec.push_back(vals);
tmpStack.pop();
ParseTree* pt = buildRowPredicate(gwip->thd, columns, vals, predicateOp);
ParseTree* pt = buildRowPredicate(gwip, columns, vals, predicateOp);
while (!tmpStack.empty())
{
@ -1604,7 +1604,7 @@ bool buildRowColumnFilter(gp_walk_info* gwip, RowColumn* rhs, RowColumn* lhs, It
vals = dynamic_cast<RowColumn*>(tmpStack.top());
valVec.push_back(vals);
tmpStack.pop();
pt1->right(buildRowPredicate(gwip->thd, columns->clone(), vals, predicateOp));
pt1->right(buildRowPredicate(gwip, columns->clone(), vals, predicateOp));
pt = pt1;
}
@ -1646,8 +1646,8 @@ bool buildRowColumnFilter(gp_walk_info* gwip, RowColumn* rhs, RowColumn* lhs, It
break;
sop->setOpType(sc->resultType(), valVec[j]->columnVec()[i]->resultType());
cf->pushFilter(new SimpleFilter(sop, sc->clone(), valVec[j]->columnVec()[i]->clone(),
gwip->thd->variables.time_zone->get_name()->ptr()));
cf->pushFilter(
new SimpleFilter(sop, sc->clone(), valVec[j]->columnVec()[i]->clone(), gwip->timeZone));
}
if (j < valVec.size())
@ -1792,7 +1792,7 @@ bool buildEqualityPredicate(execplan::ReturnedColumn* lhs, execplan::ReturnedCol
}
SimpleFilter* sf = new SimpleFilter();
sf->timeZone(gwip->thd->variables.time_zone->get_name()->ptr());
sf->timeZone(gwip->timeZone);
//@bug 2101 for when there are only constants in a delete or update where clause (eg "where 5 < 6").
// There will be no field column and it will get here only if the comparison is true.
@ -1906,11 +1906,11 @@ bool buildPredicateItem(Item_func* ifp, gp_walk_info* gwip)
sop.reset(new PredicateOperator(">"));
sop->setOpType(filterCol->resultType(), rhs->resultType());
sfr = new SimpleFilter(sop, filterCol, rhs);
sfr->timeZone(gwip->thd->variables.time_zone->get_name()->ptr());
sfr->timeZone(gwip->timeZone);
sop.reset(new PredicateOperator("<"));
sop->setOpType(filterCol->resultType(), lhs->resultType());
sfl = new SimpleFilter(sop, filterCol->clone(), lhs);
sfl->timeZone(gwip->thd->variables.time_zone->get_name()->ptr());
sfl->timeZone(gwip->timeZone);
ParseTree* ptp = new ParseTree(new LogicOperator("or"));
ptp->left(sfr);
ptp->right(sfl);
@ -1921,11 +1921,11 @@ bool buildPredicateItem(Item_func* ifp, gp_walk_info* gwip)
sop.reset(new PredicateOperator("<="));
sop->setOpType(filterCol->resultType(), rhs->resultType());
sfr = new SimpleFilter(sop, filterCol, rhs);
sfr->timeZone(gwip->thd->variables.time_zone->get_name()->ptr());
sfr->timeZone(gwip->timeZone);
sop.reset(new PredicateOperator(">="));
sop->setOpType(filterCol->resultType(), lhs->resultType());
sfl = new SimpleFilter(sop, filterCol->clone(), lhs);
sfl->timeZone(gwip->thd->variables.time_zone->get_name()->ptr());
sfl->timeZone(gwip->timeZone);
ParseTree* ptp = new ParseTree(new LogicOperator("and"));
ptp->left(sfr);
ptp->right(sfl);
@ -1985,8 +1985,7 @@ bool buildPredicateItem(Item_func* ifp, gp_walk_info* gwip)
cf->op(sop);
sop.reset(new PredicateOperator(eqop));
sop->setOpType(gwip->scsp->resultType(), lhs->resultType());
cf->pushFilter(
new SimpleFilter(sop, gwip->scsp->clone(), lhs, gwip->thd->variables.time_zone->get_name()->ptr()));
cf->pushFilter(new SimpleFilter(sop, gwip->scsp->clone(), lhs, gwip->timeZone));
while (!gwip->rcWorkStack.empty())
{
@ -1998,8 +1997,7 @@ bool buildPredicateItem(Item_func* ifp, gp_walk_info* gwip)
gwip->rcWorkStack.pop();
sop.reset(new PredicateOperator(eqop));
sop->setOpType(gwip->scsp->resultType(), lhs->resultType());
cf->pushFilter(
new SimpleFilter(sop, gwip->scsp->clone(), lhs, gwip->thd->variables.time_zone->get_name()->ptr()));
cf->pushFilter(new SimpleFilter(sop, gwip->scsp->clone(), lhs, gwip->timeZone));
}
if (!gwip->rcWorkStack.empty())
@ -2065,8 +2063,7 @@ bool buildPredicateItem(Item_func* ifp, gp_walk_info* gwip)
{
gwip->rcWorkStack.push(new ConstantColumn((int64_t)udf->val_int()));
}
(dynamic_cast<ConstantColumn*>(gwip->rcWorkStack.top()))
->timeZone(gwip->thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(gwip->rcWorkStack.top()))->timeZone(gwip->timeZone);
}
else
{
@ -2088,8 +2085,7 @@ bool buildPredicateItem(Item_func* ifp, gp_walk_info* gwip)
{
gwip->rcWorkStack.push(new ConstantColumn(buf.ptr(), ConstantColumn::NUM));
}
(dynamic_cast<ConstantColumn*>(gwip->rcWorkStack.top()))
->timeZone(gwip->thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(gwip->rcWorkStack.top()))->timeZone(gwip->timeZone);
return false;
}
@ -2265,19 +2261,19 @@ bool buildPredicateItem(Item_func* ifp, gp_walk_info* gwip)
SimpleFilter* sfo = 0;
// b IS NULL
ConstantColumn* nlhs1 = new ConstantColumn("", ConstantColumn::NULLDATA);
nlhs1->timeZone(gwip->thd->variables.time_zone->get_name()->ptr());
nlhs1->timeZone(gwip->timeZone);
sop.reset(new PredicateOperator("isnull"));
sop->setOpType(lhs->resultType(), rhs->resultType());
sfn1 = new SimpleFilter(sop, rhs, nlhs1);
sfn1->timeZone(gwip->thd->variables.time_zone->get_name()->ptr());
sfn1->timeZone(gwip->timeZone);
ParseTree* ptpl = new ParseTree(sfn1);
// a IS NULL
ConstantColumn* nlhs2 = new ConstantColumn("", ConstantColumn::NULLDATA);
nlhs2->timeZone(gwip->thd->variables.time_zone->get_name()->ptr());
nlhs2->timeZone(gwip->timeZone);
sop.reset(new PredicateOperator("isnull"));
sop->setOpType(lhs->resultType(), rhs->resultType());
sfn2 = new SimpleFilter(sop, lhs, nlhs2);
sfn2->timeZone(gwip->thd->variables.time_zone->get_name()->ptr());
sfn2->timeZone(gwip->timeZone);
ParseTree* ptpr = new ParseTree(sfn2);
// AND them both
ParseTree* ptpn = new ParseTree(new LogicOperator("and"));
@ -2287,7 +2283,7 @@ bool buildPredicateItem(Item_func* ifp, gp_walk_info* gwip)
sop.reset(new PredicateOperator("="));
sop->setOpType(lhs->resultType(), rhs->resultType());
sfo = new SimpleFilter(sop, lhs->clone(), rhs->clone());
sfo->timeZone(gwip->thd->variables.time_zone->get_name()->ptr());
sfo->timeZone(gwip->timeZone);
// OR with the NULL comparison tree
ParseTree* ptp = new ParseTree(new LogicOperator("or"));
ptp->left(sfo);
@ -2337,7 +2333,7 @@ bool buildPredicateItem(Item_func* ifp, gp_walk_info* gwip)
bool buildConstPredicate(Item_func* ifp, ReturnedColumn* rhs, gp_walk_info* gwip)
{
SimpleFilter* sf = new SimpleFilter();
sf->timeZone(gwip->thd->variables.time_zone->get_name()->ptr());
sf->timeZone(gwip->timeZone);
boost::shared_ptr<Operator> sop(new PredicateOperator(ifp->func_name()));
ConstantColumn* lhs = 0;
@ -2356,7 +2352,7 @@ bool buildConstPredicate(Item_func* ifp, ReturnedColumn* rhs, gp_walk_info* gwip
lhs = new ConstantColumn((int64_t)0, ConstantColumn::NUM);
sop.reset(new PredicateOperator("="));
}
lhs->timeZone(gwip->thd->variables.time_zone->get_name()->ptr());
lhs->timeZone(gwip->timeZone);
CalpontSystemCatalog::ColType opType = rhs->resultType();
@ -2431,7 +2427,7 @@ SimpleColumn* buildSimpleColFromDerivedTable(gp_walk_info& gwi, Item_field* ifp)
sc->tableAlias(gwi.tbList[i].alias);
sc->viewName(viewName, lower_case_table_names);
sc->resultType(ct);
sc->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
sc->timeZone(gwi.timeZone);
break;
}
}
@ -2490,7 +2486,7 @@ SimpleColumn* buildSimpleColFromDerivedTable(gp_walk_info& gwi, Item_field* ifp)
sc->tableName(csep->derivedTbAlias());
sc->colPosition(j);
sc->tableAlias(csep->derivedTbAlias());
sc->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
sc->timeZone(gwi.timeZone);
if (!viewName.empty())
{
sc->viewName(viewName, lower_case_table_names);
@ -2613,7 +2609,7 @@ void collectAllCols(gp_walk_info& gwi, Item_field* ifp)
sc->tableAlias(csep->derivedTbAlias());
sc->viewName(gwi.tbList[i].view);
sc->resultType(cols[j]->resultType());
sc->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
sc->timeZone(gwi.timeZone);
// @bug5634 derived table optimization
cols[j]->incRefCount();
@ -2661,7 +2657,7 @@ void collectAllCols(gp_walk_info& gwi, Item_field* ifp)
sc->resultType(ct);
sc->tableAlias(gwi.tbList[i].alias, lower_case_table_names);
sc->viewName(viewName, lower_case_table_names);
sc->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
sc->timeZone(gwi.timeZone);
srcp.reset(sc);
gwi.returnedCols.push_back(srcp);
gwi.columnMap.insert(CalpontSelectExecutionPlan::ColumnMap::value_type(sc->columnName(), srcp));
@ -2994,7 +2990,7 @@ SimpleColumn* getSmallestColumn(boost::shared_ptr<CalpontSystemCatalog> csc,
sc->columnName(rc->alias());
sc->sequence(0);
sc->tableAlias(tan.alias);
sc->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
sc->timeZone(gwi.timeZone);
sc->derivedTable(csep->derivedTbAlias());
sc->derivedRefCol(rc);
return sc;
@ -3013,7 +3009,7 @@ SimpleColumn* getSmallestColumn(boost::shared_ptr<CalpontSystemCatalog> csc,
tan.fisColumnStore, gwi.sessionid, lower_case_table_names);
sc->tableAlias(table->alias.ptr(), lower_case_table_names);
sc->isColumnStore(false);
sc->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
sc->timeZone(gwi.timeZone);
sc->resultType(fieldType_MysqlToIDB(field));
sc->oid(field->field_index + 1);
return sc;
@ -3043,7 +3039,7 @@ SimpleColumn* getSmallestColumn(boost::shared_ptr<CalpontSystemCatalog> csc,
SimpleColumn* sc = new SimpleColumn(tcn.schema, tcn.table, tcn.column, csc->sessionID());
sc->tableAlias(tan.alias);
sc->viewName(tan.view);
sc->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
sc->timeZone(gwi.timeZone);
sc->resultType(csc->colType(oidlist[minWidthColOffset].objnum));
sc->charsetNumber(table->field[minWidthColOffset]->charset()->number);
return sc;
@ -3209,7 +3205,7 @@ ReturnedColumn* buildReturnedColumnNull(gp_walk_info& gwi)
return new SimpleColumn("noop");
ConstantColumn* rc = new ConstantColumnNull();
if (rc)
rc->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
rc->timeZone(gwi.timeZone);
return rc;
}
@ -3346,7 +3342,7 @@ static ConstantColumn* buildConstantColumnMaybeNullFromValStr(const Item* item,
{
ConstantColumn* rc = newConstantColumnMaybeNullFromValStrNoTz(item, valStr, gwi);
if (rc)
rc->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
rc->timeZone(gwi.timeZone);
return rc;
}
@ -3365,7 +3361,7 @@ static ConstantColumn* buildConstantColumnNotNullUsingValNative(Item* item, gp_w
{
ConstantColumn* rc = newConstantColumnNotNullUsingValNativeNoTz(item, gwi);
if (rc)
rc->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
rc->timeZone(gwi.timeZone);
return rc;
}
@ -3565,7 +3561,7 @@ ArithmeticColumn* buildArithmeticColumn(Item_func* item, gp_walk_info& gwi, bool
ArithmeticColumn* ac = new ArithmeticColumn();
Item** sfitempp = item->arguments();
ArithmeticOperator* aop = new ArithmeticOperator(item->func_name());
aop->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
aop->timeZone(gwi.timeZone);
aop->setOverflowCheck(get_decimal_overflow_check(gwi.thd));
ParseTree* pt = new ParseTree(aop);
// ReturnedColumn *lhs = 0, *rhs = 0;
@ -3692,7 +3688,7 @@ ArithmeticColumn* buildArithmeticColumn(Item_func* item, gp_walk_info& gwi, bool
else
{
ConstantColumn* cc = new ConstantColumn(string("0"), (int64_t)0);
cc->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
cc->timeZone(gwi.timeZone);
if (gwi.clauseType == SELECT || gwi.clauseType == HAVING || gwi.clauseType == GROUP_BY) // select clause
{
@ -4065,15 +4061,14 @@ ReturnedColumn* buildFunctionColumn(Item_func* ifp, gp_walk_info& gwi, bool& non
THD* thd = current_thd;
sptp.reset(
new ParseTree(new ConstantColumn(static_cast<uint64_t>(thd->variables.default_week_format))));
(dynamic_cast<ConstantColumn*>(sptp->data()))
->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(sptp->data()))->timeZone(gwi.timeZone);
funcParms.push_back(sptp);
}
// add the keyword unit argument for interval function
if (funcName == "date_add_interval" || funcName == "extract" || funcName == "timestampdiff")
{
addIntervalArgs(gwi.thd, ifp, funcParms);
addIntervalArgs(&gwi, ifp, funcParms);
}
// check for unsupported arguments add the keyword unit argument for extract functions
@ -4123,19 +4118,19 @@ ReturnedColumn* buildFunctionColumn(Item_func* ifp, gp_walk_info& gwi, bool& non
// add the keyword unit argument and char length for cast functions
if (funcName == "cast_as_char")
{
castCharArgs(gwi.thd, ifp, funcParms);
castCharArgs(&gwi, ifp, funcParms);
}
// add the length and scale arguments
if (funcName == "decimal_typecast")
{
castDecimalArgs(gwi.thd, ifp, funcParms);
castDecimalArgs(&gwi, ifp, funcParms);
}
// add the type argument
if (funcName == "get_format")
{
castTypeArgs(gwi.thd, ifp, funcParms);
castTypeArgs(&gwi, ifp, funcParms);
}
// add my_time_zone
@ -4150,8 +4145,7 @@ ReturnedColumn* buildFunctionColumn(Item_func* ifp, gp_walk_info& gwi, bool& non
// FIXME: Get GMT offset (in seconds east of GMT) in Windows...
sptp.reset(new ParseTree(new ConstantColumn(static_cast<int64_t>(0), ConstantColumn::NUM)));
#endif
(dynamic_cast<ConstantColumn*>(sptp->data()))
->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(sptp->data()))->timeZone(gwi.timeZone);
funcParms.push_back(sptp);
}
@ -4161,12 +4155,10 @@ ReturnedColumn* buildFunctionColumn(Item_func* ifp, gp_walk_info& gwi, bool& non
if (funcParms.size() == 0)
{
sptp.reset(new ParseTree(new ConstantColumn((int64_t)gwi.thd->rand.seed1, ConstantColumn::NUM)));
(dynamic_cast<ConstantColumn*>(sptp->data()))
->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(sptp->data()))->timeZone(gwi.timeZone);
funcParms.push_back(sptp);
sptp.reset(new ParseTree(new ConstantColumn((int64_t)gwi.thd->rand.seed2, ConstantColumn::NUM)));
(dynamic_cast<ConstantColumn*>(sptp->data()))
->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(sptp->data()))->timeZone(gwi.timeZone);
funcParms.push_back(sptp);
gwi.no_parm_func_list.push_back(fc);
}
@ -4220,8 +4212,7 @@ ReturnedColumn* buildFunctionColumn(Item_func* ifp, gp_walk_info& gwi, bool& non
tzinfo = string((char*)buf, length);
}
sptp.reset(new ParseTree(new ConstantColumn(tzinfo)));
(dynamic_cast<ConstantColumn*>(sptp->data()))
->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(sptp->data()))->timeZone(gwi.timeZone);
funcParms.push_back(sptp);
tzinfo.clear();
if (to_tzinfo)
@ -4233,8 +4224,7 @@ ReturnedColumn* buildFunctionColumn(Item_func* ifp, gp_walk_info& gwi, bool& non
tzinfo = string((char*)buf, length);
}
sptp.reset(new ParseTree(new ConstantColumn(tzinfo)));
(dynamic_cast<ConstantColumn*>(sptp->data()))
->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(sptp->data()))->timeZone(gwi.timeZone);
funcParms.push_back(sptp);
tzinfo.clear();
}
@ -4253,8 +4243,7 @@ ReturnedColumn* buildFunctionColumn(Item_func* ifp, gp_walk_info& gwi, bool& non
sign = -1;
}
sptp.reset(new ParseTree(new ConstantColumn(sign)));
(dynamic_cast<ConstantColumn*>(sptp->data()))
->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(sptp->data()))->timeZone(gwi.timeZone);
funcParms.push_back(sptp);
}
@ -4327,16 +4316,23 @@ ReturnedColumn* buildFunctionColumn(Item_func* ifp, gp_walk_info& gwi, bool& non
#endif
fc->operationType(functor->operationType(funcParms, fc->resultType()));
// For some reason, MDB has MYSQL_TYPE_DATETIME2 for functions on a TIMESTAMP
if (fc->operationType().colDataType == CalpontSystemCatalog::TIMESTAMP)
execplan::CalpontSystemCatalog::ColType& resultType = fc->resultType();
resultType.setTimeZone(gwi.timeZone);
fc->operationType(functor->operationType(funcParms, resultType));
// For floor/ceiling/truncate/round functions applied on TIMESTAMP columns, set the
// function result type to TIMESTAMP
if ((funcName == "floor" || funcName == "ceiling" || funcName == "truncate" || funcName == "round") &&
fc->operationType().colDataType == CalpontSystemCatalog::TIMESTAMP)
{
CalpontSystemCatalog::ColType ct = fc->resultType();
ct.colDataType = CalpontSystemCatalog::TIMESTAMP;
ct.colWidth = 8;
fc->resultType(ct);
}
fc->expressionId(ci->expressionId++);
// A few functions use a different collation than that found in
// the base ifp class
if (funcName == "locate" || funcName == "find_in_set" || funcName == "strcmp")
@ -4409,7 +4405,7 @@ ReturnedColumn* buildFunctionColumn(Item_func* ifp, gp_walk_info& gwi, bool& non
}
}
fc->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
fc->timeZone(gwi.timeZone);
return fc;
}
@ -4549,11 +4545,13 @@ FunctionColumn* buildCaseFunction(Item_func* item, gp_walk_info& gwi, bool& nonS
Func* functor = funcexp->getFunctor(funcName);
fc->resultType(colType_MysqlToIDB(item));
fc->operationType(functor->operationType(funcParms, fc->resultType()));
execplan::CalpontSystemCatalog::ColType& resultType = fc->resultType();
resultType.setTimeZone(gwi.timeZone);
fc->operationType(functor->operationType(funcParms, resultType));
fc->functionName(funcName);
fc->functionParms(funcParms);
fc->expressionId(ci->expressionId++);
fc->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
fc->timeZone(gwi.timeZone);
// For function join. If any argument has non-zero joininfo, set it to the function.
fc->setSimpleColumnList();
@ -4695,7 +4693,7 @@ SimpleColumn* buildSimpleColumn(Item_field* ifp, gp_walk_info& gwi)
sc->alias(ifp->name.str);
sc->isColumnStore(prm.columnStore());
sc->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
sc->timeZone(gwi.timeZone);
if (!prm.columnStore() && ifp->field)
sc->oid(ifp->field->field_index + 1); // ExeMgr requires offset started from 1
@ -4803,7 +4801,7 @@ static void processAggregateColumnConstArg(gp_walk_info& gwi, SRCP& parm, Aggreg
{
// Explicit NULL or a const function that evaluated to NULL
cc = new ConstantColumnNull();
cc->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
cc->timeZone(gwi.timeZone);
parm.reset(cc);
ac->constCol(SRCP(rt));
return;
@ -4878,7 +4876,7 @@ ReturnedColumn* buildAggregateColumn(Item* item, gp_walk_info& gwi)
ac = new AggregateColumn(gwi.sessionid);
}
ac->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
ac->timeZone(gwi.timeZone);
if (isp->name.length)
ac->alias(isp->name.str);
@ -5397,7 +5395,7 @@ because it has multiple arguments.";
return ac;
}
void addIntervalArgs(THD* thd, Item_func* ifp, FunctionParm& functionParms)
void addIntervalArgs(gp_walk_info* gwip, Item_func* ifp, FunctionParm& functionParms)
{
string funcName = ifp->func_name();
int interval_type = -1;
@ -5409,7 +5407,7 @@ void addIntervalArgs(THD* thd, Item_func* ifp, FunctionParm& functionParms)
else if (funcName == "extract")
interval_type = ((Item_extract*)ifp)->int_type;
functionParms.push_back(getIntervalType(thd, interval_type));
functionParms.push_back(getIntervalType(gwip, interval_type));
SPTP sptp;
if (funcName == "date_add_interval")
@ -5417,42 +5415,42 @@ void addIntervalArgs(THD* thd, Item_func* ifp, FunctionParm& functionParms)
if (((Item_date_add_interval*)ifp)->date_sub_interval)
{
sptp.reset(new ParseTree(new ConstantColumn((int64_t)OP_SUB)));
(dynamic_cast<ConstantColumn*>(sptp->data()))->timeZone(thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(sptp->data()))->timeZone(gwip->timeZone);
functionParms.push_back(sptp);
}
else
{
sptp.reset(new ParseTree(new ConstantColumn((int64_t)OP_ADD)));
(dynamic_cast<ConstantColumn*>(sptp->data()))->timeZone(thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(sptp->data()))->timeZone(gwip->timeZone);
functionParms.push_back(sptp);
}
}
}
SPTP getIntervalType(THD* thd, int interval_type)
SPTP getIntervalType(gp_walk_info* gwip, int interval_type)
{
SPTP sptp;
sptp.reset(new ParseTree(new ConstantColumn((int64_t)interval_type)));
(dynamic_cast<ConstantColumn*>(sptp->data()))->timeZone(thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(sptp->data()))->timeZone(gwip->timeZone);
return sptp;
}
void castCharArgs(THD* thd, Item_func* ifp, FunctionParm& functionParms)
void castCharArgs(gp_walk_info* gwip, Item_func* ifp, FunctionParm& functionParms)
{
Item_char_typecast* idai = (Item_char_typecast*)ifp;
SPTP sptp;
sptp.reset(new ParseTree(new ConstantColumn((int64_t)idai->get_cast_length())));
(dynamic_cast<ConstantColumn*>(sptp->data()))->timeZone(thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(sptp->data()))->timeZone(gwip->timeZone);
functionParms.push_back(sptp);
}
void castDecimalArgs(THD* thd, Item_func* ifp, FunctionParm& functionParms)
void castDecimalArgs(gp_walk_info* gwip, Item_func* ifp, FunctionParm& functionParms)
{
Item_decimal_typecast* idai = (Item_decimal_typecast*)ifp;
SPTP sptp;
sptp.reset(new ParseTree(new ConstantColumn((int64_t)idai->decimals)));
(dynamic_cast<ConstantColumn*>(sptp->data()))->timeZone(thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(sptp->data()))->timeZone(gwip->timeZone);
functionParms.push_back(sptp);
// max length including sign and/or decimal points
@ -5460,12 +5458,12 @@ void castDecimalArgs(THD* thd, Item_func* ifp, FunctionParm& functionParms)
sptp.reset(new ParseTree(new ConstantColumn((int64_t)idai->max_length - 1)));
else
sptp.reset(new ParseTree(new ConstantColumn((int64_t)idai->max_length - 2)));
(dynamic_cast<ConstantColumn*>(sptp->data()))->timeZone(thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(sptp->data()))->timeZone(gwip->timeZone);
functionParms.push_back(sptp);
}
void castTypeArgs(THD* thd, Item_func* ifp, FunctionParm& functionParms)
void castTypeArgs(gp_walk_info* gwip, Item_func* ifp, FunctionParm& functionParms)
{
Item_func_get_format* get_format = (Item_func_get_format*)ifp;
SPTP sptp;
@ -5474,7 +5472,7 @@ void castTypeArgs(THD* thd, Item_func* ifp, FunctionParm& functionParms)
sptp.reset(new ParseTree(new ConstantColumn("DATE")));
else
sptp.reset(new ParseTree(new ConstantColumn("DATETIME")));
(dynamic_cast<ConstantColumn*>(sptp->data()))->timeZone(thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(sptp->data()))->timeZone(gwip->timeZone);
functionParms.push_back(sptp);
}
@ -5575,7 +5573,7 @@ void gp_walk(const Item* item, void* arg)
Item_hex_hybrid* hip = reinterpret_cast<Item_hex_hybrid*>(const_cast<Item*>(item));
gwip->rcWorkStack.push(new ConstantColumn((int64_t)hip->val_int(), ConstantColumn::NUM));
ConstantColumn* cc = dynamic_cast<ConstantColumn*>(gwip->rcWorkStack.top());
cc->timeZone(gwip->thd->variables.time_zone->get_name()->ptr());
cc->timeZone(gwip->timeZone);
break;
}
@ -5594,8 +5592,7 @@ void gp_walk(const Item* item, void* arg)
}
gwip->rcWorkStack.push(new ConstantColumn(cval));
(dynamic_cast<ConstantColumn*>(gwip->rcWorkStack.top()))
->timeZone(gwip->thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(gwip->rcWorkStack.top()))->timeZone(gwip->timeZone);
break;
}
@ -5630,7 +5627,7 @@ void gp_walk(const Item* item, void* arg)
{
// push noop for unhandled item
SimpleColumn* rc = new SimpleColumn("noop");
rc->timeZone(gwip->thd->variables.time_zone->get_name()->ptr());
rc->timeZone(gwip->timeZone);
gwip->rcWorkStack.push(rc);
break;
}
@ -5650,14 +5647,13 @@ void gp_walk(const Item* item, void* arg)
{
// push noop for unhandled item
SimpleColumn* rc = new SimpleColumn("noop");
rc->timeZone(gwip->thd->variables.time_zone->get_name()->ptr());
rc->timeZone(gwip->timeZone);
gwip->rcWorkStack.push(rc);
break;
}
gwip->rcWorkStack.push(new ConstantColumn("", ConstantColumn::NULLDATA));
(dynamic_cast<ConstantColumn*>(gwip->rcWorkStack.top()))
->timeZone(gwip->thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(gwip->rcWorkStack.top()))->timeZone(gwip->timeZone);
break;
}
@ -6175,7 +6171,7 @@ void gp_walk(const Item* item, void* arg)
{
// push noop for unhandled item
SimpleColumn* rc = new SimpleColumn("noop");
rc->timeZone(gwip->thd->variables.time_zone->get_name()->ptr());
rc->timeZone(gwip->timeZone);
gwip->rcWorkStack.push(rc);
break;
}
@ -6664,7 +6660,7 @@ int processFrom(bool& isUnion, SELECT_LEX& select_lex, gp_walk_info& gwi, SCSEP&
plan->data(csep->data());
// gwi for the union unit
gp_walk_info union_gwi;
gp_walk_info union_gwi(gwi.timeZone);
union_gwi.thd = gwi.thd;
uint32_t err = 0;
@ -6777,8 +6773,7 @@ int processWhere(SELECT_LEX& select_lex, gp_walk_info& gwi, SCSEP& csep, const s
else if (join && join->zero_result_cause)
{
gwi.rcWorkStack.push(new ConstantColumn((int64_t)0, ConstantColumn::NUM));
(dynamic_cast<ConstantColumn*>(gwi.rcWorkStack.top()))
->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(gwi.rcWorkStack.top()))->timeZone(gwi.timeZone);
}
for (Item* item : gwi.condList)
@ -7226,7 +7221,7 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i
gwi.sessionid = sessionID;
boost::shared_ptr<CalpontSystemCatalog> csc = CalpontSystemCatalog::makeCalpontSystemCatalog(sessionID);
csc->identity(CalpontSystemCatalog::FE);
csep->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
csep->timeZone(gwi.timeZone);
gwi.csc = csc;
CalpontSelectExecutionPlan::SelectList derivedTbList;
@ -7607,7 +7602,7 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i
selectSubList.push_back(ssub);
SimpleColumn* rc = new SimpleColumn();
rc->colSource(rc->colSource() | SELECT_SUB);
rc->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
rc->timeZone(gwi.timeZone);
if (sub->get_select_lex()->get_table_list())
{
@ -8414,7 +8409,7 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i
sc1->tableAlias(sc->tableAlias());
sc1->viewName(sc->viewName());
sc1->colPosition(0);
sc1->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
sc1->timeZone(gwi.timeZone);
minSc.reset(sc1);
}
}
@ -8473,12 +8468,12 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i
return 0;
}
int cp_get_table_plan(THD* thd, SCSEP& csep, cal_table_info& ti)
int cp_get_table_plan(THD* thd, SCSEP& csep, cal_table_info& ti, long timeZone)
{
gp_walk_info* gwi = ti.condInfo;
if (!gwi)
gwi = new gp_walk_info();
gwi = new gp_walk_info(timeZone);
gwi->thd = thd;
LEX* lex = thd->lex;
@ -8506,7 +8501,7 @@ int cp_get_table_plan(THD* thd, SCSEP& csep, cal_table_info& ti)
boost::algorithm::to_lower(alias);
}
sc->tableAlias(alias);
sc->timeZone(gwi->thd->variables.time_zone->get_name()->ptr());
sc->timeZone(gwi->timeZone);
assert(sc);
boost::shared_ptr<SimpleColumn> spsc(sc);
gwi->returnedCols.push_back(spsc);
@ -8581,7 +8576,10 @@ int cp_get_table_plan(THD* thd, SCSEP& csep, cal_table_info& ti)
int cp_get_group_plan(THD* thd, SCSEP& csep, cal_impl_if::cal_group_info& gi)
{
SELECT_LEX* select_lex = gi.groupByTables->select_lex;
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;
gwi.isGroupByHandler = true;
int status = getGroupPlan(gwi, *select_lex, csep, gi);
@ -8597,7 +8595,7 @@ int cp_get_group_plan(THD* thd, SCSEP& csep, cal_impl_if::cal_group_info& gi)
else if (status < 0)
return status;
// Derived table projection and filter optimization.
derivedTableOptimization(thd, csep);
derivedTableOptimization(&gwi, csep);
return 0;
}
@ -8618,7 +8616,7 @@ int cs_get_derived_plan(ha_columnstore_derived_handler* handler, THD* thd, SCSEP
cerr << "-------------- EXECUTION PLAN END --------------\n" << endl;
#endif
// Derived table projection and filter optimization.
derivedTableOptimization(thd, csep);
derivedTableOptimization(&gwi, csep);
return 0;
}
@ -8649,7 +8647,7 @@ int cs_get_select_plan(ha_columnstore_select_handler* handler, THD* thd, SCSEP&
cerr << "-------------- EXECUTION PLAN END --------------\n" << endl;
#endif
// Derived table projection and filter optimization.
derivedTableOptimization(thd, csep);
derivedTableOptimization(&gwi, csep);
return 0;
}
@ -8954,8 +8952,7 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro
else if (join && join->zero_result_cause)
{
gwi.rcWorkStack.push(new ConstantColumn((int64_t)0, ConstantColumn::NUM));
(dynamic_cast<ConstantColumn*>(gwi.rcWorkStack.top()))
->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(gwi.rcWorkStack.top()))->timeZone(gwi.timeZone);
}
SELECT_LEX tmp_select_lex;
@ -9443,7 +9440,7 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro
selectSubList.push_back(ssub);
SimpleColumn* rc = new SimpleColumn();
rc->colSource(rc->colSource() | SELECT_SUB);
rc->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
rc->timeZone(gwi.timeZone);
if (sub->get_select_lex()->get_table_list())
{
@ -10401,7 +10398,7 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro
sc1->tableName(sc->tableName());
sc1->tableAlias(sc->tableAlias());
sc1->viewName(sc->viewName());
sc1->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
sc1->timeZone(gwi.timeZone);
sc1->colPosition(0);
minSc.reset(sc1);
}

View File

@ -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)
{

View File

@ -29,9 +29,9 @@ extern int ha_mcs_impl_delete_table(const char* name);
extern int ha_mcs_impl_analyze(THD* thd, TABLE* table);
extern int ha_mcs_impl_open(const char* name, int mode, uint32_t test_if_locked);
extern int ha_mcs_impl_close(void);
extern int ha_mcs_impl_rnd_next(uchar* buf, TABLE* table);
extern int ha_mcs_impl_rnd_next(uchar* buf, TABLE* table, long timeZone);
extern int ha_mcs_impl_rnd_end(TABLE* table, bool is_derived_hand = false);
extern int ha_mcs_impl_write_row(const uchar* buf, TABLE* table, uint64_t rows_changed);
extern int ha_mcs_impl_write_row(const uchar* buf, TABLE* table, uint64_t rows_changed, long timeZone);
extern void ha_mcs_impl_start_bulk_insert(ha_rows rows, TABLE* table, bool is_cache_insert = false);
extern int ha_mcs_impl_end_bulk_insert(bool abort, TABLE* table);
extern int ha_mcs_impl_rename_table(const char* from, const char* to);
@ -45,9 +45,9 @@ extern int ha_mcs_impl_direct_update_delete_rows(bool execute, ha_rows* affected
extern int ha_mcs_impl_delete_row();
extern int ha_mcs_impl_rnd_pos(uchar* buf, uchar* pos);
extern int ha_mcs_impl_pushdown_init(mcs_handler_info* handler_info, TABLE* table);
extern int ha_mcs_impl_select_next(uchar* buf, TABLE* table);
extern int ha_mcs_impl_select_next(uchar* buf, TABLE* table, long timeZone);
extern int ha_mcs_impl_group_by_init(mcs_handler_info* handler_info, TABLE* table);
extern int ha_mcs_impl_group_by_next(TABLE* table);
extern int ha_mcs_impl_group_by_next(TABLE* table, long timeZone);
extern int ha_mcs_impl_group_by_end(TABLE* table);
#endif
@ -59,7 +59,8 @@ extern int ha_mcs_impl_group_by_end(TABLE* table);
extern int ha_mcs_impl_rename_table_(const char* from, const char* to, cal_impl_if::cal_connection_info& ci);
extern int ha_mcs_impl_write_row_(const uchar* buf, TABLE* table, cal_impl_if::cal_connection_info& ci,
ha_rows& rowsInserted);
extern int ha_mcs_impl_write_batch_row_(const uchar* buf, TABLE* table, cal_impl_if::cal_connection_info& ci);
extern int ha_mcs_impl_write_batch_row_(const uchar* buf, TABLE* table, cal_impl_if::cal_connection_info& ci,
long timeZone);
extern int ha_mcs_impl_write_last_batch(TABLE* table, cal_impl_if::cal_connection_info& ci, bool abort);
extern int ha_mcs_impl_commit_(handlerton* hton, THD* thd, bool all, cal_impl_if::cal_connection_info& ci);
extern int ha_mcs_impl_rollback_(handlerton* hton, THD* thd, bool all, cal_impl_if::cal_connection_info& ci);

View File

@ -165,6 +165,7 @@ struct gp_walk_info
bool cs_vtable_impossible_where_on_union;
bool isGroupByHandler;
long timeZone;
// MCOL-4617 The below 2 fields are used for in-to-exists
// predicate creation and injection. See usage in InSub::transform()
@ -176,7 +177,7 @@ struct gp_walk_info
TableOnExprList tableOnExprList;
std::vector<COND*> condList;
gp_walk_info()
gp_walk_info(long timeZone_)
: sessionid(0)
, fatalParseError(false)
, condPush(false)
@ -197,6 +198,7 @@ struct gp_walk_info
, cs_vtable_is_update_with_derive(false)
, cs_vtable_impossible_where_on_union(false)
, isGroupByHandler(false)
, timeZone(timeZone_)
, inSubQueryLHS(nullptr)
, inSubQueryLHSItem(nullptr)
{
@ -391,7 +393,7 @@ const std::string infinidb_err_msg =
"distributed syntax or consider changing the MariaDB Columnstore Operating Mode (infinidb_vtable_mode).";
int cp_get_plan(THD* thd, execplan::SCSEP& csep);
int cp_get_table_plan(THD* thd, execplan::SCSEP& csep, cal_impl_if::cal_table_info& ti);
int cp_get_table_plan(THD* thd, execplan::SCSEP& csep, cal_impl_if::cal_table_info& ti, long timeZone);
int cp_get_group_plan(THD* thd, execplan::SCSEP& csep, cal_impl_if::cal_group_info& gi);
int cs_get_derived_plan(ha_columnstore_derived_handler* handler, THD* thd, execplan::SCSEP& csep,
gp_walk_info& gwi);
@ -428,14 +430,14 @@ execplan::ReturnedColumn* buildAggregateColumn(Item* item, gp_walk_info& gwi);
execplan::ReturnedColumn* buildWindowFunctionColumn(Item* item, gp_walk_info& gwi, bool& nonSupport);
execplan::ReturnedColumn* buildPseudoColumn(Item* item, gp_walk_info& gwi, bool& nonSupport,
uint32_t pseudoType);
void addIntervalArgs(THD* thd, Item_func* ifp, funcexp::FunctionParm& functionParms);
void castCharArgs(THD* thd, Item_func* ifp, funcexp::FunctionParm& functionParms);
void castDecimalArgs(THD* thd, Item_func* ifp, funcexp::FunctionParm& functionParms);
void castTypeArgs(THD* thd, Item_func* ifp, funcexp::FunctionParm& functionParms);
void addIntervalArgs(gp_walk_info* gwip, Item_func* ifp, funcexp::FunctionParm& functionParms);
void castCharArgs(gp_walk_info* gwip, Item_func* ifp, funcexp::FunctionParm& functionParms);
void castDecimalArgs(gp_walk_info* gwip, Item_func* ifp, funcexp::FunctionParm& functionParms);
void castTypeArgs(gp_walk_info* gwip, Item_func* ifp, funcexp::FunctionParm& functionParms);
// void parse_item (Item* item, std::vector<Item_field*>& field_vec, bool& hasNonSupportItem, uint16&
// parseInfo);
bool isPredicateFunction(Item* item, gp_walk_info* gwip);
execplan::ParseTree* buildRowPredicate(THD* thd, execplan::RowColumn* lhs, execplan::RowColumn* rhs,
execplan::ParseTree* buildRowPredicate(gp_walk_info* gwip, execplan::RowColumn* lhs, execplan::RowColumn* rhs,
std::string predicateOp);
bool buildRowColumnFilter(gp_walk_info* gwip, execplan::RowColumn* rhs, execplan::RowColumn* lhs,
Item_func* ifp);
@ -448,13 +450,13 @@ std::string getViewName(TABLE_LIST* table_ptr);
bool buildConstPredicate(Item_func* ifp, execplan::ReturnedColumn* rhs, gp_walk_info* gwip);
execplan::CalpontSystemCatalog::ColType fieldType_MysqlToIDB(const Field* field);
execplan::CalpontSystemCatalog::ColType colType_MysqlToIDB(const Item* item);
execplan::SPTP getIntervalType(THD* thd, int interval_type);
execplan::SPTP getIntervalType(gp_walk_info* gwip, int interval_type);
uint32_t isPseudoColumn(std::string funcName);
void setDerivedTable(execplan::ParseTree* n);
execplan::ParseTree* setDerivedFilter(THD* thd, execplan::ParseTree*& n,
execplan::ParseTree* setDerivedFilter(gp_walk_info* gwip, execplan::ParseTree*& n,
std::map<std::string, execplan::ParseTree*>& obj,
execplan::CalpontSelectExecutionPlan::SelectList& derivedTbList);
void derivedTableOptimization(THD* thd, execplan::SCSEP& csep);
void derivedTableOptimization(gp_walk_info* gwip, execplan::SCSEP& csep);
bool buildEqualityPredicate(execplan::ReturnedColumn* lhs, execplan::ReturnedColumn* rhs, gp_walk_info* gwip,
boost::shared_ptr<execplan::Operator>& sop, const Item_func::Functype& funcType,
const std::vector<Item*>& itemList, bool isInSubs = false);

View File

@ -385,7 +385,10 @@ void partitionByValue_common(UDF_ARGS* args, // inp
csc->identity(CalpontSystemCatalog::FE);
OID_t oid = csc->lookupOID(tcn);
CalpontSystemCatalog::ColType ct = csc->colType(oid);
datatypes::SessionParam sp(current_thd->variables.time_zone->get_name()->ptr());
const char* timeZone = current_thd->variables.time_zone->get_name()->ptr();
long timeZoneOffset;
dataconvert::timeZoneToOffset(timeZone, strlen(timeZone), &timeZoneOffset);
datatypes::SessionParam sp(timeZoneOffset);
datatypes::SimpleValue startVal;
datatypes::SimpleValue endVal;
datatypes::round_style_t rfMin = datatypes::round_style_t::NONE;
@ -1252,7 +1255,10 @@ extern "C"
string schema, table, column;
CalpontSystemCatalog::ColType ct;
string errMsg;
datatypes::SessionParam sp(current_thd->variables.time_zone->get_name()->ptr());
const char* timeZone = current_thd->variables.time_zone->get_name()->ptr();
long timeZoneOffset;
dataconvert::timeZoneToOffset(timeZone, strlen(timeZone), &timeZoneOffset);
datatypes::SessionParam sp(timeZoneOffset);
datatypes::SimpleValue startVal;
datatypes::SimpleValue endVal;
datatypes::round_style_t rfMin = datatypes::round_style_t::NONE;

View File

@ -581,6 +581,8 @@ ha_columnstore_derived_handler::ha_columnstore_derived_handler(THD* thd, TABLE_L
: derived_handler(thd, mcs_hton)
{
derived = dt;
const char* timeZone = thd->variables.time_zone->get_name()->ptr();
dataconvert::timeZoneToOffset(timeZone, strlen(timeZone), &time_zone);
}
/***********************************************************
@ -625,7 +627,7 @@ int ha_columnstore_derived_handler::next_row()
{
DBUG_ENTER("ha_columnstore_derived_handler::next_row");
int rc = ha_mcs_impl_rnd_next(table->record[0], table);
int rc = ha_mcs_impl_rnd_next(table->record[0], table, time_zone);
DBUG_RETURN(rc);
}
@ -670,6 +672,8 @@ ha_mcs_group_by_handler::ha_mcs_group_by_handler(THD* thd_arg, Query* query)
, order_by(query->order_by)
, having(query->having)
{
const char* timeZone = thd_arg->variables.time_zone->get_name()->ptr();
dataconvert::timeZoneToOffset(timeZone, strlen(timeZone), &time_zone);
}
/***********************************************************
@ -705,7 +709,7 @@ int ha_mcs_group_by_handler::init_scan()
int ha_mcs_group_by_handler::next_row()
{
DBUG_ENTER("ha_mcs_group_by_handler::next_row");
int rc = ha_mcs_impl_group_by_next(table);
int rc = ha_mcs_impl_group_by_next(table, time_zone);
DBUG_RETURN(rc);
}
@ -985,6 +989,8 @@ ha_columnstore_select_handler::ha_columnstore_select_handler(THD* thd, SELECT_LE
, pushdown_init_rc(0)
{
select = select_lex;
const char* timeZone = thd->variables.time_zone->get_name()->ptr();
dataconvert::timeZoneToOffset(timeZone, strlen(timeZone), &time_zone);
}
/***********************************************************
@ -1028,7 +1034,7 @@ int ha_columnstore_select_handler::next_row()
{
DBUG_ENTER("ha_columnstore_select_handler::next_row");
int rc = ha_mcs_impl_select_next(table->record[0], table);
int rc = ha_mcs_impl_select_next(table->record[0], table, time_zone);
DBUG_RETURN(rc);
}

View File

@ -76,6 +76,9 @@ struct mcs_handler_info
***********************************************************/
class ha_mcs_group_by_handler : public group_by_handler
{
private:
long time_zone;
public:
ha_mcs_group_by_handler(THD* thd_arg, Query* query);
~ha_mcs_group_by_handler();
@ -109,6 +112,7 @@ class ha_columnstore_derived_handler : public derived_handler
{
private:
COLUMNSTORE_SHARE* share;
long time_zone;
public:
ha_columnstore_derived_handler(THD* thd_arg, TABLE_LIST* tbl);
@ -138,6 +142,7 @@ class ha_columnstore_select_handler : public select_handler
COLUMNSTORE_SHARE* share;
bool prepared;
bool scan_ended;
long time_zone;
public:
bool scan_initialized;

View File

@ -494,7 +494,7 @@ execplan::ReturnedColumn* buildPseudoColumn(Item* item, gp_walk_info& gwi, bool&
cc = new ConstantColumn(localPm);
else
cc = new ConstantColumn("", ConstantColumn::NULLDATA);
cc->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
cc->timeZone(gwi.timeZone);
cc->alias(ifp->full_name() ? ifp->full_name() : "");
return cc;
@ -556,7 +556,7 @@ execplan::ReturnedColumn* buildPseudoColumn(Item* item, gp_walk_info& gwi, bool&
parms.push_back(sptp);
fc->functionParms(parms);
fc->expressionId(ci->expressionId++);
fc->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
fc->timeZone(gwi.timeZone);
// string result type
CalpontSystemCatalog::ColType ct;

View File

@ -109,8 +109,7 @@ execplan::ParseTree* ScalarSub::transform()
{
fSub = (Item_subselect*)(fFunc->arguments()[0]);
fColumn.reset(new ConstantColumn("", ConstantColumn::NULLDATA));
(dynamic_cast<ConstantColumn*>(fColumn.get()))
->timeZone(fGwip.thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(fColumn.get()))->timeZone(fGwip.timeZone);
delete rhs;
return buildParseTree(op);
}
@ -176,7 +175,7 @@ execplan::ParseTree* ScalarSub::transform_between()
SOP sop;
sop.reset(op_LE);
rhs = new ParseTree(new SimpleFilter(sop, fColumn.get(), op3));
(dynamic_cast<SimpleFilter*>(rhs->data()))->timeZone(fGwip.thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<SimpleFilter*>(rhs->data()))->timeZone(fGwip.timeZone);
}
SubSelect* sub1 = dynamic_cast<SubSelect*>(op2);
@ -192,7 +191,7 @@ execplan::ParseTree* ScalarSub::transform_between()
SOP sop;
sop.reset(op_GE);
lhs = new ParseTree(new SimpleFilter(sop, fColumn.get(), op2));
(dynamic_cast<SimpleFilter*>(lhs->data()))->timeZone(fGwip.thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<SimpleFilter*>(lhs->data()))->timeZone(fGwip.timeZone);
}
if (!rhs || !lhs)
@ -245,7 +244,7 @@ execplan::ParseTree* ScalarSub::buildParseTree(PredicateOperator* op)
csep->subType(CalpontSelectExecutionPlan::SINGLEROW_SUBS);
// gwi for the sub query
gp_walk_info gwi;
gp_walk_info gwi(fGwip.timeZone);
gwi.thd = fGwip.thd;
gwi.subQuery = this;

View File

@ -67,7 +67,7 @@ SCSEP SelectSubQuery::transform()
csep->subType(CalpontSelectExecutionPlan::SELECT_SUBS);
// gwi for the sub query
gp_walk_info gwi;
gp_walk_info gwi(fGwip.timeZone);
gwi.thd = fGwip.thd;
gwi.subQuery = this;

View File

@ -65,7 +65,7 @@ void View::transform()
csep->sessionID(fParentGwip->sessionid);
// gwi for the sub query
gp_walk_info gwi;
gp_walk_info gwi(fParentGwip->timeZone);
gwi.thd = fParentGwip->thd;
uint32_t sessionID = csep->sessionID();

View File

@ -145,27 +145,25 @@ ReturnedColumn* buildBoundExp(WF_Boundary& bound, SRCP& order, gp_walk_info& gwi
// put interval val column to bound
(dynamic_cast<FunctionColumn*>(rc))->functionName(funcName);
(dynamic_cast<FunctionColumn*>(rc))->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<FunctionColumn*>(rc))->timeZone(gwi.timeZone);
sptp.reset(new ParseTree(order->clone()));
funcParms.push_back(sptp);
sptp.reset(new ParseTree(intervalCol->val()->clone()));
funcParms.push_back(sptp);
funcParms.push_back(getIntervalType(gwi.thd, intervalCol->intervalType()));
funcParms.push_back(getIntervalType(&gwi, intervalCol->intervalType()));
SRCP srcp(intervalCol->val());
bound.fVal = srcp;
if (addOp)
{
sptp.reset(new ParseTree(new ConstantColumn("ADD")));
(dynamic_cast<ConstantColumn*>(sptp->data()))
->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(sptp->data()))->timeZone(gwi.timeZone);
funcParms.push_back(sptp);
}
else
{
sptp.reset(new ParseTree(new ConstantColumn("SUB")));
(dynamic_cast<ConstantColumn*>(sptp->data()))
->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(sptp->data()))->timeZone(gwi.timeZone);
funcParms.push_back(sptp);
}
@ -187,7 +185,7 @@ ReturnedColumn* buildBoundExp(WF_Boundary& bound, SRCP& order, gp_walk_info& gwi
else
aop = new ArithmeticOperator("-");
aop->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
aop->timeZone(gwi.timeZone);
ParseTree* pt = new ParseTree(aop);
ParseTree *lhs = 0, *rhs = 0;
lhs = new ParseTree(order->clone());
@ -314,7 +312,7 @@ ReturnedColumn* buildWindowFunctionColumn(Item* item, gp_walk_info& gwi, bool& n
Item_sum* item_sum = wf->window_func();
string funcName = ConvertFuncName(item_sum);
WindowFunctionColumn* ac = new WindowFunctionColumn(funcName);
ac->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
ac->timeZone(gwi.timeZone);
ac->distinct(item_sum->has_with_distinct());
Window_spec* win_spec = wf->window_spec;
SRCP srcp;
@ -407,45 +405,45 @@ ReturnedColumn* buildWindowFunctionColumn(Item* item, gp_walk_info& gwi, bool& n
sprintf(sRespectNulls, "%lu", bRespectNulls);
srcp.reset(new ConstantColumn(sRespectNulls, (uint64_t)bRespectNulls,
ConstantColumn::NUM)); // IGNORE/RESPECT NULLS. 1 => RESPECT
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.timeZone);
funcParms.push_back(srcp);
break;
}
case Item_sum::FIRST_VALUE_FUNC:
srcp.reset(new ConstantColumn("1", (uint64_t)1, ConstantColumn::NUM)); // OFFSET (always one)
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.timeZone);
funcParms.push_back(srcp);
srcp.reset(new ConstantColumn("1", (uint64_t)1, ConstantColumn::NUM)); // FROM_FIRST
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.timeZone);
funcParms.push_back(srcp);
srcp.reset(
new ConstantColumn("1", (uint64_t)1, ConstantColumn::NUM)); // IGNORE/RESPECT NULLS. 1 => RESPECT
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.timeZone);
funcParms.push_back(srcp);
break;
case Item_sum::LAST_VALUE_FUNC:
srcp.reset(new ConstantColumn("1", (uint64_t)1, ConstantColumn::NUM)); // OFFSET (always one)
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.timeZone);
funcParms.push_back(srcp);
srcp.reset(new ConstantColumn("0", (uint64_t)0, ConstantColumn::NUM)); // FROM_LAST
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.timeZone);
funcParms.push_back(srcp);
srcp.reset(
new ConstantColumn("1", (uint64_t)1, ConstantColumn::NUM)); // IGNORE/RESPECT NULLS. 1 => RESPECT
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.timeZone);
funcParms.push_back(srcp);
break;
case Item_sum::NTH_VALUE_FUNC:
// When the front end supports these paramters, this needs modification
srcp.reset(new ConstantColumn("1", (uint64_t)1, ConstantColumn::NUM)); // FROM FIRST/LAST 1 => FIRST
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.timeZone);
funcParms.push_back(srcp);
srcp.reset(
new ConstantColumn("1", (uint64_t)1, ConstantColumn::NUM)); // IGNORE/RESPECT NULLS. 1 => RESPECT
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.timeZone);
funcParms.push_back(srcp);
break;
@ -453,11 +451,11 @@ ReturnedColumn* buildWindowFunctionColumn(Item* item, gp_walk_info& gwi, bool& n
case Item_sum::LAG_FUNC:
// When the front end supports these paramters, this needs modification
srcp.reset(new ConstantColumn("", ConstantColumn::NULLDATA)); // Default to fill in for NULL values
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.timeZone);
funcParms.push_back(srcp);
srcp.reset(
new ConstantColumn("1", (uint64_t)1, ConstantColumn::NUM)); // IGNORE/RESPECT NULLS. 1 => RESPECT
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.timeZone);
funcParms.push_back(srcp);
break;
@ -802,8 +800,7 @@ ReturnedColumn* buildWindowFunctionColumn(Item* item, gp_walk_info& gwi, bool& n
bound = 1;
srcp.reset(new ConstantColumn((int64_t)bound));
(dynamic_cast<ConstantColumn*>(srcp.get()))
->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.timeZone);
frm.fStart.fVal = srcp;
frm.fStart.fBound.reset(buildBoundExp(frm.fStart, srcp, gwi));
@ -819,8 +816,7 @@ ReturnedColumn* buildWindowFunctionColumn(Item* item, gp_walk_info& gwi, bool& n
bound = 1;
srcp.reset(new ConstantColumn((int64_t)bound));
(dynamic_cast<ConstantColumn*>(srcp.get()))
->timeZone(gwi.thd->variables.time_zone->get_name()->ptr());
(dynamic_cast<ConstantColumn*>(srcp.get()))->timeZone(gwi.timeZone);
frm.fEnd.fVal = srcp;
frm.fEnd.fBound.reset(buildBoundExp(frm.fEnd, srcp, gwi));