未验证 提交 3b0679d3 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #16445 from taosdata/enh/removeConvert

enh: remove compare type convertion
......@@ -105,6 +105,97 @@ int32_t compareStrPatternNotMatch(const void *pLeft, const void *pRight);
int32_t compareWStrPatternMatch(const void *pLeft, const void *pRight);
int32_t compareWStrPatternNotMatch(const void *pLeft, const void *pRight);
int32_t compareInt8Int16(const void *pLeft, const void *pRight);
int32_t compareInt8Int32(const void *pLeft, const void *pRight);
int32_t compareInt8Int64(const void *pLeft, const void *pRight);
int32_t compareInt8Float(const void *pLeft, const void *pRight);
int32_t compareInt8Double(const void *pLeft, const void *pRight);
int32_t compareInt8Uint8(const void *pLeft, const void *pRight);
int32_t compareInt8Uint16(const void *pLeft, const void *pRight);
int32_t compareInt8Uint32(const void *pLeft, const void *pRight);
int32_t compareInt8Uint64(const void *pLeft, const void *pRight);
int32_t compareInt16Int8(const void *pLeft, const void *pRight);
int32_t compareInt16Int32(const void *pLeft, const void *pRight);
int32_t compareInt16Int64(const void *pLeft, const void *pRight);
int32_t compareInt16Float(const void *pLeft, const void *pRight);
int32_t compareInt16Double(const void *pLeft, const void *pRight);
int32_t compareInt16Uint8(const void *pLeft, const void *pRight);
int32_t compareInt16Uint16(const void *pLeft, const void *pRight);
int32_t compareInt16Uint32(const void *pLeft, const void *pRight);
int32_t compareInt16Uint64(const void *pLeft, const void *pRight);
int32_t compareInt32Int8(const void *pLeft, const void *pRight);
int32_t compareInt32Int16(const void *pLeft, const void *pRight);
int32_t compareInt32Int64(const void *pLeft, const void *pRight);
int32_t compareInt32Float(const void *pLeft, const void *pRight);
int32_t compareInt32Double(const void *pLeft, const void *pRight);
int32_t compareInt32Uint8(const void *pLeft, const void *pRight);
int32_t compareInt32Uint16(const void *pLeft, const void *pRight);
int32_t compareInt32Uint32(const void *pLeft, const void *pRight);
int32_t compareInt32Uint64(const void *pLeft, const void *pRight);
int32_t compareInt64Int8(const void *pLeft, const void *pRight);
int32_t compareInt64Int16(const void *pLeft, const void *pRight);
int32_t compareInt64Int32(const void *pLeft, const void *pRight);
int32_t compareInt64Float(const void *pLeft, const void *pRight);
int32_t compareInt64Double(const void *pLeft, const void *pRight);
int32_t compareInt64Uint8(const void *pLeft, const void *pRight);
int32_t compareInt64Uint16(const void *pLeft, const void *pRight);
int32_t compareInt64Uint32(const void *pLeft, const void *pRight);
int32_t compareInt64Uint64(const void *pLeft, const void *pRight);
int32_t compareFloatInt8(const void *pLeft, const void *pRight);
int32_t compareFloatInt16(const void *pLeft, const void *pRight);
int32_t compareFloatInt32(const void *pLeft, const void *pRight);
int32_t compareFloatInt64(const void *pLeft, const void *pRight);
int32_t compareFloatDouble(const void *pLeft, const void *pRight);
int32_t compareFloatUint8(const void *pLeft, const void *pRight);
int32_t compareFloatUint16(const void *pLeft, const void *pRight);
int32_t compareFloatUint32(const void *pLeft, const void *pRight);
int32_t compareFloatUint64(const void *pLeft, const void *pRight);
int32_t compareDoubleInt8(const void *pLeft, const void *pRight);
int32_t compareDoubleInt16(const void *pLeft, const void *pRight);
int32_t compareDoubleInt32(const void *pLeft, const void *pRight);
int32_t compareDoubleInt64(const void *pLeft, const void *pRight);
int32_t compareDoubleFloat(const void *pLeft, const void *pRight);
int32_t compareDoubleUint8(const void *pLeft, const void *pRight);
int32_t compareDoubleUint16(const void *pLeft, const void *pRight);
int32_t compareDoubleUint32(const void *pLeft, const void *pRight);
int32_t compareDoubleUint64(const void *pLeft, const void *pRight);
int32_t compareUint8Int8(const void *pLeft, const void *pRight);
int32_t compareUint8Int16(const void *pLeft, const void *pRight);
int32_t compareUint8Int32(const void *pLeft, const void *pRight);
int32_t compareUint8Int64(const void *pLeft, const void *pRight);
int32_t compareUint8Float(const void *pLeft, const void *pRight);
int32_t compareUint8Double(const void *pLeft, const void *pRight);
int32_t compareUint8Uint16(const void *pLeft, const void *pRight);
int32_t compareUint8Uint32(const void *pLeft, const void *pRight);
int32_t compareUint8Uint64(const void *pLeft, const void *pRight);
int32_t compareUint16Int8(const void *pLeft, const void *pRight);
int32_t compareUint16Int16(const void *pLeft, const void *pRight);
int32_t compareUint16Int32(const void *pLeft, const void *pRight);
int32_t compareUint16Int64(const void *pLeft, const void *pRight);
int32_t compareUint16Float(const void *pLeft, const void *pRight);
int32_t compareUint16Double(const void *pLeft, const void *pRight);
int32_t compareUint16Uint8(const void *pLeft, const void *pRight);
int32_t compareUint16Uint32(const void *pLeft, const void *pRight);
int32_t compareUint16Uint64(const void *pLeft, const void *pRight);
int32_t compareUint32Int8(const void *pLeft, const void *pRight);
int32_t compareUint32Int16(const void *pLeft, const void *pRight);
int32_t compareUint32Int32(const void *pLeft, const void *pRight);
int32_t compareUint32Int64(const void *pLeft, const void *pRight);
int32_t compareUint32Float(const void *pLeft, const void *pRight);
int32_t compareUint32Double(const void *pLeft, const void *pRight);
int32_t compareUint32Uint8(const void *pLeft, const void *pRight);
int32_t compareUint32Uint16(const void *pLeft, const void *pRight);
int32_t compareUint32Uint64(const void *pLeft, const void *pRight);
int32_t compareUint64Int8(const void *pLeft, const void *pRight);
int32_t compareUint64Int16(const void *pLeft, const void *pRight);
int32_t compareUint64Int32(const void *pLeft, const void *pRight);
int32_t compareUint64Int64(const void *pLeft, const void *pRight);
int32_t compareUint64Float(const void *pLeft, const void *pRight);
int32_t compareUint64Double(const void *pLeft, const void *pRight);
int32_t compareUint64Uint8(const void *pLeft, const void *pRight);
int32_t compareUint64Uint16(const void *pLeft, const void *pRight);
int32_t compareUint64Uint32(const void *pLeft, const void *pRight);
__compar_fn_t getComparFunc(int32_t type, int32_t optr);
__compar_fn_t getKeyComparFunc(int32_t keyType, int32_t order);
int32_t doCompare(const char *a, const char *b, int32_t type, size_t size);
......
......@@ -350,6 +350,7 @@ struct SFilterInfo {
extern bool filterDoCompare(__compar_fn_t func, uint8_t optr, void *left, void *right);
extern __compar_fn_t filterGetCompFunc(int32_t type, int32_t optr);
extern __compar_fn_t filterGetCompFuncEx(int32_t lType, int32_t rType, int32_t optr);
#ifdef __cplusplus
}
......
......@@ -47,6 +47,7 @@ typedef struct SScalarCtx {
#define SCL_IS_NULL_VALUE_NODE(_node) ((QUERY_NODE_VALUE == nodeType(_node)) && (TSDB_DATA_TYPE_NULL == ((SValueNode *)_node)->node.resType.type))
#define SCL_IS_COMPARISON_OPERATOR(_opType) ((_opType) >= OP_TYPE_GREATER_THAN && (_opType) < OP_TYPE_IS_NOT_UNKNOWN)
#define SCL_DOWNGRADE_DATETYPE(_type) ((_type) == TSDB_DATA_TYPE_BIGINT || TSDB_DATA_TYPE_DOUBLE == (_type) || (_type) == TSDB_DATA_TYPE_UBIGINT)
#define SCL_NO_NEED_CONVERT_COMPARISION(_ltype, _rtype, _optr) (IS_NUMERIC_TYPE(_ltype) && IS_NUMERIC_TYPE(_rtype) && ((_optr) >= OP_TYPE_GREATER_THAN && (_optr) <= OP_TYPE_NOT_EQUAL))
#define sclFatal(...) qFatal(__VA_ARGS__)
#define sclError(...) qError(__VA_ARGS__)
......
......@@ -132,6 +132,77 @@ __compar_fn_t gDataCompare[] = {compareInt32Val, compareInt8Val, compareInt16Val
compareChkNotInString, compareStrPatternNotMatch, compareWStrPatternNotMatch
};
__compar_fn_t gInt8SignCompare[] = {
compareInt8Val, compareInt8Int16, compareInt8Int32, compareInt8Int64, compareInt8Float, compareInt8Double
};
__compar_fn_t gInt8UsignCompare[] = {
compareInt8Uint8, compareInt8Uint16, compareInt8Uint32, compareInt8Uint64
};
__compar_fn_t gInt16SignCompare[] = {
compareInt16Int8, compareInt16Val, compareInt16Int32, compareInt16Int64, compareInt16Float, compareInt16Double
};
__compar_fn_t gInt16UsignCompare[] = {
compareInt16Uint8, compareInt16Uint16, compareInt16Uint32, compareInt16Uint64
};
__compar_fn_t gInt32SignCompare[] = {
compareInt32Int8, compareInt32Int16, compareInt32Val, compareInt32Int64, compareInt32Float, compareInt32Double
};
__compar_fn_t gInt32UsignCompare[] = {
compareInt32Uint8, compareInt32Uint16, compareInt32Uint32, compareInt32Uint64
};
__compar_fn_t gInt64SignCompare[] = {
compareInt64Int8, compareInt64Int16, compareInt64Int32, compareInt64Val, compareInt64Float, compareInt64Double
};
__compar_fn_t gInt64UsignCompare[] = {
compareInt64Uint8, compareInt64Uint16, compareInt64Uint32, compareInt64Uint64
};
__compar_fn_t gFloatSignCompare[] = {
compareFloatInt8, compareFloatInt16, compareFloatInt32, compareFloatInt64, compareFloatVal, compareFloatDouble
};
__compar_fn_t gFloatUsignCompare[] = {
compareFloatUint8, compareFloatUint16, compareFloatUint32, compareFloatUint64
};
__compar_fn_t gDoubleSignCompare[] = {
compareDoubleInt8, compareDoubleInt16, compareDoubleInt32, compareDoubleInt64, compareDoubleFloat, compareDoubleVal
};
__compar_fn_t gDoubleUsignCompare[] = {
compareDoubleUint8, compareDoubleUint16, compareDoubleUint32, compareDoubleUint64
};
__compar_fn_t gUint8SignCompare[] = {
compareUint8Int8, compareUint8Int16, compareUint8Int32, compareUint8Int64, compareUint8Float, compareUint8Double
};
__compar_fn_t gUint8UsignCompare[] = {
compareUint8Val, compareUint8Uint16, compareUint8Uint32, compareUint8Uint64
};
__compar_fn_t gUint16SignCompare[] = {
compareUint16Int8, compareUint16Int16, compareUint16Int32, compareUint16Int64, compareUint16Float, compareUint16Double
};
__compar_fn_t gUint16UsignCompare[] = {
compareUint16Uint8, compareUint16Val, compareUint16Uint32, compareUint16Uint64
};
__compar_fn_t gUint32SignCompare[] = {
compareUint32Int8, compareUint32Int16, compareUint32Int32, compareUint32Int64, compareUint32Float, compareUint32Double
};
__compar_fn_t gUint32UsignCompare[] = {
compareUint32Uint8, compareUint32Uint16, compareUint32Val, compareUint32Uint64
};
__compar_fn_t gUint64SignCompare[] = {
compareUint64Int8, compareUint64Int16, compareUint64Int32, compareUint64Int64, compareUint64Float, compareUint64Double
};
__compar_fn_t gUint64UsignCompare[] = {
compareUint64Uint8, compareUint64Uint16, compareUint64Uint32, compareUint64Val
};
int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
int8_t comparFn = 0;
......@@ -257,6 +328,93 @@ __compar_fn_t filterGetCompFunc(int32_t type, int32_t optr) {
return gDataCompare[filterGetCompFuncIdx(type, optr)];
}
__compar_fn_t filterGetCompFuncEx(int32_t lType, int32_t rType, int32_t optr) {
switch (lType) {
case TSDB_DATA_TYPE_TINYINT: {
if (IS_SIGNED_NUMERIC_TYPE(rType) || IS_FLOAT_TYPE(rType)) {
return gInt8SignCompare[rType - TSDB_DATA_TYPE_TINYINT];
} else {
return gInt8UsignCompare[rType - TSDB_DATA_TYPE_UTINYINT];
}
break;
}
case TSDB_DATA_TYPE_SMALLINT: {
if (IS_SIGNED_NUMERIC_TYPE(rType) || IS_FLOAT_TYPE(rType)) {
return gInt16SignCompare[rType - TSDB_DATA_TYPE_TINYINT];
} else {
return gInt16UsignCompare[rType - TSDB_DATA_TYPE_UTINYINT];
}
break;
}
case TSDB_DATA_TYPE_INT: {
if (IS_SIGNED_NUMERIC_TYPE(rType) || IS_FLOAT_TYPE(rType)) {
return gInt32SignCompare[rType - TSDB_DATA_TYPE_TINYINT];
} else {
return gInt32UsignCompare[rType - TSDB_DATA_TYPE_UTINYINT];
}
break;
}
case TSDB_DATA_TYPE_BIGINT: {
if (IS_SIGNED_NUMERIC_TYPE(rType) || IS_FLOAT_TYPE(rType)) {
return gInt64SignCompare[rType - TSDB_DATA_TYPE_TINYINT];
} else {
return gInt64UsignCompare[rType - TSDB_DATA_TYPE_UTINYINT];
}
break;
}
case TSDB_DATA_TYPE_FLOAT: {
if (IS_SIGNED_NUMERIC_TYPE(rType) || IS_FLOAT_TYPE(rType)) {
return gFloatSignCompare[rType - TSDB_DATA_TYPE_TINYINT];
} else {
return gFloatUsignCompare[rType - TSDB_DATA_TYPE_UTINYINT];
}
break;
}
case TSDB_DATA_TYPE_DOUBLE: {
if (IS_SIGNED_NUMERIC_TYPE(rType) || IS_FLOAT_TYPE(rType)) {
return gDoubleSignCompare[rType - TSDB_DATA_TYPE_TINYINT];
} else {
return gDoubleUsignCompare[rType - TSDB_DATA_TYPE_UTINYINT];
}
break;
}
case TSDB_DATA_TYPE_UTINYINT: {
if (IS_SIGNED_NUMERIC_TYPE(rType) || IS_FLOAT_TYPE(rType)) {
return gUint8SignCompare[rType - TSDB_DATA_TYPE_TINYINT];
} else {
return gUint8UsignCompare[rType - TSDB_DATA_TYPE_UTINYINT];
}
break;
}
case TSDB_DATA_TYPE_USMALLINT: {
if (IS_SIGNED_NUMERIC_TYPE(rType) || IS_FLOAT_TYPE(rType)) {
return gUint16SignCompare[rType - TSDB_DATA_TYPE_TINYINT];
} else {
return gUint16UsignCompare[rType - TSDB_DATA_TYPE_UTINYINT];
}
break;
}
case TSDB_DATA_TYPE_UINT: {
if (IS_SIGNED_NUMERIC_TYPE(rType) || IS_FLOAT_TYPE(rType)) {
return gUint32SignCompare[rType - TSDB_DATA_TYPE_TINYINT];
} else {
return gUint32UsignCompare[rType - TSDB_DATA_TYPE_UTINYINT];
}
break;
}
case TSDB_DATA_TYPE_UBIGINT: {
if (IS_SIGNED_NUMERIC_TYPE(rType) || IS_FLOAT_TYPE(rType)) {
return gUint64SignCompare[rType - TSDB_DATA_TYPE_TINYINT];
} else {
return gUint64UsignCompare[rType - TSDB_DATA_TYPE_UTINYINT];
}
break;
}
default:
break;
}
return NULL;
}
static FORCE_INLINE int32_t filterCompareGroupCtx(const void *pLeft, const void *pRight) {
SFilterGroupCtx *left = *((SFilterGroupCtx**)pLeft), *right = *((SFilterGroupCtx**)pRight);
......
......@@ -909,11 +909,11 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut, int32_t*
int8_t gConvertTypes[TSDB_DATA_TYPE_BLOB+1][TSDB_DATA_TYPE_BLOB+1] = {
/* NULL BOOL TINY SMAL INT BIG FLOA DOUB VARC TIME NCHA UTIN USMA UINT UBIG JSON VARB DECI BLOB */
/*NULL*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/*BOOL*/ 0, 0, 0, 3, 4, 5, 6, 7, 7, 9, 7, 0, 12, 13, 14, 0, 7, 0, 0,
/*BOOL*/ 0, 0, 2, 3, 4, 5, 6, 7, 7, 9, 7, 11, 12, 13, 14, 0, 7, 0, 0,
/*TINY*/ 0, 0, 0, 3, 4, 5, 6, 7, 7, 9, 7, 3, 4, 5, 7, 0, 7, 0, 0,
/*SMAL*/ 0, 0, 0, 0, 4, 5, 6, 7, 7, 9, 7, 3, 4, 5, 7, 0, 7, 0, 0,
/*INT */ 0, 0, 0, 0, 0, 5, 6, 7, 7, 9, 7, 4, 4, 5, 7, 0, 7, 0, 0,
/*BIGI*/ 0, 0, 0, 0, 0, 0, 6, 7, 7, 0, 7, 5, 5, 5, 7, 0, 7, 0, 0,
/*BIGI*/ 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 7, 5, 5, 5, 7, 0, 7, 0, 0,
/*FLOA*/ 0, 0, 0, 0, 0, 0, 0, 7, 7, 6, 7, 6, 6, 6, 6, 0, 7, 0, 0,
/*DOUB*/ 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 0, 7, 0, 0,
/*VARC*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 8, 7, 7, 7, 7, 0, 0, 0, 0,
......@@ -1681,10 +1681,14 @@ void vectorBitOr(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord, int32_t optr) {
int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
__compar_fn_t fp = filterGetCompFunc(GET_PARAM_TYPE(pLeft), optr);
if(terrno != TSDB_CODE_SUCCESS){
return;
int32_t lType = GET_PARAM_TYPE(pLeft);
int32_t rType = GET_PARAM_TYPE(pRight);
__compar_fn_t fp = NULL;
if (lType == rType) {
fp = filterGetCompFunc(lType, optr);
} else {
fp = filterGetCompFuncEx(lType, rType, optr);
}
pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
......@@ -1716,22 +1720,26 @@ void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *
void vectorCompare(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord, int32_t optr) {
SScalarParam pLeftOut = {0};
SScalarParam pRightOut = {0};
vectorConvert(pLeft, pRight, &pLeftOut, &pRightOut);
SScalarParam *param1 = NULL;
SScalarParam *param2 = NULL;
if (pLeftOut.columnData != NULL) {
param1 = &pLeftOut;
} else {
if (SCL_NO_NEED_CONVERT_COMPARISION(GET_PARAM_TYPE(pLeft), GET_PARAM_TYPE(pRight), optr)) {
param1 = pLeft;
}
if (pRightOut.columnData != NULL) {
param2 = &pRightOut;
} else {
param2 = pRight;
} else {
vectorConvert(pLeft, pRight, &pLeftOut, &pRightOut);
if (pLeftOut.columnData != NULL) {
param1 = &pLeftOut;
} else {
param1 = pLeft;
}
if (pRightOut.columnData != NULL) {
param2 = &pRightOut;
} else {
param2 = pRight;
}
}
vectorCompareImpl(param1, param2, pOut, _ord, optr);
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册