1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-08-08 14:22:09 +03:00

Merge fixes.

This commit is contained in:
Roman Nozdrin
2020-06-25 14:16:13 +00:00
parent 8c02802ac1
commit bd0d5af123
5 changed files with 32 additions and 495 deletions

View File

@@ -128,405 +128,6 @@ private:
const CHARSET_INFO* cs; const CHARSET_INFO* cs;
}; };
inline bool PredicateOperator::getBoolVal(rowgroup::Row& row, bool& isNull, ReturnedColumn* lop, ReturnedColumn* rop)
{
// like operator. both sides are string.
if (fOp == OP_LIKE || fOp == OP_NOTLIKE)
{
SP_CNX_Regex regex = rop->regex();
// Ugh. The strings returned by getStrVal have null padding out to the col width. boost::regex
// considers these nulls significant, but they're not in the pattern, so we need to strip
// them off...
const std::string& v = lop->getStrVal(row, isNull);
// char* c = (char*)alloca(v.length() + 1);
// memcpy(c, v.c_str(), v.length());
// c[v.length()] = 0;
// std::string vv(c);
if (regex)
{
#ifdef POSIX_REGEX
bool ret = regexec(regex.get(), v.c_str(), 0, NULL, 0) == 0;
#else
bool ret = boost::regex_match(v.c_str(), *regex);
#endif
return (((fOp == OP_LIKE) ? ret : !ret) && !isNull);
}
else
{
#ifdef POSIX_REGEX
regex_t regex;
std::string str = dataconvert::DataConvert::constructRegexp(rop->getStrVal(row, isNull));
regcomp(&regex, str.c_str(), REG_NOSUB | REG_EXTENDED);
bool ret = regexec(&regex, v.c_str(), 0, NULL, 0) == 0;
regfree(&regex);
#else
boost::regex regex(dataconvert::DataConvert::constructRegexp(rop->getStrVal(row, isNull)));
bool ret = boost::regex_match(v.c_str(), regex);
#endif
return (((fOp == OP_LIKE) ? ret : !ret) && !isNull);
}
}
// fOpType should have already been set on the connector during parsing
switch (fOperationType.colDataType)
{
case execplan::CalpontSystemCatalog::BIGINT:
case execplan::CalpontSystemCatalog::INT:
case execplan::CalpontSystemCatalog::MEDINT:
case execplan::CalpontSystemCatalog::TINYINT:
case execplan::CalpontSystemCatalog::SMALLINT:
{
if (fOp == OP_ISNULL)
{
lop->getIntVal(row, isNull);
bool ret = isNull;
isNull = false;
return ret;
}
if (fOp == OP_ISNOTNULL)
{
lop->getIntVal(row, isNull);
bool ret = isNull;
isNull = false;
return !ret;
}
if (isNull)
return false;
int64_t val1 = lop->getIntVal(row, isNull);
if (isNull)
return false;
return numericCompare(val1, rop->getIntVal(row, isNull)) && !isNull;
}
case execplan::CalpontSystemCatalog::UBIGINT:
case execplan::CalpontSystemCatalog::UINT:
case execplan::CalpontSystemCatalog::UMEDINT:
case execplan::CalpontSystemCatalog::UTINYINT:
case execplan::CalpontSystemCatalog::USMALLINT:
{
if (fOp == OP_ISNULL)
{
lop->getUintVal(row, isNull);
bool ret = isNull;
isNull = false;
return ret;
}
if (fOp == OP_ISNOTNULL)
{
lop->getUintVal(row, isNull);
bool ret = isNull;
isNull = false;
return !ret;
}
if (isNull)
return false;
uint64_t val1 = lop->getUintVal(row, isNull);
if (isNull)
return false;
return numericCompare(val1, rop->getUintVal(row, isNull)) && !isNull;
}
case execplan::CalpontSystemCatalog::FLOAT:
case execplan::CalpontSystemCatalog::UFLOAT:
case execplan::CalpontSystemCatalog::DOUBLE:
case execplan::CalpontSystemCatalog::UDOUBLE:
{
if (fOp == OP_ISNULL)
{
lop->getDoubleVal(row, isNull);
bool ret = isNull;
isNull = false;
return ret;
}
if (fOp == OP_ISNOTNULL)
{
lop->getDoubleVal(row, isNull);
bool ret = isNull;
isNull = false;
return !ret;
}
if (isNull)
return false;
double val1 = lop->getDoubleVal(row, isNull);
if (isNull)
return false;
return numericCompare(val1, rop->getDoubleVal(row, isNull)) && !isNull;
}
case execplan::CalpontSystemCatalog::LONGDOUBLE:
{
if (fOp == OP_ISNULL)
{
lop->getLongDoubleVal(row, isNull);
bool ret = isNull;
isNull = false;
return ret;
}
if (fOp == OP_ISNOTNULL)
{
lop->getLongDoubleVal(row, isNull);
bool ret = isNull;
isNull = false;
return !ret;
}
if (isNull)
return false;
long double val1 = lop->getLongDoubleVal(row, isNull);
if (isNull)
return false;
long double val2 = rop->getLongDoubleVal(row, isNull);
if (isNull)
return false;
// In many case, rounding error will prevent an eq compare to work
// In these cases, use the largest scale of the two items.
if (fOp == execplan::OP_EQ)
{
// In case a val is a representation of a very large integer,
// we won't want to just multiply by scale, as it may move
// significant digits out of scope. So we break them apart
// and compare each separately
int64_t scale = std::max(lop->resultType().scale, rop->resultType().scale);
if (scale)
{
long double intpart1;
long double fract1 = modfl(val1, &intpart1);
long double intpart2;
long double fract2 = modfl(val2, &intpart2);
if (numericCompare(intpart1, intpart2))
{
double factor = pow(10.0, (double)scale);
fract1 = roundl(fract1 * factor);
fract2 = roundl(fract2 * factor);
return numericCompare(fract1, fract2);
}
else
{
return false;
}
}
}
return numericCompare(val1, val2);
}
case execplan::CalpontSystemCatalog::DECIMAL:
case execplan::CalpontSystemCatalog::UDECIMAL:
{
if (fOp == OP_ISNULL)
{
lop->getDecimalVal(row, isNull);
bool ret = isNull;
isNull = false;
return ret;
}
if (fOp == OP_ISNOTNULL)
{
lop->getDecimalVal(row, isNull);
bool ret = isNull;
isNull = false;
return !ret;
}
if (isNull)
return false;
IDB_Decimal val1 = lop->getDecimalVal(row, isNull);
if (isNull)
return false;
return numericCompare(val1, rop->getDecimalVal(row, isNull)) && !isNull;
}
case execplan::CalpontSystemCatalog::DATE:
{
if (fOp == OP_ISNULL)
{
lop->getDateIntVal(row, isNull);
bool ret = isNull;
isNull = false;
return ret;
}
if (fOp == OP_ISNOTNULL)
{
lop->getDateIntVal(row, isNull);
bool ret = isNull;
isNull = false;
return !ret;
}
if (isNull)
return false;
int64_t val1 = lop->getDateIntVal(row, isNull);
if (isNull)
return false;
return numericCompare(val1, (int64_t)rop->getDateIntVal(row, isNull)) && !isNull;
}
case execplan::CalpontSystemCatalog::DATETIME:
{
if (fOp == OP_ISNULL)
{
lop->getDatetimeIntVal(row, isNull);
bool ret = isNull;
isNull = false;
return ret;
}
if (fOp == OP_ISNOTNULL)
{
lop->getDatetimeIntVal(row, isNull);
bool ret = isNull;
isNull = false;
return !ret;
}
if (isNull)
return false;
int64_t val1 = lop->getDatetimeIntVal(row, isNull);
if (isNull)
return false;
return numericCompare(val1, rop->getDatetimeIntVal(row, isNull)) && !isNull;
}
case execplan::CalpontSystemCatalog::TIMESTAMP:
{
if (fOp == OP_ISNULL)
{
lop->getTimestampIntVal(row, isNull);
bool ret = isNull;
isNull = false;
return ret;
}
if (fOp == OP_ISNOTNULL)
{
lop->getTimestampIntVal(row, isNull);
bool ret = isNull;
isNull = false;
return !ret;
}
if (isNull)
return false;
int64_t val1 = lop->getTimestampIntVal(row, isNull);
if (isNull)
return false;
return numericCompare(val1, rop->getTimestampIntVal(row, isNull)) && !isNull;
}
case execplan::CalpontSystemCatalog::TIME:
{
if (fOp == OP_ISNULL)
{
lop->getTimeIntVal(row, isNull);
bool ret = isNull;
isNull = false;
return ret;
}
if (fOp == OP_ISNOTNULL)
{
lop->getTimeIntVal(row, isNull);
bool ret = isNull;
isNull = false;
return !ret;
}
if (isNull)
return false;
int64_t val1 = lop->getTimeIntVal(row, isNull);
if (isNull)
return false;
return numericCompare(val1, rop->getTimeIntVal(row, isNull)) && !isNull;
}
case execplan::CalpontSystemCatalog::VARCHAR:
case execplan::CalpontSystemCatalog::CHAR:
case execplan::CalpontSystemCatalog::TEXT:
{
if (fOp == OP_ISNULL)
{
lop->getStrVal(row, isNull);
bool ret = isNull;
isNull = false;
return ret;
}
if (fOp == OP_ISNOTNULL)
{
lop->getStrVal(row, isNull);
bool ret = isNull;
isNull = false;
return !ret;
}
if (isNull)
return false;
const std::string& val1 = lop->getStrVal(row, isNull);
if (isNull)
return false;
return strTrimCompare(val1, rop->getStrVal(row, isNull)) && !isNull;
// return strCompare(val1, rop->getStrVal(row, isNull)) && !isNull;
}
// MCOL-641 WIP This is an incorrect assumption.
case execplan::CalpontSystemCatalog::VARBINARY:
case execplan::CalpontSystemCatalog::BLOB:
return false;
break;
default:
{
std::ostringstream oss;
oss << "invalid predicate operation type: " << fOperationType.colDataType;
throw logging::InvalidOperationExcept(oss.str());
}
}
return false;
}
inline bool PredicateOperator::numericCompare(IDB_Decimal& op1, IDB_Decimal& op2) inline bool PredicateOperator::numericCompare(IDB_Decimal& op1, IDB_Decimal& op2)
{ {
switch (fOp) switch (fOp)

View File

@@ -155,12 +155,12 @@ string Func_char::getStrVal(Row& row,
if (tmpval > static_cast<int128_t>(INT64_MAX)) if (tmpval > static_cast<int128_t>(INT64_MAX))
tmpval = INT64_MAX; tmpval = INT64_MAX;
// WIP MCOL-641
if ( !getChar((int64_t)tmpval, buf) ) /*if ( !getChar((int64_t)tmpval, buf) )
{ {
isNull = true; isNull = true;
return ""; return "";
} }*/
} }
else else
{ {
@@ -172,11 +172,12 @@ string Func_char::getStrVal(Row& row,
if ( lefto > 4 ) if ( lefto > 4 )
value++; value++;
if ( !getChar((int64_t)value, buf) ) // WIP MCOL-641
/*if ( !getChar((int64_t)value, buf) )
{ {
isNull = true; isNull = true;
return ""; return "";
} }*/
} }
} }
break; break;

