1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-29 08:21:15 +03:00

MCOL-4180 dbcon/execplan review

This commit is contained in:
Roman Nozdrin
2020-12-25 15:35:11 +00:00
parent 399e13780a
commit 5c3b22ddf7
7 changed files with 47 additions and 50 deletions

View File

@ -584,6 +584,28 @@ class Decimal: public TSInt128
return !this->operator==(rhs); return !this->operator==(rhs);
} }
Decimal integralWideRound(const int128_t& scaleDivisor = 0) const
{
int128_t scaleDivisorInt = scaleDivisor;
if(UNLIKELY(!scaleDivisorInt))
{
datatypes::getScaleDivisor(scaleDivisorInt, scale);
}
lldiv_t div = lldiv(s128Value, scaleDivisorInt);
if (datatypes::abs(div.rem) * 2 >= scaleDivisorInt)
{
return Decimal(value,
scale,
precision,
(div.quot < 0) ? div.quot-- : div.quot++);
}
return Decimal(value,
scale,
precision,
div.quot);
}
inline bool isTSInt128ByPrecision() const inline bool isTSInt128ByPrecision() const
{ {
return precision > INT64MAXPRECISION return precision > INT64MAXPRECISION

View File

@ -112,7 +112,7 @@ struct is_uint128_t<uint128_t> {
static const bool value = true; static const bool value = true;
}; };
inline int128_t abs(int128_t& x) inline int128_t abs(int128_t x)
{ {
return (x >= 0) ? x : -x; return (x >= 0) ? x : -x;
} }

View File

@ -328,7 +328,7 @@ void ConstantColumn::serialize(messageqcpp::ByteStream& b) const
b << (uint8_t)fResult.boolVal; b << (uint8_t)fResult.boolVal;
b << fResult.strVal; b << fResult.strVal;
b << (uint64_t)fResult.decimalVal.value; b << (uint64_t)fResult.decimalVal.value;
b << (uint128_t)fResult.decimalVal.s128Value; b << fResult.decimalVal.s128Value;
b << (uint8_t)fResult.decimalVal.scale; b << (uint8_t)fResult.decimalVal.scale;
b << (uint8_t)fResult.decimalVal.precision; b << (uint8_t)fResult.decimalVal.precision;
} }
@ -353,7 +353,7 @@ void ConstantColumn::unserialize(messageqcpp::ByteStream& b)
b >> (uint8_t&)fResult.boolVal; b >> (uint8_t&)fResult.boolVal;
b >> fResult.strVal; b >> fResult.strVal;
b >> (uint64_t&)fResult.decimalVal.value; b >> (uint64_t&)fResult.decimalVal.value;
b >> (uint128_t&)fResult.decimalVal.s128Value; b >> fResult.decimalVal.s128Value;
b >> (uint8_t&)fResult.decimalVal.scale; b >> (uint8_t&)fResult.decimalVal.scale;
b >> (uint8_t&)fResult.decimalVal.precision; b >> (uint8_t&)fResult.decimalVal.precision;
} }

View File

@ -270,9 +270,7 @@ public:
} }
else else
{ {
decimal.s128Value = (int128_t)(decimal.s128Value > 0 ? decimal = decimal.integralWideRound();
(__float128)decimal.s128Value / scaleMultiplier + 0.5 :
(__float128)decimal.s128Value / scaleMultiplier - 0.5);
} }
} }
} }

View File

