From 0863ecd279f8518af2964d268697b678c82bf500 Mon Sep 17 00:00:00 2001 From: mariadb-AndreyPiskunov Date: Thu, 25 Aug 2022 18:21:43 +0300 Subject: [PATCH] Replace getBinaryField --- datatypes/mcs_datatype.cpp | 2 +- datatypes/mcs_int128.h | 5 +++ dbcon/joblist/groupconcat.cpp | 2 +- tests/rowgroup-tests.cpp | 4 +-- utils/rowgroup/rowaggregation.cpp | 36 ++++++++++----------- utils/rowgroup/rowgroup.cpp | 6 ++-- utils/rowgroup/rowgroup.h | 32 +++++------------- utils/windowfunction/windowfunctiontype.cpp | 2 +- writeengine/server/we_dmlcommandproc.cpp | 8 ++--- 9 files changed, 43 insertions(+), 54 deletions(-) diff --git a/datatypes/mcs_datatype.cpp b/datatypes/mcs_datatype.cpp index 9dfe800f5..b06c5f1aa 100644 --- a/datatypes/mcs_datatype.cpp +++ b/datatypes/mcs_datatype.cpp @@ -552,7 +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.getBinaryField(pos); + int128_t* decPtr = row.getTSInt128Field(pos).getValPtr(); return f->store_decimal128(datatypes::Decimal(0, f->scale(), f->precision(), decPtr)); } diff --git a/datatypes/mcs_int128.h b/datatypes/mcs_int128.h index 1dd5d1e35..2ef199f35 100644 --- a/datatypes/mcs_int128.h +++ b/datatypes/mcs_int128.h @@ -306,6 +306,11 @@ 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/joblist/groupconcat.cpp b/dbcon/joblist/groupconcat.cpp index e44026468..b693a2eab 100644 --- a/dbcon/joblist/groupconcat.cpp +++ b/dbcon/joblist/groupconcat.cpp @@ -368,7 +368,7 @@ void GroupConcatAgUM::applyMapping(const boost::shared_array& mapping, cons } else if (datatypes::isWideDecimalType(fRow.getColType(i), fRow.getColumnWidth(i))) { - row.copyBinaryField(fRow, i, mapping[i]); + row.copyBinaryField(fRow, i, mapping[i]); } } else diff --git a/tests/rowgroup-tests.cpp b/tests/rowgroup-tests.cpp index 5073702ae..0c2a2e789 100644 --- a/tests/rowgroup-tests.cpp +++ b/tests/rowgroup-tests.cpp @@ -285,8 +285,8 @@ TEST_F(RowDecimalTest, CopyBinaryFieldCheck) col2Out = rOut.getTSInt128Field(1); EXPECT_NE(col1In, col1Out); EXPECT_NE(col2In, col2Out); - r.copyBinaryField(rOut, 0, 0); - r.copyBinaryField(rOut, 1, 1); + r.copyBinaryField(rOut, 0, 0); + r.copyBinaryField(rOut, 1, 1); col1Out = rOut.getTSInt128Field(0); col2Out = rOut.getTSInt128Field(1); EXPECT_EQ(col1In.getValue(), col1Out.getValue()); diff --git a/utils/rowgroup/rowaggregation.cpp b/utils/rowgroup/rowaggregation.cpp index 41301535b..092d10e08 100644 --- a/utils/rowgroup/rowaggregation.cpp +++ b/utils/rowgroup/rowaggregation.cpp @@ -868,7 +868,7 @@ void RowAggregation::initMapData(const Row& rowIn) if (LIKELY(rowIn.getColumnWidth(colIn) == datatypes::MAXDECIMALWIDTH)) { uint32_t colOutOffset = fRow.getOffset(colOut); - fRow.setBinaryField_offset(rowIn.getBinaryField(colIn), sizeof(int128_t), colOutOffset); + fRow.setBinaryField_offset(rowIn.getTSInt128Field(colIn).getValPtr(), sizeof(int128_t), colOutOffset); } 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.getBinaryField(colIn), fRow.getBinaryField(colOut), colOut, + updateIntMinMax(rowIn.getTSInt128Field(colIn).getValPtr(), fRow.getTSInt128Field(colOut).getValPtr(), colOut, funcType); } else if (rowIn.getColumnWidth(colIn) <= datatypes::MAXLEGACYWIDTH) @@ -1260,7 +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.getBinaryField(colIn); + int128_t* dec = rowIn.getTSInt128Field(colIn).getValPtr(); wideValInPtr = reinterpret_cast(dec); } else if (width <= datatypes::MAXLEGACYWIDTH) @@ -1329,8 +1329,8 @@ void RowAggregation::doSum(const Row& rowIn, int64_t colIn, int64_t colOut, int { if (LIKELY(!isNull(fRowGroupOut, fRow, colOut))) { - int128_t* valOutPtr = fRow.getBinaryField(colOut); - int128_t sum = *valOutPtr + valIn; + int128_t valOut = fRow.getTSInt128Field(colOut).getValue(); + int128_t sum = valOut + valIn; fRow.setBinaryField(&sum, colOut); } else @@ -1344,8 +1344,8 @@ void RowAggregation::doSum(const Row& rowIn, int64_t colIn, int64_t colOut, int int128_t* dec = reinterpret_cast(wideValInPtr); if (LIKELY(!isNull(fRowGroupOut, fRow, colOut))) { - int128_t* valOutPtr = fRow.getBinaryField(colOut); - int128_t sum = *valOutPtr + *dec; + int128_t valOut = fRow.getTSInt128Field(colOut).getValue(); + int128_t sum = valOut + *dec; fRow.setBinaryField(&sum, colOut); } else @@ -1793,7 +1793,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.getBinaryField(colIn); + int128_t* dec = rowIn.getTSInt128Field(colIn).getValPtr(); wideValInPtr = reinterpret_cast(dec); } else if (width <= datatypes::MAXLEGACYWIDTH) @@ -1859,8 +1859,8 @@ void RowAggregation::doAvg(const Row& rowIn, int64_t colIn, int64_t colOut, int6 { if (LIKELY(notFirstValue)) { - int128_t* valOutPtr = fRow.getBinaryField(colOut); - int128_t sum = *valOutPtr + valIn; + int128_t valOut = fRow.getTSInt128Field(colOut).getValue(); + int128_t sum = valOut + valIn; fRow.setBinaryField(&sum, colOut); } else @@ -1874,8 +1874,8 @@ void RowAggregation::doAvg(const Row& rowIn, int64_t colIn, int64_t colOut, int6 int128_t* dec = reinterpret_cast(wideValInPtr); if (LIKELY(notFirstValue)) { - int128_t* valOutPtr = fRow.getBinaryField(colOut); - int128_t sum = *valOutPtr + *dec; + int128_t valOut = fRow.getTSInt128Field(colOut).getValue(); + int128_t sum = valOut + *dec; fRow.setBinaryField(&sum, colOut); } else @@ -1925,7 +1925,7 @@ void RowAggregation::doStatistics(const Row& rowIn, int64_t colIn, int64_t colOu if (LIKELY(fRowGroupIn.getColumnWidth(colIn) == datatypes::MAXDECIMALWIDTH)) { // To save from unaligned memory - datatypes::TSInt128 val128In(rowIn.getBinaryField(colIn)); + datatypes::TSInt128 val128In = rowIn.getTSInt128Field(colIn); valIn = static_cast(val128In.toTFloat128()); } else if (fRowGroupIn.getColumnWidth(colIn) <= datatypes::MAXLEGACYWIDTH) @@ -4182,7 +4182,7 @@ void RowAggregationUMP2::doAvg(const Row& rowIn, int64_t colIn, int64_t colOut, isWideDataType = width == datatypes::MAXDECIMALWIDTH; if (LIKELY(isWideDataType)) { - int128_t* dec = rowIn.getBinaryField(colIn); + int128_t* dec = rowIn.getTSInt128Field(colIn).getValPtr(); wideValInPtr = reinterpret_cast(dec); } else if (width <= datatypes::MAXLEGACYWIDTH) @@ -4236,8 +4236,8 @@ void RowAggregationUMP2::doAvg(const Row& rowIn, int64_t colIn, int64_t colOut, { if (LIKELY(cnt > 0)) { - int128_t* valOutPtr = fRow.getBinaryField(colOut); - int128_t sum = valIn + *valOutPtr; + int128_t valOut = fRow.getTSInt128Field(colOut).getValue(); + int128_t sum = valIn + valOut; fRow.setBinaryField(&sum, colOut); fRow.setUintField(rowIn.getUintField(colAuxIn) + cnt, colAux); } @@ -4253,8 +4253,8 @@ void RowAggregationUMP2::doAvg(const Row& rowIn, int64_t colIn, int64_t colOut, int128_t* dec = reinterpret_cast(wideValInPtr); if (LIKELY(cnt > 0)) { - int128_t* valOutPtr = fRow.getBinaryField(colOut); - int128_t sum = *valOutPtr + *dec; + int128_t valOut = fRow.getTSInt128Field(colOut).getValue();; + int128_t sum = valOut + *dec; fRow.setBinaryField(&sum, colOut); fRow.setUintField(rowIn.getUintField(colAuxIn) + cnt, colAux); } diff --git a/utils/rowgroup/rowgroup.cpp b/utils/rowgroup/rowgroup.cpp index 7aa41477b..195199b02 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], getBinaryField(i)); + datatypes::Decimal dec(0, scale[i], precision[i], getTSInt128Field(i).getValPtr()); os << dec << " "; break; } @@ -1023,7 +1023,7 @@ bool Row::equals(const Row& r2, uint32_t lastCol) const } else if (UNLIKELY(datatypes::isWideDecimalType(columnType, colWidths[col]))) { - if (*getBinaryField(col) != *r2.getBinaryField(col)) + if (getTSInt128Field(col).getValue() != r2.getTSInt128Field(col).getValue()) return false; } else if (getUintField(col) != r2.getUintField(col)) @@ -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.getBinaryField(i), 16, out->getOffset(mapping[i])); + out->setBinaryField_offset(in.getTSInt128Field(i).getValPtr(), 16, out->getOffset(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 c3ecab709..eee661e43 100644 --- a/utils/rowgroup/rowgroup.h +++ b/utils/rowgroup/rowgroup.h @@ -443,7 +443,7 @@ class Row { if (LIKELY(getColumnWidth(colIndex) == datatypes::MAXDECIMALWIDTH)) return datatypes::Decimal(0, (int)getScale(colIndex), getPrecision(colIndex), - getBinaryField(colIndex)); + getTSInt128Field(colIndex).getValPtr()); return datatypes::Decimal(datatypes::TSInt64(getIntField(colIndex)), (int)getScale(colIndex), getPrecision(colIndex)); } @@ -516,12 +516,7 @@ class Row 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); - // inline std::string getBinaryField(uint32_t colIndex) const; - template - inline T* getBinaryField(uint32_t colIndex) const; - // To simplify parameter type deduction. - template - inline T* getBinaryField(T* argtype, uint32_t colIndex) const; + template inline T* getBinaryField_offset(uint32_t offset) const; @@ -549,7 +544,7 @@ class Row // that's not string-table safe, this one is inline void copyField(Row& dest, uint32_t destIndex, uint32_t srcIndex) const; - template + inline void copyBinaryField(Row& dest, uint32_t destIndex, uint32_t srcIndex) const; std::string toString(uint32_t rownum = 0) const; @@ -1019,17 +1014,6 @@ inline void Row::setStringField(const utils::ConstString& str, uint32_t colIndex } } -template -inline T* Row::getBinaryField(uint32_t colIndex) const -{ - return getBinaryField_offset(offsets[colIndex]); -} - -template -inline T* Row::getBinaryField(T* argtype, uint32_t colIndex) const -{ - return getBinaryField_offset(offsets[colIndex]); -} template inline T* Row::getBinaryField_offset(uint32_t offset) const @@ -1113,7 +1097,7 @@ inline void Row::getInt128Field(uint32_t colIndex, int128_t& x) const inline datatypes::TSInt128 Row::getTSInt128Field(uint32_t colIndex) const { - const int128_t* ptr = getBinaryField(colIndex); + const int128_t* ptr = reinterpret_cast(&data[offsets[colIndex]]);; return datatypes::TSInt128(ptr); } @@ -1351,7 +1335,7 @@ inline void Row::copyField(Row& out, uint32_t destIndex, uint32_t srcIndex) cons } else if (UNLIKELY(datatypes::isWideDecimalType(types[srcIndex], colWidths[srcIndex]))) { - copyBinaryField(out, destIndex, srcIndex); + copyBinaryField(out, destIndex, srcIndex); } else { @@ -1359,10 +1343,10 @@ inline void Row::copyField(Row& out, uint32_t destIndex, uint32_t srcIndex) cons } } -template + inline void Row::copyBinaryField(Row& out, uint32_t destIndex, uint32_t srcIndex) const { - out.setBinaryField(getBinaryField(srcIndex), destIndex); + out.setBinaryField(getTSInt128Field(srcIndex).getValPtr(), destIndex); } inline void Row::setRid(uint64_t rid) @@ -1981,7 +1965,7 @@ inline void copyRow(const Row& in, Row* out, uint32_t colCount) } else if (UNLIKELY(datatypes::isWideDecimalType(in.getColType(i), in.getColumnWidth(i)))) { - in.copyBinaryField(*out, i, i); + in.copyBinaryField(*out, i, i); } else { diff --git a/utils/windowfunction/windowfunctiontype.cpp b/utils/windowfunction/windowfunctiontype.cpp index 43f05f4bc..194aa81a4 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.getBinaryField(i)); + datatypes::TSInt128::assignPtrPtr(&t, fRow.getTSInt128Field(i).getValPtr()); } break; } diff --git a/writeengine/server/we_dmlcommandproc.cpp b/writeengine/server/we_dmlcommandproc.cpp index 5eb5cfbc1..0383826ce 100644 --- a/writeengine/server/we_dmlcommandproc.cpp +++ b/writeengine/server/we_dmlcommandproc.cpp @@ -205,7 +205,7 @@ uint8_t WE_DMLCommandProc::processSingleInsert(messageqcpp::ByteStream& bs, std: colStruct.colDataType = colType.colDataType; dctnryStruct.fCharsetNumber = colType.charsetNumber; - + if (colStruct.tokenFlag) { dctnryStruct.dctnryOid = colType.ddn.dictOID; @@ -1656,7 +1656,7 @@ uint8_t WE_DMLCommandProc::processBatchInsertBinary(messageqcpp::ByteStream& bs, } // @Bug 5996 validate hwm before starts - // TODO MCOL-5021 hasAuxCol is hardcoded to false; add support here. + // TODO MCOL-5021 hasAuxCol is hardcoded to false; add support here. rc = validateColumnHWMs(ridList, systemCatalogPtr, colDBRootExtentInfo, "Starting", false); if (rc != 0) @@ -3113,7 +3113,7 @@ uint8_t WE_DMLCommandProc::processUpdate(messageqcpp::ByteStream& bs, std::strin { datatypes::Decimal dec(0, fetchColScales[fetchColPos], rowGroups[txnId]->getPrecision()[fetchColPos], - row.getBinaryField(fetchColPos)); + row.getTSInt128Field(fetchColPos).getValPtr()); value = dec.toString(true); break; } @@ -3468,7 +3468,7 @@ uint8_t WE_DMLCommandProc::processUpdate(messageqcpp::ByteStream& bs, std::strin { datatypes::Decimal dec(0, fetchColScales[fetchColPos], rowGroups[txnId]->getPrecision()[fetchColPos], - row.getBinaryField(fetchColPos)); + row.getTSInt128Field(fetchColPos).getValPtr()); value = dec.toString(true); break; }