From d2432f9bf6d7c05db3bdb550c4224fa94f4aa9cf Mon Sep 17 00:00:00 2001 From: Leonid Fedorov Date: Fri, 26 Aug 2022 15:12:22 +0000 Subject: [PATCH] get rid of pointers for 128 fields --- datatypes/mcs_datatype.cpp | 3 +- datatypes/mcs_int128.h | 5 -- dbcon/execplan/returnedcolumn.cpp | 6 -- dbcon/execplan/returnedcolumn.h | 1 - dbcon/execplan/simplecolumn.cpp | 9 +-- utils/rowgroup/rowaggregation.cpp | 63 +++++++++------------ utils/rowgroup/rowaggregation.h | 2 +- utils/rowgroup/rowgroup.cpp | 4 +- utils/rowgroup/rowgroup.h | 17 +----- utils/windowfunction/windowfunctiontype.cpp | 2 +- writeengine/server/we_dmlcommandproc.cpp | 10 ++-- 11 files changed, 40 insertions(+), 82 deletions(-) diff --git a/datatypes/mcs_datatype.cpp b/datatypes/mcs_datatype.cpp index b06c5f1aa..5eef21c7f 100644 --- a/datatypes/mcs_datatype.cpp +++ b/datatypes/mcs_datatype.cpp @@ -552,8 +552,7 @@ int TypeHandlerXDecimal::storeValueToField64(rowgroup::Row& row, int pos, StoreF int TypeHandlerXDecimal::storeValueToField128(rowgroup::Row& row, int pos, StoreField* f) const { - int128_t* decPtr = row.getTSInt128Field(pos).getValPtr(); - return f->store_decimal128(datatypes::Decimal(0, f->scale(), f->precision(), decPtr)); + return f->store_decimal128(datatypes::Decimal(row.getTSInt128Field(pos), f->scale(), f->precision())); } int TypeHandlerStr::storeValueToFieldBlobText(rowgroup::Row& row, int pos, StoreField* f) const diff --git a/datatypes/mcs_int128.h b/datatypes/mcs_int128.h index 2ef199f35..1dd5d1e35 100644 --- a/datatypes/mcs_int128.h +++ b/datatypes/mcs_int128.h @@ -306,11 +306,6 @@ class TSInt128 return s128Value; } - inline int128_t* getValPtr() - { - return &s128Value; - } - // print int128_t parts represented as PODs uint8_t printPodParts(char* buf, const int128_t& high, const int128_t& mid, const int128_t& low) const; diff --git a/dbcon/execplan/returnedcolumn.cpp b/dbcon/execplan/returnedcolumn.cpp index fffc5a26b..0373c881d 100644 --- a/dbcon/execplan/returnedcolumn.cpp +++ b/dbcon/execplan/returnedcolumn.cpp @@ -50,7 +50,6 @@ ReturnedColumn::ReturnedColumn() , fColPosition(-1) , fHasAggregate(false) , fInputIndex(-1) - , fInputOffset(-1) , fOutputIndex(-1) , fExpressionId((uint32_t)-1) { @@ -71,7 +70,6 @@ ReturnedColumn::ReturnedColumn(const string& sql) , fHasAggregate(false) , fData(sql) , fInputIndex(-1) - , fInputOffset(-1) , fOutputIndex(-1) , fExpressionId((uint32_t)-1) { @@ -91,7 +89,6 @@ ReturnedColumn::ReturnedColumn(const uint32_t sessionID, const bool returnAll) , fColPosition(-1) , fHasAggregate(false) , fInputIndex(-1) - , fInputOffset(-1) , fOutputIndex(-1) , fExpressionId((uint32_t)-1) { @@ -113,7 +110,6 @@ ReturnedColumn::ReturnedColumn(const ReturnedColumn& rhs, const uint32_t session , fHasAggregate(rhs.fHasAggregate) , fData(rhs.fData) , fInputIndex(rhs.fInputIndex) - , fInputOffset(rhs.fInputOffset) , fOutputIndex(rhs.fOutputIndex) , fExpressionId(rhs.fExpressionId) { @@ -146,7 +142,6 @@ void ReturnedColumn::serialize(messageqcpp::ByteStream& b) const b << (uint64_t)fColSource; b << (int64_t)fColPosition; b << (uint32_t)fInputIndex; - b << (uint32_t)fInputOffset; b << (uint32_t)fOutputIndex; b << (int32_t)fSequence; b << (uint8_t)fReturnAll; @@ -169,7 +164,6 @@ void ReturnedColumn::unserialize(messageqcpp::ByteStream& b) b >> (uint64_t&)fColSource; b >> (int64_t&)fColPosition; b >> (uint32_t&)fInputIndex; - b >> (uint32_t&)fInputOffset; b >> (uint32_t&)fOutputIndex; b >> (int32_t&)fSequence; b >> (uint8_t&)fReturnAll; diff --git a/dbcon/execplan/returnedcolumn.h b/dbcon/execplan/returnedcolumn.h index 1f00aec05..f79caf580 100644 --- a/dbcon/execplan/returnedcolumn.h +++ b/dbcon/execplan/returnedcolumn.h @@ -372,7 +372,6 @@ class ReturnedColumn : public TreeNode protected: std::string fErrMsg; /// error occured in evaluation uint32_t fInputIndex; /// index to the input rowgroup - uint32_t fInputOffset; /// index to the input rowgroup uint32_t fOutputIndex; /// index to the output rowgroup uint32_t fExpressionId; /// unique id for this expression }; diff --git a/dbcon/execplan/simplecolumn.cpp b/dbcon/execplan/simplecolumn.cpp index 2e3226f5f..3cf5186b1 100644 --- a/dbcon/execplan/simplecolumn.cpp +++ b/dbcon/execplan/simplecolumn.cpp @@ -489,12 +489,6 @@ bool SimpleColumn::singleTable(CalpontSystemCatalog::TableAliasName& tan) // @todo move to inline void SimpleColumn::evaluate(Row& row, bool& isNull) { - // TODO Move this block into an appropriate place - if (UNLIKELY((int)(fInputOffset == (uint32_t)-1))) - { - fInputOffset = row.getOffset(fInputIndex); - } - bool isNull2 = row.isNullValue(fInputIndex); if (isNull2) @@ -632,8 +626,7 @@ void SimpleColumn::evaluate(Row& row, bool& isNull) { case 16: { - datatypes::TSInt128::assignPtrPtr(&fResult.decimalVal.s128Value, - row.getBinaryField_offset(fInputOffset)); + fResult.decimalVal.s128Value = row.getTSInt128Field(fInputIndex).getValue(); break; } case 1: diff --git a/utils/rowgroup/rowaggregation.cpp b/utils/rowgroup/rowaggregation.cpp index 092d10e08..1fc1cdd74 100644 --- a/utils/rowgroup/rowaggregation.cpp +++ b/utils/rowgroup/rowaggregation.cpp @@ -32,6 +32,7 @@ #include #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(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(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(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(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(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(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(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); } } diff --git a/utils/rowgroup/rowaggregation.h b/utils/rowgroup/rowaggregation.h index a5abc4b40..18cb9e748 100644 --- a/utils/rowgroup/rowaggregation.h +++ b/utils/rowgroup/rowaggregation.h @@ -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); diff --git a/utils/rowgroup/rowgroup.cpp b/utils/rowgroup/rowgroup.cpp index 195199b02..95861a48b 100644 --- a/utils/rowgroup/rowgroup.cpp +++ b/utils/rowgroup/rowgroup.cpp @@ -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 diff --git a/utils/rowgroup/rowgroup.h b/utils/rowgroup/rowgroup.h index eee661e43..8f80dc422 100644 --- a/utils/rowgroup/rowgroup.h +++ b/utils/rowgroup/rowgroup.h @@ -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 - inline T* getBinaryField_offset(uint32_t offset) const; - inline boost::shared_ptr getUserData(uint32_t colIndex) const; inline void setUserData(mcsv1sdk::mcsv1Context& context, boost::shared_ptr userData, uint32_t len, uint32_t colIndex); @@ -1014,13 +1008,6 @@ inline void Row::setStringField(const utils::ConstString& str, uint32_t colIndex } } - -template -inline T* Row::getBinaryField_offset(uint32_t offset) const -{ - return reinterpret_cast(&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) diff --git a/utils/windowfunction/windowfunctiontype.cpp b/utils/windowfunction/windowfunctiontype.cpp index 194aa81a4..eb8b6331d 100644 --- a/utils/windowfunction/windowfunctiontype.cpp +++ b/utils/windowfunction/windowfunctiontype.cpp @@ -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; } diff --git a/writeengine/server/we_dmlcommandproc.cpp b/writeengine/server/we_dmlcommandproc.cpp index 0383826ce..540ad28b4 100644 --- a/writeengine/server/we_dmlcommandproc.cpp +++ b/writeengine/server/we_dmlcommandproc.cpp @@ -3111,9 +3111,8 @@ uint8_t WE_DMLCommandProc::processUpdate(messageqcpp::ByteStream& bs, std::strin { if (fetchColColwidths[fetchColPos] == datatypes::MAXDECIMALWIDTH) { - datatypes::Decimal dec(0, fetchColScales[fetchColPos], - rowGroups[txnId]->getPrecision()[fetchColPos], - row.getTSInt128Field(fetchColPos).getValPtr()); + datatypes::Decimal dec(row.getTSInt128Field(fetchColPos), fetchColScales[fetchColPos], + rowGroups[txnId]->getPrecision()[fetchColPos]); value = dec.toString(true); break; } @@ -3466,9 +3465,8 @@ uint8_t WE_DMLCommandProc::processUpdate(messageqcpp::ByteStream& bs, std::strin { if (fetchColColwidths[fetchColPos] == datatypes::MAXDECIMALWIDTH) { - datatypes::Decimal dec(0, fetchColScales[fetchColPos], - rowGroups[txnId]->getPrecision()[fetchColPos], - row.getTSInt128Field(fetchColPos).getValPtr()); + datatypes::Decimal dec(row.getTSInt128Field(fetchColPos), fetchColScales[fetchColPos], + rowGroups[txnId]->getPrecision()[fetchColPos]); value = dec.toString(true); break; }