@ -125,8 +125,6 @@ bool PredicateOperator::operator!=(const TreeNode* t) const
return (!(*this == t)); return (!(*this == t));
} }
//FIXME: VARBINARY???
//FIXME: BINARY???
void PredicateOperator::setOpType(Type& l, Type& r) void PredicateOperator::setOpType(Type& l, Type& r)
{ {
fOperationType = l; // Default to left side. Modify as needed. fOperationType = l; // Default to left side. Modify as needed.
@ -763,7 +761,6 @@ bool PredicateOperator::getBoolVal(rowgroup::Row& row, bool& isNull, ReturnedCol
return strTrimCompare(val1, rop->getStrVal(row, isNull)) && !isNull; return strTrimCompare(val1, rop->getStrVal(row, isNull)) && !isNull;
} }
//FIXME: ???
case execplan::CalpontSystemCatalog::VARBINARY: case execplan::CalpontSystemCatalog::VARBINARY:
case execplan::CalpontSystemCatalog::BLOB: case execplan::CalpontSystemCatalog::BLOB:
return false; return false;

View File

@ -1038,56 +1038,30 @@ inline IDB_Decimal TreeNode::getDecimalVal()
throw logging::InvalidConversionExcept("TreeNode::getDecimalVal: non-support conversion from binary string"); throw logging::InvalidConversionExcept("TreeNode::getDecimalVal: non-support conversion from binary string");
case CalpontSystemCatalog::BIGINT: case CalpontSystemCatalog::BIGINT:
{
idbassert(fResultType.scale == 0);
if (fResultType.isWideDecimalPrecision())
fResult.decimalVal = IDB_Decimal(0, 0, fResultType.precision,
(int128_t)fResult.intVal);
else
fResult.decimalVal = IDB_Decimal(fResult.intVal, 0,
fResultType.precision);
break;
}
case CalpontSystemCatalog::MEDINT: case CalpontSystemCatalog::MEDINT:
case CalpontSystemCatalog::INT: case CalpontSystemCatalog::INT:
case CalpontSystemCatalog::SMALLINT: case CalpontSystemCatalog::SMALLINT:
case CalpontSystemCatalog::TINYINT: case CalpontSystemCatalog::TINYINT:
{ {
idbassert(fResultType.scale == 0); idbassert(fResultType.scale == 0);
fResult.decimalVal = IDB_Decimal(fResult.intVal,
fResult.decimalVal = IDB_Decimal(fResult.intVal, 0, 0,
fResultType.precision); fResultType.precision,
fResult.intVal);
break; break;
} }
case CalpontSystemCatalog::UBIGINT: case CalpontSystemCatalog::UBIGINT:
{
idbassert(fResultType.scale == 0);
if (fResultType.isWideDecimalPrecision())
fResult.decimalVal = IDB_Decimal(0, 0, fResultType.precision,
(int128_t)fResult.uintVal);
else
fResult.decimalVal = IDB_Decimal((int64_t)fResult.uintVal, 0,
fResultType.precision);
break;
}
case CalpontSystemCatalog::UMEDINT: case CalpontSystemCatalog::UMEDINT:
case CalpontSystemCatalog::UINT: case CalpontSystemCatalog::UINT:
case CalpontSystemCatalog::USMALLINT: case CalpontSystemCatalog::USMALLINT:
case CalpontSystemCatalog::UTINYINT: case CalpontSystemCatalog::UTINYINT:
{ {
idbassert(fResultType.scale == 0); idbassert(fResultType.scale == 0);
fResult.decimalVal = IDB_Decimal((int64_t)fResult.uintVal,
fResult.decimalVal = IDB_Decimal((int64_t)fResult.uintVal, 0, 0,
fResultType.precision); fResultType.precision,
fResult.uintVal);
break; break;
} }
@ -1108,8 +1082,11 @@ inline IDB_Decimal TreeNode::getDecimalVal()
} }
else else
{ {
fResult.decimalVal = IDB_Decimal((int64_t)lroundl(dlScaled), int64_t val = (int64_t)lroundl(dlScaled);
fResultType.scale, fResultType.precision); fResult.decimalVal = IDB_Decimal(val,
fResultType.scale,
fResultType.precision,
val);
} }
break; break;

View File

@ -393,7 +393,7 @@ void WindowFunctionColumn::adjustResultType()
if (fFunctionParms[0]->resultType().colDataType == CalpontSystemCatalog::DECIMAL || if (fFunctionParms[0]->resultType().colDataType == CalpontSystemCatalog::DECIMAL ||
fFunctionParms[0]->resultType().colDataType == CalpontSystemCatalog::UDECIMAL) fFunctionParms[0]->resultType().colDataType == CalpontSystemCatalog::UDECIMAL)
{ {
fResultType.colWidth = sizeof(int128_t); fResultType.colWidth = datatypes::MAXDECIMALWIDTH;
} }
else else
{ {
@ -696,14 +696,17 @@ void WindowFunctionColumn::evaluate(Row& row, bool& isNull)
case 16: case 16:
{ {
int128_t val; datatypes::TSInt128 val = row.getTSInt128Field(fInputIndex);
row.getInt128Field(fInputIndex, val);
if (val == datatypes::Decimal128Null) if (val.isNull())
{
isNull = true; isNull = true;
}
else else
{ {
fResult.decimalVal = IDB_Decimal(0, fResultType.scale, fResultType.precision, val); fResult.decimalVal = IDB_Decimal(val,
fResultType.scale,
fResultType.precision);
} }
break; break;