1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-08-05 16:15:50 +03:00

Bugfixes from develop (#2095)

* MaxConcurrentTransactions were not cleared when config is wrong (#2093)

* Wrong concatenation in between predicate (#2092)

* We forgot to initilize longdoublenull value (#2091)

* WriteBatchFieldMariaDB m_type was wrong (#2090)

* moda returned local object pointer (#2089)

* Wrong power of 2 in esimator` (#2088)

* targetDbroot should be assined, not compared (#2087)

* obviously wrong bytesTx assignment (#2086)

* GetInterrupted returned bool instead of bool * (#2085)
This commit is contained in:
Leonid Fedorov
2021-08-19 18:02:09 +03:00
committed by GitHub
parent e79c9ef1a3
commit ea622eec93
9 changed files with 72 additions and 120 deletions

View File

@@ -1211,7 +1211,7 @@ string BetweenPredicate::getPredicateString() const
between_predicate += fRH1ScalarExpression; between_predicate += fRH1ScalarExpression;
between_predicate += " "; between_predicate += " ";
between_predicate += fOperator2; between_predicate += fOperator2;
between_predicate + " "; between_predicate += " ";
between_predicate += fRH2ScalarExpression; between_predicate += fRH2ScalarExpression;
return between_predicate; return between_predicate;

View File

@@ -159,16 +159,16 @@ uint32_t RowEstimator::estimateDistinctValues(const execplan::CalpontSystemCatal
// Return limit/2 for integers where limit is number of possible values. // Return limit/2 for integers where limit is number of possible values.
case CalpontSystemCatalog::TINYINT: case CalpontSystemCatalog::TINYINT:
return (2 ^ 8) / 2; return (1 << 8) / 2;
case CalpontSystemCatalog::UTINYINT: case CalpontSystemCatalog::UTINYINT:
return (2 ^ 8); return (1 << 8);
case CalpontSystemCatalog::SMALLINT: case CalpontSystemCatalog::SMALLINT:
return (2 ^ 16) / 2; return (1 << 16) / 2;
case CalpontSystemCatalog::USMALLINT: case CalpontSystemCatalog::USMALLINT:
return (2 ^ 16); return (1 << 16);
// Next group all have range greater than 8M (# of rows in an extent), use 8M/2 as the estimate. // Next group all have range greater than 8M (# of rows in an extent), use 8M/2 as the estimate.
case CalpontSystemCatalog::MEDINT: case CalpontSystemCatalog::MEDINT:

View File

@@ -202,11 +202,11 @@ class WriteBatchFieldMariaDB: public WriteBatchField
public: public:
Field *m_field; Field * m_field;
const CalpontSystemCatalog::ColType &m_type; const CalpontSystemCatalog::ColType & m_type;
uint32_t m_mbmaxlen; uint32_t m_mbmaxlen;
WriteBatchFieldMariaDB(Field *field, WriteBatchFieldMariaDB(Field *field,
const CalpontSystemCatalog::ColType type, const CalpontSystemCatalog::ColType & type,
uint32_t mbmaxlen) uint32_t mbmaxlen)
:m_field(field), m_type(type), m_mbmaxlen(mbmaxlen) :m_field(field), m_type(type), m_mbmaxlen(mbmaxlen)
{ } { }
@@ -423,7 +423,7 @@ public:
return 8; return 8;
} }
size_t ColWriteBatchUInt64(const uchar *buf, bool nullVal, ColBatchWriter &ci) override size_t ColWriteBatchUInt64(const uchar *buf, bool nullVal, ColBatchWriter &ci) override
{ {
if (nullVal && (m_type.constraintType != CalpontSystemCatalog::NOTNULL_CONSTRAINT)) if (nullVal && (m_type.constraintType != CalpontSystemCatalog::NOTNULL_CONSTRAINT))
fprintf(ci.filePtr(), "%c", ci.delimiter()); fprintf(ci.filePtr(), "%c", ci.delimiter());
@@ -433,7 +433,7 @@ public:
} }
size_t ColWriteBatchSInt32(const uchar *buf, bool nullVal, ColBatchWriter &ci) override size_t ColWriteBatchSInt32(const uchar *buf, bool nullVal, ColBatchWriter &ci) override
{ {
if (nullVal && (m_type.constraintType != CalpontSystemCatalog::NOTNULL_CONSTRAINT)) if (nullVal && (m_type.constraintType != CalpontSystemCatalog::NOTNULL_CONSTRAINT))
fprintf(ci.filePtr(), "%c", ci.delimiter()); fprintf(ci.filePtr(), "%c", ci.delimiter());
@@ -442,7 +442,7 @@ public:
return 4; return 4;
} }
size_t ColWriteBatchUInt32(const uchar *buf, bool nullVal, ColBatchWriter &ci) override size_t ColWriteBatchUInt32(const uchar *buf, bool nullVal, ColBatchWriter &ci) override
{ {
if (nullVal && (m_type.constraintType != CalpontSystemCatalog::NOTNULL_CONSTRAINT)) if (nullVal && (m_type.constraintType != CalpontSystemCatalog::NOTNULL_CONSTRAINT))
fprintf(ci.filePtr(), "%c", ci.delimiter()); fprintf(ci.filePtr(), "%c", ci.delimiter());
@@ -451,7 +451,7 @@ public:
return 4; return 4;
} }
size_t ColWriteBatchSInt16(const uchar *buf, bool nullVal, ColBatchWriter &ci) override size_t ColWriteBatchSInt16(const uchar *buf, bool nullVal, ColBatchWriter &ci) override
{ {
if (nullVal && (m_type.constraintType != CalpontSystemCatalog::NOTNULL_CONSTRAINT)) if (nullVal && (m_type.constraintType != CalpontSystemCatalog::NOTNULL_CONSTRAINT))
fprintf(ci.filePtr(), "%c", ci.delimiter()); fprintf(ci.filePtr(), "%c", ci.delimiter());
@@ -460,7 +460,7 @@ public:
return 2; return 2;
} }
size_t ColWriteBatchUInt16(const uchar *buf, bool nullVal, ColBatchWriter &ci) override size_t ColWriteBatchUInt16(const uchar *buf, bool nullVal, ColBatchWriter &ci) override
{ {
if (nullVal && (m_type.constraintType != CalpontSystemCatalog::NOTNULL_CONSTRAINT)) if (nullVal && (m_type.constraintType != CalpontSystemCatalog::NOTNULL_CONSTRAINT))
fprintf(ci.filePtr(), "%c", ci.delimiter()); fprintf(ci.filePtr(), "%c", ci.delimiter());
@@ -469,7 +469,7 @@ public:
return 2; return 2;
} }
size_t ColWriteBatchSInt8(const uchar *buf, bool nullVal, ColBatchWriter &ci) override size_t ColWriteBatchSInt8(const uchar *buf, bool nullVal, ColBatchWriter &ci) override
{ {
if (nullVal && (m_type.constraintType != CalpontSystemCatalog::NOTNULL_CONSTRAINT)) if (nullVal && (m_type.constraintType != CalpontSystemCatalog::NOTNULL_CONSTRAINT))
fprintf(ci.filePtr(), "%c", ci.delimiter()); fprintf(ci.filePtr(), "%c", ci.delimiter());
@@ -478,7 +478,7 @@ public:
return 1; return 1;
} }
size_t ColWriteBatchUInt8(const uchar *buf, bool nullVal, ColBatchWriter &ci) override size_t ColWriteBatchUInt8(const uchar *buf, bool nullVal, ColBatchWriter &ci) override
{ {
if (nullVal && (m_type.constraintType != CalpontSystemCatalog::NOTNULL_CONSTRAINT)) if (nullVal && (m_type.constraintType != CalpontSystemCatalog::NOTNULL_CONSTRAINT))
fprintf(ci.filePtr(), "%c", ci.delimiter()); fprintf(ci.filePtr(), "%c", ci.delimiter());
@@ -488,7 +488,7 @@ public:
} }
size_t ColWriteBatchXFloat(const uchar *buf, bool nullVal, ColBatchWriter &ci) override size_t ColWriteBatchXFloat(const uchar *buf, bool nullVal, ColBatchWriter &ci) override
{ {
if (nullVal && (m_type.constraintType != CalpontSystemCatalog::NOTNULL_CONSTRAINT)) if (nullVal && (m_type.constraintType != CalpontSystemCatalog::NOTNULL_CONSTRAINT))
fprintf(ci.filePtr(), "%c", ci.delimiter()); fprintf(ci.filePtr(), "%c", ci.delimiter());
@@ -513,7 +513,7 @@ public:
} }
size_t ColWriteBatchXDouble(const uchar *buf, bool nullVal, ColBatchWriter &ci) override size_t ColWriteBatchXDouble(const uchar *buf, bool nullVal, ColBatchWriter &ci) override
{ {
if (nullVal && (m_type.constraintType != CalpontSystemCatalog::NOTNULL_CONSTRAINT)) if (nullVal && (m_type.constraintType != CalpontSystemCatalog::NOTNULL_CONSTRAINT))
fprintf(ci.filePtr(), "%c", ci.delimiter()); fprintf(ci.filePtr(), "%c", ci.delimiter());
@@ -527,7 +527,7 @@ public:
} }
size_t ColWriteBatchSLongDouble(const uchar *buf, bool nullVal, ColBatchWriter &ci) override size_t ColWriteBatchSLongDouble(const uchar *buf, bool nullVal, ColBatchWriter &ci) override
{ {
if (nullVal && (m_type.constraintType != CalpontSystemCatalog::NOTNULL_CONSTRAINT)) if (nullVal && (m_type.constraintType != CalpontSystemCatalog::NOTNULL_CONSTRAINT))
fprintf(ci.filePtr(), "%c", ci.delimiter()); fprintf(ci.filePtr(), "%c", ci.delimiter());
@@ -537,7 +537,7 @@ public:
} }
size_t ColWriteBatchXDecimal(const uchar *buf, bool nullVal, ColBatchWriter &ci) override size_t ColWriteBatchXDecimal(const uchar *buf, bool nullVal, ColBatchWriter &ci) override
{ {
uint bytesBefore = numDecimalBytes(m_type.precision - m_type.scale); uint bytesBefore = numDecimalBytes(m_type.precision - m_type.scale);
uint totalBytes = bytesBefore + numDecimalBytes(m_type.scale); uint totalBytes = bytesBefore + numDecimalBytes(m_type.scale);
@@ -838,13 +838,13 @@ public:
} }
size_t ColWriteBatchVarbinary(const uchar *buf0, bool nullVal, ColBatchWriter &ci) override size_t ColWriteBatchVarbinary(const uchar *buf0, bool nullVal, ColBatchWriter &ci) override
{ {
return ColWriteBatchString(buf0, nullVal, ci, &ColWriteBatchBlobString); return ColWriteBatchString(buf0, nullVal, ci, &ColWriteBatchBlobString);
} }
size_t ColWriteBatchBlob(const uchar *buf0, bool nullVal, ColBatchWriter &ci) override size_t ColWriteBatchBlob(const uchar *buf0, bool nullVal, ColBatchWriter &ci) override
{ {
return (UNLIKELY(m_type.colDataType == CalpontSystemCatalog::BLOB)) ? return (UNLIKELY(m_type.colDataType == CalpontSystemCatalog::BLOB)) ?
ColWriteBatchString(buf0, nullVal, ci, &ColWriteBatchBlobString) : ColWriteBatchString(buf0, nullVal, ci, &ColWriteBatchBlobString) :

View File

@@ -61,7 +61,7 @@ void Func::init()
double* dp = reinterpret_cast<double*>(&dni); double* dp = reinterpret_cast<double*>(&dni);
fDoubleNullVal = *dp; fDoubleNullVal = *dp;
fDoubleNullVal = joblist::LONGDOUBLENULL; fLongDoubleNullVal = joblist::LONGDOUBLENULL;
} }

View File

@@ -3,7 +3,7 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <string.h> #include <string.h>
#include <tr1/unordered_map> #include <unordered_map>
#include <algorithm> #include <algorithm>
#include "idb_mysql.h" #include "idb_mysql.h"
@@ -31,10 +31,11 @@ struct moda_data
{ {
long double fSum; long double fSum;
uint64_t fCount; uint64_t fCount;
enum Item_result fReturnType; enum Item_result fReturnType;
std::tr1::unordered_map<int64_t, uint32_t> mapINT; std::unordered_map<int64_t, uint32_t> mapINT;
std::tr1::unordered_map<double, uint32_t> mapREAL; std::unordered_map<double, uint32_t> mapREAL;
std::tr1::unordered_map<long double, uint32_t> mapDECIMAL; std::unordered_map<long double, uint32_t> mapDECIMAL;
std::string result;
void clear() void clear()
{ {
fSum = 0.0; fSum = 0.0;
@@ -44,9 +45,39 @@ struct moda_data
mapDECIMAL.clear(); mapDECIMAL.clear();
} }
}; };
} }
template<class TYPE, class CONTAINER>
char * moda(CONTAINER & container, struct moda_data* data)
{
TYPE avg = (TYPE)data->fCount ? data->fSum / data->fCount : 0;
TYPE val = 0.0;
uint32_t maxCnt = 0.0;
for (auto iter = container.begin(); iter != container.end(); ++iter)
{
if (iter->second > maxCnt)
{
val = iter->first;
maxCnt = iter->second;
}
else if (iter->second == maxCnt)
{
// Tie breaker: choose the closest to avg. If still tie, choose smallest
if ((abs(val-avg) > abs(iter->first-avg))
|| ((abs(val-avg) == abs(iter->first-avg)) && (abs(val) > abs(iter->first))))
{
val = iter->first;
}
}
}
data->result = std::to_string(val);
return const_cast<char*>(data->result.c_str());
}
extern "C" extern "C"
{ {
@@ -83,7 +114,7 @@ void moda_deinit(UDF_INIT* initid)
struct moda_data* data = (struct moda_data*)initid->ptr; struct moda_data* data = (struct moda_data*)initid->ptr;
data->clear(); data->clear();
delete data; delete data;
} }
#ifdef _MSC_VER #ifdef _MSC_VER
__declspec(dllexport) __declspec(dllexport)
@@ -98,7 +129,7 @@ void moda_clear(UDF_INIT* initid, char* is_null __attribute__((unused)),
#ifdef _MSC_VER #ifdef _MSC_VER
__declspec(dllexport) __declspec(dllexport)
#endif #endif
void moda_add(UDF_INIT* initid, void moda_add(UDF_INIT* initid,
UDF_ARGS* args, UDF_ARGS* args,
char* is_null, char* is_null,
char* message __attribute__((unused))) char* message __attribute__((unused)))
@@ -188,101 +219,22 @@ void moda_remove(UDF_INIT* initid, UDF_ARGS* args,
#ifdef _MSC_VER #ifdef _MSC_VER
__declspec(dllexport) __declspec(dllexport)
#endif #endif
char* moda(UDF_INIT* initid, UDF_ARGS* args __attribute__((unused)), char* moda(UDF_INIT* initid, UDF_ARGS* args, char* is_null, char* error __attribute__((unused)))
char* is_null, char* error __attribute__((unused)))
{ {
struct moda_data* data = (struct moda_data*)initid->ptr; struct moda_data* data = (struct moda_data*)initid->ptr;
uint32_t maxCnt = 0.0;
switch (args->arg_type[0]) switch (args->arg_type[0])
{ {
case INT_RESULT: case INT_RESULT:
{ return moda<int64_t>(data->mapINT, data);
typename std::tr1::unordered_map<int64_t, uint32_t>::iterator iter;
int64_t avg = (int64_t)data->fCount ? data->fSum / data->fCount : 0;
int64_t val = 0.0;
for (iter = data->mapINT.begin(); iter != data->mapINT.end(); ++iter)
{
if (iter->second > maxCnt)
{
val = iter->first;
maxCnt = iter->second;
}
else if (iter->second == maxCnt)
{
// Tie breaker: choose the closest to avg. If still tie, choose smallest
if ((abs(val-avg) > abs(iter->first-avg))
|| ((abs(val-avg) == abs(iter->first-avg)) && (abs(val) > abs(iter->first))))
{
val = iter->first;
}
}
}
std::ostringstream oss;
oss << val;
return const_cast<char*>(oss.str().c_str());
break;
}
case REAL_RESULT: case REAL_RESULT:
{ return moda<double>(data->mapREAL, data);
typename std::tr1::unordered_map<double, uint32_t>::iterator iter;
double avg = data->fCount ? data->fSum / data->fCount : 0;
double val = 0.0;
for (iter = data->mapREAL.begin(); iter != data->mapREAL.end(); ++iter)
{
if (iter->second > maxCnt)
{
val = iter->first;
maxCnt = iter->second;
}
else if (iter->second == maxCnt)
{
// Tie breaker: choose the closest to avg. If still tie, choose smallest
if ((abs(val-avg) > abs(iter->first-avg))
|| ((abs(val-avg) == abs(iter->first-avg)) && (abs(val) > abs(iter->first))))
{
val = iter->first;
}
}
}
std::ostringstream oss;
oss << val;
return const_cast<char*>(oss.str().c_str());
break;
}
case DECIMAL_RESULT: case DECIMAL_RESULT:
case STRING_RESULT: case STRING_RESULT:
{ return moda<long double>(data->mapDECIMAL, data);
typename std::tr1::unordered_map<long double, uint32_t>::iterator iter;
long double avg = data->fCount ? data->fSum / data->fCount : 0;
long double val = 0.0;
for (iter = data->mapDECIMAL.begin(); iter != data->mapDECIMAL.end(); ++iter)
{
if (iter->second > maxCnt)
{
val = iter->first;
maxCnt = iter->second;
}
else if (iter->second == maxCnt)
{
long double thisVal = iter->first;
// Tie breaker: choose the closest to avg. If still tie, choose smallest
if ((abs(val-avg) > abs(thisVal-avg))
|| ((abs(val-avg) == abs(thisVal-avg)) && (abs(val) > abs(thisVal))))
{
val = thisVal;
}
}
}
std::ostringstream oss;
oss << val;
return const_cast<char*>(oss.str().c_str());
break;
}
default: default:
break; return NULL;
} }
return NULL; return NULL;
} }
} // Extern "C" } // Extern "C"

View File

@@ -74,7 +74,7 @@ public:
{ {
return bInterrupted; return bInterrupted;
} }
bool getInterruptedPtr() bool * getInterruptedPtr()
{ {
return &bInterrupted; return &bInterrupted;
} }
@@ -98,7 +98,7 @@ protected:
bool bHasDropValue; // Set to false when we discover the UDAnF doesn't implement dropValue. bool bHasDropValue; // Set to false when we discover the UDAnF doesn't implement dropValue.
// To hold distinct values and their counts // To hold distinct values and their counts
typedef std::tr1::unordered_map<static_any::any, uint64_t, DistinctHasher, DistinctEqual> DistinctMap; typedef std::tr1::unordered_map<static_any::any, uint64_t, DistinctHasher, DistinctEqual> DistinctMap;
DistinctMap fDistinctMap; DistinctMap fDistinctMap;
static_any::any fValOut; // The return value static_any::any fValOut; // The return value

View File

@@ -100,7 +100,7 @@ SessionManagerServer::SessionManagerServer() : unique32(0), unique64(0)
catch (const std::exception& e) catch (const std::exception& e)
{ {
cout << e.what() << endl; cout << e.what() << endl;
stmp.empty(); stmp.clear();
} }
if (stmp != "") if (stmp != "")

View File

@@ -460,7 +460,7 @@ int RedistributeControlThread::makeRedistributePlan()
{ {
if (targetDbroot == targetDbroots.end()) if (targetDbroot == targetDbroots.end())
{ {
targetDbroot == targetDbroots.begin(); targetDbroot = targetDbroots.begin();
} }
if (dbPartVec[*targetDbroot].size() < partCount) if (dbPartVec[*targetDbroot].size() < partCount)

View File

@@ -213,7 +213,7 @@ public:
void setBytesTx(uint32_t BytesTx) void setBytesTx(uint32_t BytesTx)
{ {
boost::mutex::scoped_lock aLock(fTxMutex); boost::mutex::scoped_lock aLock(fTxMutex);
BytesTx = BytesTx; fBytesTx = BytesTx;
aLock.unlock(); aLock.unlock();
} }
void updateBytesTx(uint32_t fBytes) void updateBytesTx(uint32_t fBytes)