View File

@@ -57,7 +57,6 @@
//..comment out NDEBUG to enable assertions, uncomment NDEBUG to disable //..comment out NDEBUG to enable assertions, uncomment NDEBUG to disable
//#define NDEBUG //#define NDEBUG
#include "funcexp/utils_utf8.h"
#include "mcs_decimal.h" #include "mcs_decimal.h"
using namespace std; using namespace std;

View File

@@ -1175,10 +1175,11 @@ bool Row::equals(const Row& r2, const std::vector<uint32_t>& keyCols) const
for (uint32_t i = 0; i < keyCols.size(); i++) for (uint32_t i = 0; i < keyCols.size(); i++)
{ {
const uint32_t& col = keyCols[i]; const uint32_t& col = keyCols[i];
cscDataType columnType = getColType(col);
if (UNLIKELY(getColType(col) == execplan::CalpontSystemCatalog::VARCHAR || if (UNLIKELY(columnType == execplan::CalpontSystemCatalog::VARCHAR ||
(getColType(col) == execplan::CalpontSystemCatalog::CHAR && (colWidths[col] > 1)) || (columnType == execplan::CalpontSystemCatalog::CHAR && (colWidths[col] > 1)) ||
getColType(col) == execplan::CalpontSystemCatalog::TEXT)) columnType == execplan::CalpontSystemCatalog::TEXT))
{ {
CHARSET_INFO* cs = getCharset(col); CHARSET_INFO* cs = getCharset(col);
if (cs->strnncollsp(getStringPointer(col), getStringLength(col), if (cs->strnncollsp(getStringPointer(col), getStringLength(col),
@@ -1187,7 +1188,7 @@ bool Row::equals(const Row& r2, const std::vector<uint32_t>& keyCols) const
return false; return false;
} }
} }
else if (UNLIKELY(getColType(col) == execplan::CalpontSystemCatalog::BLOB)) else if (UNLIKELY(columnType == execplan::CalpontSystemCatalog::BLOB))
{ {
if (getStringLength(col) != r2.getStringLength(col)) if (getStringLength(col) != r2.getStringLength(col))
return false; return false;
@@ -1197,19 +1198,25 @@ bool Row::equals(const Row& r2, const std::vector<uint32_t>& keyCols) const
} }
else else
{ {
if (getColType(col) == execplan::CalpontSystemCatalog::LONGDOUBLE) if (UNLIKELY(columnType == execplan::CalpontSystemCatalog::LONGDOUBLE))
{ {
if (getLongDoubleField(col) != r2.getLongDoubleField(col)) if (getLongDoubleField(col) != r2.getLongDoubleField(col))
return false; return false;
} }
else if (UNLIKELY(execplan::isDecimal(columnType)))
{
if (getBinaryField<int128_t>(col) != r2.getBinaryField<int128_t>(col))
return false;
}
else if (getUintField(col) != r2.getUintField(col)) else if (getUintField(col) != r2.getUintField(col))
{
return false; return false;
}
} }
} }
return true; return true;
} }
bool Row::equals(const Row& r2, uint32_t lastCol) const bool Row::equals(const Row& r2, uint32_t lastCol) const
{ {
// This check fires with empty r2 only. // This check fires with empty r2 only.
@@ -1227,9 +1234,10 @@ bool Row::equals(const Row& r2, uint32_t lastCol) const
// because binary equality is not equality for many charsets/collations // because binary equality is not equality for many charsets/collations
for (uint32_t col = 0; col <= lastCol; col++) for (uint32_t col = 0; col <= lastCol; col++)
{ {
if (UNLIKELY(getColType(col) == execplan::CalpontSystemCatalog::VARCHAR || cscDataType columnType = getColType(col);
(getColType(col) == execplan::CalpontSystemCatalog::CHAR && (colWidths[col] > 1)) || if (UNLIKELY(columnType == execplan::CalpontSystemCatalog::VARCHAR ||
getColType(col) == execplan::CalpontSystemCatalog::TEXT)) (columnType == execplan::CalpontSystemCatalog::CHAR && (colWidths[col] > 1)) ||
columnType == execplan::CalpontSystemCatalog::TEXT))
{ {
CHARSET_INFO* cs = getCharset(col); CHARSET_INFO* cs = getCharset(col);
if (cs->strnncollsp(getStringPointer(col), getStringLength(col), if (cs->strnncollsp(getStringPointer(col), getStringLength(col),
@@ -1238,7 +1246,7 @@ bool Row::equals(const Row& r2, uint32_t lastCol) const
return false; return false;
} }
} }
else if (UNLIKELY(getColType(col) == execplan::CalpontSystemCatalog::BLOB)) else if (UNLIKELY(columnType == execplan::CalpontSystemCatalog::BLOB))
{ {
if (getStringLength(col) != r2.getStringLength(col)) if (getStringLength(col) != r2.getStringLength(col))
return false; return false;
@@ -1248,13 +1256,20 @@ bool Row::equals(const Row& r2, uint32_t lastCol) const
} }
else else
{ {
if (getColType(col) == execplan::CalpontSystemCatalog::LONGDOUBLE) if (UNLIKELY(columnType == execplan::CalpontSystemCatalog::LONGDOUBLE))
{ {
if (getLongDoubleField(col) != r2.getLongDoubleField(col)) if (getLongDoubleField(col) != r2.getLongDoubleField(col))
return false; return false;
} }
else if (UNLIKELY(execplan::isDecimal(columnType)))
{
if (getBinaryField<int128_t>(col) != r2.getBinaryField<int128_t>(col))
return false;
}
else if (getUintField(col) != r2.getUintField(col)) else if (getUintField(col) != r2.getUintField(col))
{
return false; return false;
}
} }
} }
return true; return true;

View File

@@ -1301,85 +1301,6 @@ inline uint64_t Row::hash(uint32_t lastCol) const
return ret; return ret;
} }
inline bool Row::equals(const Row& r2, const std::vector<uint32_t>& keyCols) const
{
for (uint32_t i = 0; i < keyCols.size(); i++)
{
const uint32_t& col = keyCols[i];
cscDataType columnType = getColType(i);
if (!isLongString(col))
{
if (UNLIKELY(columnType == execplan::CalpontSystemCatalog::LONGDOUBLE))
{
if (getLongDoubleField(i) != r2.getLongDoubleField(i))
return false;
}
else if (UNLIKELY(execplan::isDecimal(columnType)))
{
if (getBinaryField<int128_t>(i) != r2.getBinaryField<int128_t>(i))
return false;
}
else if (getUintField(col) != r2.getUintField(col))
return false;
}
else
{
if (getStringLength(col) != r2.getStringLength(col))
return false;
if (memcmp(getStringPointer(col), r2.getStringPointer(col), getStringLength(col)))
return false;
}
}
return true;
}
inline bool Row::equals(const Row& r2, uint32_t lastCol) const
{
// This check fires with empty r2 only.
if (lastCol >= columnCount)
return true;
if (!useStringTable && !r2.useStringTable)
return !(memcmp(&data[offsets[0]], &r2.data[offsets[0]], offsets[lastCol + 1] - offsets[0]));
for (uint32_t i = 0; i <= lastCol; i++)
{
cscDataType columnType = getColType(i);
if (!isLongString(i))
{
if (UNLIKELY(getColType(i) == execplan::CalpontSystemCatalog::LONGDOUBLE))
{
if (getLongDoubleField(i) != r2.getLongDoubleField(i))
return false;
}
else if (UNLIKELY(execplan::isDecimal(columnType)))
{
if (*getBinaryField<int128_t>(i) != *r2.getBinaryField<int128_t>(i))
return false;
}
else if (getUintField(i) != r2.getUintField(i))
return false;
}
else
{
uint32_t len = getStringLength(i);
if (len != r2.getStringLength(i))
return false;
if (memcmp(getStringPointer(i), r2.getStringPointer(i), len))
return false;
}
}
return true;
}
inline bool Row::equals(const Row& r2) const inline bool Row::equals(const Row& r2) const
{ {
return equals(r2, columnCount - 1); return equals(r2, columnCount - 1);