1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-30 19:23:07 +03:00

get rid of pointers for 128 fields

This commit is contained in:
Leonid Fedorov
2022-08-26 15:12:22 +00:00
parent 0863ecd279
commit d2432f9bf6
11 changed files with 40 additions and 82 deletions

View File

@ -32,6 +32,7 @@
#include <cassert>
#include "joblisttypes.h"
#include "mcs_basic_types.h"
#include "resourcemanager.h"
#include "groupconcat.h"
@ -74,9 +75,9 @@ inline bool minMax(T d1, T d2, int type)
return d1 > d2;
}
inline bool minMax(int128_t* d1, int128_t* d2, int type)
inline bool minMax(int128_t d1, int128_t d2, int type)
{
return (type == rowgroup::ROWAGG_MIN) ? *d1 < *d2 : *d1 > *d2;
return (type == rowgroup::ROWAGG_MIN) ? d1 < d2 : d1 > d2;
}
inline int64_t getIntNullValue(int colType)
@ -247,13 +248,12 @@ const static_any::any& RowAggregation::strTypeId(typeStr);
static const string overflowMsg("Aggregation overflow.");
inline void RowAggregation::updateIntMinMax(int128_t* val1, int128_t* val2, int64_t col, int func)
inline void RowAggregation::updateIntMinMax(int128_t val1, int128_t val2, int64_t col, int func)
{
int32_t colOutOffset = fRow.getOffset(col);
if (isNull(fRowGroupOut, fRow, col))
fRow.setBinaryField_offset(val1, sizeof(int128_t), colOutOffset);
fRow.setInt128Field(val1, col);
else if (minMax(val1, val2, func))
fRow.setBinaryField_offset(val1, sizeof(int128_t), colOutOffset);
fRow.setInt128Field(val1, col);
}
inline void RowAggregation::updateIntMinMax(int64_t val1, int64_t val2, int64_t col, int func)
@ -867,8 +867,8 @@ void RowAggregation::initMapData(const Row& rowIn)
{
if (LIKELY(rowIn.getColumnWidth(colIn) == datatypes::MAXDECIMALWIDTH))
{
uint32_t colOutOffset = fRow.getOffset(colOut);
fRow.setBinaryField_offset(rowIn.getTSInt128Field(colIn).getValPtr(), sizeof(int128_t), colOutOffset);
int128_t value = rowIn.getTSInt128Field(colIn).getValue();
fRow.setInt128Field(value, colOut);
}
else if (rowIn.getColumnWidth(colIn) <= datatypes::MAXLEGACYWIDTH)
{
@ -1128,7 +1128,7 @@ void RowAggregation::doMinMax(const Row& rowIn, int64_t colIn, int64_t colOut, i
{
if (LIKELY(rowIn.getColumnWidth(colIn) == datatypes::MAXDECIMALWIDTH))
{
updateIntMinMax(rowIn.getTSInt128Field(colIn).getValPtr(), fRow.getTSInt128Field(colOut).getValPtr(), colOut,
updateIntMinMax(rowIn.getTSInt128Field(colIn).getValue(), fRow.getTSInt128Field(colOut).getValue(), colOut,
funcType);
}
else if (rowIn.getColumnWidth(colIn) <= datatypes::MAXLEGACYWIDTH)
@ -1226,7 +1226,7 @@ void RowAggregation::doSum(const Row& rowIn, int64_t colIn, int64_t colOut, int
datatypes::SystemCatalog::ColDataType colDataType = rowIn.getColType(colIn);
long double valIn = 0;
bool isWideDataType = false;
void* wideValInPtr = nullptr;
int128_t wideValue = 0;
if (rowIn.isNullValue(colIn))
return;
@ -1260,8 +1260,7 @@ void RowAggregation::doSum(const Row& rowIn, int64_t colIn, int64_t colOut, int
isWideDataType = width == datatypes::MAXDECIMALWIDTH;
if (LIKELY(isWideDataType))
{
int128_t* dec = rowIn.getTSInt128Field(colIn).getValPtr();
wideValInPtr = reinterpret_cast<void*>(dec);
wideValue = rowIn.getTSInt128Field(colIn).getValue();
}
else if (width <= datatypes::MAXLEGACYWIDTH)
{
@ -1341,16 +1340,15 @@ void RowAggregation::doSum(const Row& rowIn, int64_t colIn, int64_t colOut, int
}
else if (isWideDataType)
{
int128_t* dec = reinterpret_cast<int128_t*>(wideValInPtr);
if (LIKELY(!isNull(fRowGroupOut, fRow, colOut)))
{
int128_t valOut = fRow.getTSInt128Field(colOut).getValue();
int128_t sum = valOut + *dec;
fRow.setBinaryField(&sum, colOut);
int128_t sum = valOut + wideValue;
fRow.setInt128Field(sum, colOut);
}
else
{
fRow.setBinaryField(dec, colOut);
fRow.setInt128Field(wideValue, colOut);
}
}
else
@ -1762,7 +1760,7 @@ void RowAggregation::doAvg(const Row& rowIn, int64_t colIn, int64_t colOut, int6
datatypes::SystemCatalog::ColDataType colDataType = rowIn.getColType(colIn);
long double valIn = 0;
bool isWideDataType = false;
void* wideValInPtr = nullptr;
int128_t wideValue = 0;
switch (colDataType)
{
@ -1793,8 +1791,7 @@ void RowAggregation::doAvg(const Row& rowIn, int64_t colIn, int64_t colOut, int6
isWideDataType = width == datatypes::MAXDECIMALWIDTH;
if (LIKELY(isWideDataType))
{
int128_t* dec = rowIn.getTSInt128Field(colIn).getValPtr();
wideValInPtr = reinterpret_cast<void*>(dec);
wideValue = rowIn.getTSInt128Field(colIn).getValue();
}
else if (width <= datatypes::MAXLEGACYWIDTH)
{
@ -1871,16 +1868,15 @@ void RowAggregation::doAvg(const Row& rowIn, int64_t colIn, int64_t colOut, int6
}
else if (isWideDataType)
{
int128_t* dec = reinterpret_cast<int128_t*>(wideValInPtr);
if (LIKELY(notFirstValue))
{
int128_t valOut = fRow.getTSInt128Field(colOut).getValue();
int128_t sum = valOut + *dec;
fRow.setBinaryField(&sum, colOut);
int128_t sum = valOut + wideValue;
fRow.setInt128Field(sum, colOut);
}
else
{
fRow.setBinaryField(dec, colOut);
fRow.setInt128Field(wideValue, colOut);
}
}
else
@ -2618,21 +2614,20 @@ void RowAggregationUM::calculateAvgColumns()
}
else
{
uint32_t offset = fRow.getOffset(colOut);
uint32_t scale = fRow.getScale(colOut);
// Get multiplied to deliver AVG with the scale closest
// to the expected original scale + 4.
// There is a counterpart in buildAggregateColumn.
datatypes::Decimal::setScalePrecision4Avg(precision, scale);
int128_t* sumPnt = fRow.getBinaryField_offset<int128_t>(offset);
int128_t sumPnt = fRow.getTSInt128Field(colOut).getValue();
uint32_t scaleDiff = scale - fRow.getScale(colOut);
// multiplication overflow check
datatypes::MultiplicationOverflowCheck multOp;
int128_t sum = 0;
if (scaleDiff > 0)
multOp(*sumPnt, datatypes::mcs_pow_10[scaleDiff], sum);
multOp(sumPnt, datatypes::mcs_pow_10[scaleDiff], sum);
else
sum = *sumPnt;
sum = sumPnt;
datatypes::lldiv_t_128 avgAndRem = datatypes::lldiv128(sum, cnt);
// Round the last digit
if (datatypes::abs(avgAndRem.rem) * 2 >= (int128_t)cnt)
@ -2646,7 +2641,7 @@ void RowAggregationUM::calculateAvgColumns()
avgAndRem.quot++;
}
}
fRow.setBinaryField_offset(&avgAndRem.quot, sizeof(avgAndRem.quot), offset);
fRow.setInt128Field(avgAndRem.quot, colOut);
}
}
}
@ -4151,7 +4146,7 @@ void RowAggregationUMP2::doAvg(const Row& rowIn, int64_t colIn, int64_t colOut,
datatypes::SystemCatalog::ColDataType colDataType = rowIn.getColType(colIn);
long double valIn = 0;
bool isWideDataType = false;
void* wideValInPtr = nullptr;
int128_t wideValue = 0;
switch (colDataType)
{
@ -4182,8 +4177,7 @@ void RowAggregationUMP2::doAvg(const Row& rowIn, int64_t colIn, int64_t colOut,
isWideDataType = width == datatypes::MAXDECIMALWIDTH;
if (LIKELY(isWideDataType))
{
int128_t* dec = rowIn.getTSInt128Field(colIn).getValPtr();
wideValInPtr = reinterpret_cast<void*>(dec);
wideValue = rowIn.getTSInt128Field(colIn).getValue();
}
else if (width <= datatypes::MAXLEGACYWIDTH)
{
@ -4250,17 +4244,16 @@ void RowAggregationUMP2::doAvg(const Row& rowIn, int64_t colIn, int64_t colOut,
}
else if (isWideDataType)
{
int128_t* dec = reinterpret_cast<int128_t*>(wideValInPtr);
if (LIKELY(cnt > 0))
{
int128_t valOut = fRow.getTSInt128Field(colOut).getValue();;
int128_t sum = valOut + *dec;
fRow.setBinaryField(&sum, colOut);
int128_t sum = valOut + wideValue;
fRow.setInt128Field(sum, colOut);
fRow.setUintField(rowIn.getUintField(colAuxIn) + cnt, colAux);
}
else
{
fRow.setBinaryField(dec, colOut);
fRow.setInt128Field(wideValue, colOut);
fRow.setUintField(rowIn.getUintField(colAuxIn), colAux);
}
}

View File

@ -559,7 +559,7 @@ class RowAggregation : public messageqcpp::Serializeable
copyRow(fNullRow, &row);
}
inline void updateIntMinMax(int128_t* val1, int128_t* val2, int64_t col, int func);
inline void updateIntMinMax(int128_t val1, int128_t val2, int64_t col, int func);
inline void updateIntMinMax(int64_t val1, int64_t val2, int64_t col, int func);
inline void updateUintMinMax(uint64_t val1, uint64_t val2, int64_t col, int func);
inline void updateCharMinMax(uint64_t val1, uint64_t val2, int64_t col, int func);

View File

@ -589,7 +589,7 @@ string Row::toString(uint32_t rownum) const
case CalpontSystemCatalog::UDECIMAL:
if (colWidths[i] == datatypes::MAXDECIMALWIDTH)
{
datatypes::Decimal dec(0, scale[i], precision[i], getTSInt128Field(i).getValPtr());
datatypes::Decimal dec(getTSInt128Field(i), scale[i], precision[i]);
os << dec << " ";
break;
}
@ -1456,7 +1456,7 @@ void applyMapping(const int* mapping, const Row& in, Row* out)
// Migrate to offset based methods here
// code precision 2 width convertor
else if (UNLIKELY(datatypes::isWideDecimalType(in.getColTypes()[i], in.getColumnWidth(i))))
out->setBinaryField_offset(in.getTSInt128Field(i).getValPtr(), 16, out->getOffset(mapping[i]));
out->setInt128Field(in.getTSInt128Field(i).getValue(), mapping[i]);
else if (in.isUnsigned(i))
out->setUintField(in.getUintField(i), mapping[i]);
else

View File

@ -442,8 +442,7 @@ class Row
inline datatypes::Decimal getDecimalField(uint32_t colIndex) const
{
if (LIKELY(getColumnWidth(colIndex) == datatypes::MAXDECIMALWIDTH))
return datatypes::Decimal(0, (int)getScale(colIndex), getPrecision(colIndex),
getTSInt128Field(colIndex).getValPtr());
return datatypes::Decimal(getTSInt128Field(colIndex), (int)getScale(colIndex), getPrecision(colIndex));
return datatypes::Decimal(datatypes::TSInt64(getIntField(colIndex)), (int)getScale(colIndex),
getPrecision(colIndex));
}
@ -515,11 +514,6 @@ class Row
inline const uint8_t* getVarBinaryField(uint32_t colIndex) const;
inline const uint8_t* getVarBinaryField(uint32_t& len, uint32_t colIndex) const;
inline void setVarBinaryField(const uint8_t* val, uint32_t len, uint32_t colIndex);
template <typename T>
inline T* getBinaryField_offset(uint32_t offset) const;
inline boost::shared_ptr<mcsv1sdk::UserData> getUserData(uint32_t colIndex) const;
inline void setUserData(mcsv1sdk::mcsv1Context& context, boost::shared_ptr<mcsv1sdk::UserData> userData,
uint32_t len, uint32_t colIndex);
@ -1014,13 +1008,6 @@ inline void Row::setStringField(const utils::ConstString& str, uint32_t colIndex
}
}
template <typename T>
inline T* Row::getBinaryField_offset(uint32_t offset) const
{
return reinterpret_cast<T*>(&data[offset]);
}
inline std::string Row::getVarBinaryStringField(uint32_t colIndex) const
{
if (inStringTable(colIndex))
@ -1346,7 +1333,7 @@ inline void Row::copyField(Row& out, uint32_t destIndex, uint32_t srcIndex) cons
inline void Row::copyBinaryField(Row& out, uint32_t destIndex, uint32_t srcIndex) const
{
out.setBinaryField(getTSInt128Field(srcIndex).getValPtr(), destIndex);
out.setInt128Field(getTSInt128Field(srcIndex).getValue(), destIndex);
}
inline void Row::setRid(uint64_t rid)

View File

@ -526,7 +526,7 @@ void WindowFunctionType::implicit2T(uint64_t i, T& t, int s)
}
else if (width == datatypes::MAXDECIMALWIDTH)
{
datatypes::TSInt128::assignPtrPtr(&t, fRow.getTSInt128Field(i).getValPtr());
t = fRow.getTSInt128Field(i).getValue();
}
break;
}