You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-29 08:21:15 +03:00
MCOL-4361 Replace pow(10.0, (double)scale) expressions with a static dictionary lookup.
This commit is contained in:
@ -1519,7 +1519,7 @@ double Func_cast_decimal::getDoubleVal(Row& row,
|
||||
return static_cast<double>(decimal);
|
||||
}
|
||||
|
||||
return (double) decimal.value / helpers::powerOf10_c[decimal.scale];
|
||||
return decimal.decimal64ToXFloat<double>();
|
||||
}
|
||||
|
||||
|
||||
@ -1631,7 +1631,7 @@ double Func_cast_double::getDoubleVal(Row& row,
|
||||
}
|
||||
else
|
||||
{
|
||||
dblval = (double)(decimal.value / pow((double)10, decimal.scale));
|
||||
dblval = decimal.decimal64ToXFloat<double>();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -248,7 +248,7 @@ mcsv1_UDAF::ReturnCode Moda_impl_T<T>::nextValue(mcsv1Context* context, ColumnDa
|
||||
|
||||
if (val != 0 && scale > 0)
|
||||
{
|
||||
val /= pow(10.0, (double)scale);
|
||||
val /= datatypes::scaleDivisor<double>(scale);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1458,12 +1458,8 @@ void RowAggregation::doSum(const Row& rowIn, int64_t colIn, int64_t colOut, int
|
||||
}
|
||||
else if (width <= datatypes::MAXLEGACYWIDTH)
|
||||
{
|
||||
valIn = rowIn.getIntField(colIn);
|
||||
double scale = (double)(fRowGroupIn.getScale())[colIn];
|
||||
if (valIn != 0 && scale > 0)
|
||||
{
|
||||
valIn /= pow(10.0, scale);
|
||||
}
|
||||
uint32_t scale = fRowGroupIn.getScale()[colIn];
|
||||
valIn = rowIn.getScaledSInt64FieldAsXFloat<long double>(colIn, scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1938,12 +1934,8 @@ void RowAggregation::doAvg(const Row& rowIn, int64_t colIn, int64_t colOut, int6
|
||||
}
|
||||
else if (width <= datatypes::MAXLEGACYWIDTH)
|
||||
{
|
||||
valIn = rowIn.getIntField(colIn);
|
||||
double scale = (double)(fRowGroupIn.getScale())[colIn];
|
||||
if (valIn != 0 && scale > 0)
|
||||
{
|
||||
valIn /= pow(10.0, scale);
|
||||
}
|
||||
uint32_t scale = fRowGroupIn.getScale()[colIn];
|
||||
valIn = rowIn.getScaledSInt64FieldAsXFloat<long double>(colIn, scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -3366,8 +3358,8 @@ void RowAggregationUM::calculateStatisticsFunctions()
|
||||
long double sum1 = fRow.getLongDoubleField(colAux);
|
||||
long double sum2 = fRow.getLongDoubleField(colAux + 1);
|
||||
|
||||
int scale = fRow.getScale(colOut);
|
||||
long double factor = pow(10.0, scale);
|
||||
uint32_t scale = fRow.getScale(colOut);
|
||||
auto factor = datatypes::scaleDivisor<long double>(scale);
|
||||
|
||||
if (scale != 0) // adjust the scale if necessary
|
||||
{
|
||||
@ -3732,7 +3724,8 @@ void RowAggregationUM::doNotNullConstantAggregate(const ConstantAggData& aggData
|
||||
else if (width <= datatypes::MAXLEGACYWIDTH)
|
||||
{
|
||||
double dbl = strtod(aggData.fConstValue.c_str(), 0);
|
||||
double scale = pow(10.0, (double) fRowGroupOut->getScale()[i]);
|
||||
auto scale = datatypes::scaleDivisor<double>(fRowGroupOut->getScale()[i]);
|
||||
// TODO: isn't overflow possible below:
|
||||
fRow.setIntField((int64_t)(scale * dbl), colOut);
|
||||
}
|
||||
else
|
||||
@ -3862,7 +3855,8 @@ void RowAggregationUM::doNotNullConstantAggregate(const ConstantAggData& aggData
|
||||
else if (width == datatypes::MAXLEGACYWIDTH)
|
||||
{
|
||||
double dbl = strtod(aggData.fConstValue.c_str(), 0);
|
||||
dbl *= pow(10.0, (double) fRowGroupOut->getScale()[i]);
|
||||
// TODO: isn't precision loss possible below?
|
||||
dbl *= datatypes::scaleDivisor<double>(fRowGroupOut->getScale()[i]);
|
||||
dbl *= rowCnt;
|
||||
|
||||
if ((dbl > 0 && dbl > (double) numeric_limits<int64_t>::max()) ||
|
||||
@ -4077,9 +4071,9 @@ void RowAggregationUM::doNotNullConstantAggregate(const ConstantAggData& aggData
|
||||
case execplan::CalpontSystemCatalog::UDECIMAL:
|
||||
{
|
||||
double dbl = strtod(aggData.fConstValue.c_str(), 0);
|
||||
double scale = pow(10.0, (double) fRowGroupOut->getScale()[i]);
|
||||
datum.columnData = (int64_t)(scale * dbl);
|
||||
datum.scale = scale;
|
||||
// TODO: isn't overflow possible below?
|
||||
datum.columnData = (int64_t) (dbl * datatypes::scaleDivisor<double>(fRowGroupOut->getScale()[i]));
|
||||
datum.scale = fRowGroupOut->getScale()[i];
|
||||
datum.precision = fRowGroupOut->getPrecision()[i];
|
||||
}
|
||||
break;
|
||||
@ -4454,12 +4448,8 @@ void RowAggregationUMP2::doAvg(const Row& rowIn, int64_t colIn, int64_t colOut,
|
||||
}
|
||||
else if (width <= datatypes::MAXLEGACYWIDTH)
|
||||
{
|
||||
valIn = rowIn.getIntField(colIn);
|
||||
double scale = (double)(fRowGroupIn.getScale())[colIn];
|
||||
if (valIn != 0 && scale > 0)
|
||||
{
|
||||
valIn /= pow(10.0, scale);
|
||||
}
|
||||
uint32_t scale = fRowGroupIn.getScale()[colIn];
|
||||
valIn = rowIn.getScaledSInt64FieldAsXFloat<long double>(colIn, scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -376,6 +376,38 @@ public:
|
||||
inline uint64_t getUintField(uint32_t colIndex) const;
|
||||
template<int len> inline int64_t getIntField(uint32_t colIndex) const;
|
||||
inline int64_t getIntField(uint32_t colIndex) const;
|
||||
// Get a signed 64-bit integer column value, convert to the given
|
||||
// floating point data type T (e.g. float, double, long double)
|
||||
// and divide it according to the scale.
|
||||
template<typename T>
|
||||
inline T getScaledSInt64FieldAsXFloat(uint32_t colIndex, uint32_t scale) const
|
||||
{
|
||||
const T d = getIntField(colIndex);
|
||||
if (!scale)
|
||||
return d;
|
||||
return d / datatypes::scaleDivisor<T>(scale);
|
||||
}
|
||||
template<typename T>
|
||||
inline T getScaledSInt64FieldAsXFloat(uint32_t colIndex) const
|
||||
{
|
||||
return getScaledSInt64FieldAsXFloat<T>(colIndex, getScale(colIndex));
|
||||
}
|
||||
// Get an unsigned 64-bit integer column value, convert to the given
|
||||
// floating point data type T (e.g. float, double, long double)
|
||||
// and divide it according to the scale.
|
||||
template<typename T>
|
||||
inline T getScaledUInt64FieldAsXFloat(uint32_t colIndex, uint32_t scale) const
|
||||
{
|
||||
const T d = getUintField(colIndex);
|
||||
if (!scale)
|
||||
return d;
|
||||
return d / datatypes::scaleDivisor<T>(scale);
|
||||
}
|
||||
template<typename T>
|
||||
inline T getScaledUInt64FieldAsXFloat(uint32_t colIndex) const
|
||||
{
|
||||
return getScaledUInt64FieldAsXFloat<T>(colIndex, getScale(colIndex));
|
||||
}
|
||||
template<typename T>
|
||||
inline bool equals(T* value, uint32_t colIndex) const;
|
||||
template<int len> inline bool equals(uint64_t val, uint32_t colIndex) const;
|
||||
|
@ -633,7 +633,7 @@ protected:
|
||||
{
|
||||
double val = convertAnyTo<double>(datum.columnData);
|
||||
if (val != 0 && datum.scale > 0)
|
||||
val /= pow(10.0, (double) datum.scale);
|
||||
val /= datatypes::scaleDivisor<double>(datum.scale);
|
||||
return val;
|
||||
}
|
||||
|
||||
|
@ -181,16 +181,16 @@ double MCS_add::getDoubleVal(Row& row,
|
||||
else if (op1.scale >= op2.scale)
|
||||
{
|
||||
dec.scale = op2.scale;
|
||||
op1.value *= (int64_t)pow((double)10, op1.scale - op2.scale);
|
||||
op1.value *= datatypes::scaleDivisor<int64_t>((uint32_t) (op1.scale - op2.scale));
|
||||
}
|
||||
else
|
||||
{
|
||||
dec.scale = op1.scale;
|
||||
op2.value *= (int64_t)pow((double)10, op2.scale - op1.scale);
|
||||
op2.value *= datatypes::scaleDivisor<int64_t>((uint32_t) (op2.scale - op1.scale));
|
||||
}
|
||||
|
||||
dec.value = op1.value + op2.value;
|
||||
return (double)(dec.value / pow((double)10, dec.scale));
|
||||
return dec.decimal64ToXFloat<double>();
|
||||
}
|
||||
|
||||
default:
|
||||
|
@ -191,8 +191,8 @@ void WF_stats<T>::operator()(int64_t b, int64_t e, int64_t c)
|
||||
|
||||
if (fCount > 1)
|
||||
{
|
||||
int scale = fRow.getScale(colIn);
|
||||
long double factor = pow(10.0, scale);
|
||||
uint32_t scale = fRow.getScale(colIn);
|
||||
auto factor = datatypes::scaleDivisor<long double>(scale);
|
||||
long double ldSum1 = fSum1;
|
||||
long double ldSum2 = fSum2;
|
||||
|
||||
|
Reference in New Issue
Block a user