From 905a07801e0e9717e0c12792f4dc780a83886dea Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Mon, 1 Aug 2022 16:19:50 +0800 Subject: [PATCH 1/2] fix: fix errors of join test case --- include/util/taoserror.h | 1 + source/libs/parser/src/parTranslater.c | 26 + source/libs/scalar/src/filter.c | 669 +++++++++++++------------ source/util/src/terror.c | 1 + tests/script/jenkins/basic.txt | 2 +- tests/script/tsim/parser/join.sim | 26 +- 6 files changed, 393 insertions(+), 332 deletions(-) diff --git a/include/util/taoserror.h b/include/util/taoserror.h index da2f58307d..f0e5079399 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -556,6 +556,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_PAR_INVALID_SMA_INDEX TAOS_DEF_ERROR_CODE(0, 0x2660) #define TSDB_CODE_PAR_INVALID_SELECTED_EXPR TAOS_DEF_ERROR_CODE(0, 0x2661) #define TSDB_CODE_PAR_GET_META_ERROR TAOS_DEF_ERROR_CODE(0, 0x2662) +#define TSDB_CODE_PAR_NOT_UNIQUE_TABLE_ALIAS TAOS_DEF_ERROR_CODE(0, 0x2663) #define TSDB_CODE_PAR_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x26FF) //planner diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 5d1889194e..987a53533d 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -61,16 +61,42 @@ static bool beforeHaving(ESqlClause clause) { return clause < SQL_CLAUSE_HAVING; static bool afterHaving(ESqlClause clause) { return clause > SQL_CLAUSE_HAVING; } +static bool hasSameTableAlias(SArray* pTables) { + if (taosArrayGetSize(pTables) < 2) { + return false; + } + STableNode* pTable0 = taosArrayGetP(pTables, 0); + for (int32_t i = 1; i < taosArrayGetSize(pTables); ++i) { + STableNode* pTable = taosArrayGetP(pTables, i); + if (0 == strcmp(pTable0->tableAlias, pTable->tableAlias)) { + return true; + } + } + return false; +} + static int32_t addNamespace(STranslateContext* pCxt, void* pTable) { size_t currTotalLevel = taosArrayGetSize(pCxt->pNsLevel); if (currTotalLevel > pCxt->currLevel) { SArray* pTables = taosArrayGetP(pCxt->pNsLevel, pCxt->currLevel); taosArrayPush(pTables, &pTable); + if (hasSameTableAlias(pTables)) { + return generateSyntaxErrMsgExt(&pCxt->msgBuf, + TSDB_CODE_PAR_NOT_UNIQUE_TABLE_ALIAS, + "Not unique table/alias: '%s'", + ((STableNode*)pTable)->tableAlias); + } } else { do { SArray* pTables = taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES); if (pCxt->currLevel == currTotalLevel) { taosArrayPush(pTables, &pTable); + if (hasSameTableAlias(pTables)) { + return generateSyntaxErrMsgExt(&pCxt->msgBuf, + TSDB_CODE_PAR_NOT_UNIQUE_TABLE_ALIAS, + "Not unique table/alias: '%s'", + ((STableNode*)pTable)->tableAlias); + } } taosArrayPush(pCxt->pNsLevel, &pTables); ++currTotalLevel; diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index 8e4e31d6cc..04328fda9c 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -98,7 +98,7 @@ rangeCompFunc filterGetRangeCompFunc(char sflag, char eflag) { if (FILTER_GET_FLAG(eflag, RANGE_FLG_EXCLUDE)) { return filterRangeCompLe; } - + return filterRangeCompLi; } @@ -106,7 +106,7 @@ rangeCompFunc filterGetRangeCompFunc(char sflag, char eflag) { if (FILTER_GET_FLAG(sflag, RANGE_FLG_EXCLUDE)) { return filterRangeCompGe; } - + return filterRangeCompGi; } @@ -131,7 +131,7 @@ rangeCompFunc gRangeCompare[] = {filterRangeCompee, filterRangeCompei, filterRan int8_t filterGetRangeCompFuncFromOptrs(uint8_t optr, uint8_t optr2) { if (optr2) { - assert(optr2 == OP_TYPE_LOWER_THAN || optr2 == OP_TYPE_LOWER_EQUAL); + assert(optr2 == OP_TYPE_LOWER_THAN || optr2 == OP_TYPE_LOWER_EQUAL); if (optr == OP_TYPE_GREATER_THAN) { if (optr2 == OP_TYPE_LOWER_THAN) { @@ -165,9 +165,9 @@ int8_t filterGetRangeCompFuncFromOptrs(uint8_t optr, uint8_t optr2) { } __compar_fn_t gDataCompare[] = {compareInt32Val, compareInt8Val, compareInt16Val, compareInt64Val, compareFloatVal, - compareDoubleVal, compareLenPrefixedStr, compareStrPatternMatch, compareChkInString, compareWStrPatternMatch, + compareDoubleVal, compareLenPrefixedStr, compareStrPatternMatch, compareChkInString, compareWStrPatternMatch, compareLenPrefixedWStr, compareUint8Val, compareUint16Val, compareUint32Val, compareUint64Val, - setChkInBytes1, setChkInBytes2, setChkInBytes4, setChkInBytes8, compareStrRegexCompMatch, + setChkInBytes1, setChkInBytes2, setChkInBytes4, setChkInBytes8, compareStrRegexCompMatch, compareStrRegexCompNMatch, setChkNotInBytes1, setChkNotInBytes2, setChkNotInBytes4, setChkNotInBytes8, compareChkNotInString, compareStrPatternNotMatch, compareWStrPatternNotMatch }; @@ -178,20 +178,20 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) { if (optr == OP_TYPE_IN && (type != TSDB_DATA_TYPE_BINARY && type != TSDB_DATA_TYPE_NCHAR)) { switch (type) { case TSDB_DATA_TYPE_BOOL: - case TSDB_DATA_TYPE_TINYINT: - case TSDB_DATA_TYPE_UTINYINT: + case TSDB_DATA_TYPE_TINYINT: + case TSDB_DATA_TYPE_UTINYINT: return 15; case TSDB_DATA_TYPE_SMALLINT: case TSDB_DATA_TYPE_USMALLINT: return 16; case TSDB_DATA_TYPE_INT: case TSDB_DATA_TYPE_UINT: - case TSDB_DATA_TYPE_FLOAT: + case TSDB_DATA_TYPE_FLOAT: return 17; - case TSDB_DATA_TYPE_BIGINT: - case TSDB_DATA_TYPE_UBIGINT: - case TSDB_DATA_TYPE_DOUBLE: - case TSDB_DATA_TYPE_TIMESTAMP: + case TSDB_DATA_TYPE_BIGINT: + case TSDB_DATA_TYPE_UBIGINT: + case TSDB_DATA_TYPE_DOUBLE: + case TSDB_DATA_TYPE_TIMESTAMP: return 18; case TSDB_DATA_TYPE_JSON: terrno = TSDB_CODE_QRY_JSON_IN_ERROR; @@ -204,20 +204,20 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) { if (optr == OP_TYPE_NOT_IN && (type != TSDB_DATA_TYPE_BINARY && type != TSDB_DATA_TYPE_NCHAR)) { switch (type) { case TSDB_DATA_TYPE_BOOL: - case TSDB_DATA_TYPE_TINYINT: - case TSDB_DATA_TYPE_UTINYINT: + case TSDB_DATA_TYPE_TINYINT: + case TSDB_DATA_TYPE_UTINYINT: return 21; case TSDB_DATA_TYPE_SMALLINT: case TSDB_DATA_TYPE_USMALLINT: return 22; case TSDB_DATA_TYPE_INT: case TSDB_DATA_TYPE_UINT: - case TSDB_DATA_TYPE_FLOAT: + case TSDB_DATA_TYPE_FLOAT: return 23; - case TSDB_DATA_TYPE_BIGINT: - case TSDB_DATA_TYPE_UBIGINT: - case TSDB_DATA_TYPE_DOUBLE: - case TSDB_DATA_TYPE_TIMESTAMP: + case TSDB_DATA_TYPE_BIGINT: + case TSDB_DATA_TYPE_UBIGINT: + case TSDB_DATA_TYPE_DOUBLE: + case TSDB_DATA_TYPE_TIMESTAMP: return 24; case TSDB_DATA_TYPE_JSON: terrno = TSDB_CODE_QRY_JSON_IN_ERROR; @@ -257,10 +257,10 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) { } else { /* normal relational comparFn */ comparFn = 6; } - + break; } - + case TSDB_DATA_TYPE_NCHAR: { if (optr == OP_TYPE_MATCH) { comparFn = 19; @@ -289,7 +289,7 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) { comparFn = 0; break; } - + return comparFn; } @@ -308,7 +308,7 @@ static FORCE_INLINE int32_t filterCompareGroupCtx(const void *pLeft, const void int32_t filterInitUnitsFields(SFilterInfo *info) { info->unitSize = FILTER_DEFAULT_UNIT_SIZE; info->units = taosMemoryCalloc(info->unitSize, sizeof(SFilterUnit)); - + info->fields[FLD_TYPE_COLUMN].num = 0; info->fields[FLD_TYPE_COLUMN].size = FILTER_DEFAULT_FIELD_SIZE; info->fields[FLD_TYPE_COLUMN].fields = taosMemoryCalloc(info->fields[FLD_TYPE_COLUMN].size, sizeof(SFilterField)); @@ -321,7 +321,7 @@ int32_t filterInitUnitsFields(SFilterInfo *info) { static FORCE_INLINE SFilterRangeNode* filterNewRange(SFilterRangeCtx *ctx, SFilterRange* ra) { SFilterRangeNode *r = NULL; - + if (ctx->rf) { r = ctx->rf; ctx->rf = ctx->rf->next; @@ -341,7 +341,7 @@ void* filterInitRangeCtx(int32_t type, int32_t options) { qError("not supported range type:%d", type); return NULL; } - + SFilterRangeCtx *ctx = taosMemoryCalloc(1, sizeof(SFilterRangeCtx)); ctx->type = type; @@ -366,7 +366,7 @@ int32_t filterResetRangeCtx(SFilterRangeCtx *ctx) { ctx->isrange = false; SFilterRangeNode *r = ctx->rf; - + while (r && r->next) { r = r->next; } @@ -402,7 +402,7 @@ int32_t filterConvertRange(SFilterRangeCtx *cur, SFilterRange *ra, bool *notNull } } - + if (FILTER_GET_FLAG(ra->sflag, RANGE_FLG_NULL) && FILTER_GET_FLAG(ra->eflag, RANGE_FLG_NULL)) { *notNull = true; } else { @@ -438,7 +438,7 @@ int32_t filterAddRangeImpl(void* h, SFilterRange* ra, int32_t optr) { SFilterRangeCtx *ctx = (SFilterRangeCtx *)h; if (ctx->rs == NULL) { - if ((FILTER_GET_FLAG(ctx->status, MR_ST_START) == 0) + if ((FILTER_GET_FLAG(ctx->status, MR_ST_START) == 0) || (FILTER_GET_FLAG(ctx->status, MR_ST_ALL) && (optr == LOGIC_COND_TYPE_AND)) || ((!FILTER_GET_FLAG(ctx->status, MR_ST_ALL)) && (optr == LOGIC_COND_TYPE_OR))) { APPEND_RANGE(ctx, ctx->rs, ra); @@ -489,23 +489,23 @@ int32_t filterAddRangeImpl(void* h, SFilterRange* ra, int32_t optr) { //TSDB_RELATION_OR - + bool smerged = false; bool emerged = false; while (r != NULL) { cr = ctx->pCompareFunc(&r->ra.s, &ra->e); - if (FILTER_GREATER(cr, r->ra.sflag, ra->eflag)) { + if (FILTER_GREATER(cr, r->ra.sflag, ra->eflag)) { if (emerged == false) { INSERT_RANGE(ctx, r, ra); } - + break; } if (smerged == false) { cr = ctx->pCompareFunc(&ra->s, &r->ra.e); - if (FILTER_GREATER(cr, ra->sflag, r->ra.eflag)) { + if (FILTER_GREATER(cr, ra->sflag, r->ra.eflag)) { if (r->next) { r= r->next; continue; @@ -516,23 +516,23 @@ int32_t filterAddRangeImpl(void* h, SFilterRange* ra, int32_t optr) { } cr = ctx->pCompareFunc(&r->ra.s, &ra->s); - if (FILTER_GREATER(cr, r->ra.sflag, ra->sflag)) { - SIMPLE_COPY_VALUES((char *)&r->ra.s, &ra->s); + if (FILTER_GREATER(cr, r->ra.sflag, ra->sflag)) { + SIMPLE_COPY_VALUES((char *)&r->ra.s, &ra->s); cr == 0 ? (r->ra.sflag &= ra->sflag) : (r->ra.sflag = ra->sflag); } smerged = true; } - + if (emerged == false) { cr = ctx->pCompareFunc(&ra->e, &r->ra.e); if (FILTER_GREATER(cr, ra->eflag, r->ra.eflag)) { SIMPLE_COPY_VALUES((char *)&r->ra.e, &ra->e); - if (cr == 0) { + if (cr == 0) { r->ra.eflag &= ra->eflag; break; } - + r->ra.eflag = ra->eflag; emerged = true; r = r->next; @@ -553,7 +553,7 @@ int32_t filterAddRangeImpl(void* h, SFilterRange* ra, int32_t optr) { SIMPLE_COPY_VALUES(&r->prev->ra.e, (char *)&r->ra.e); cr == 0 ? (r->prev->ra.eflag &= r->ra.eflag) : (r->prev->ra.eflag = r->ra.eflag); FREE_RANGE(ctx, r); - + break; } } @@ -571,12 +571,12 @@ int32_t filterAddRangeImpl(void* h, SFilterRange* ra, int32_t optr) { } } - return TSDB_CODE_SUCCESS; + return TSDB_CODE_SUCCESS; } int32_t filterAddRange(void* h, SFilterRange* ra, int32_t optr) { SFilterRangeCtx *ctx = (SFilterRangeCtx *)h; - + if (FILTER_GET_FLAG(ra->sflag, RANGE_FLG_NULL)) { SIMPLE_COPY_VALUES(&ra->s, getDataMin(ctx->type)); //FILTER_CLR_FLAG(ra->sflag, RA_NULL); @@ -602,7 +602,7 @@ int32_t filterAddRangeCtx(void *dst, void *src, int32_t optr) { } SFilterRangeNode *r = sctx->rs; - + while (r) { filterAddRange(dctx, &r->ra, optr); r = r->next; @@ -616,14 +616,14 @@ int32_t filterCopyRangeCtx(void *dst, void *src) { SFilterRangeCtx *sctx = (SFilterRangeCtx *)src; dctx->status = sctx->status; - + dctx->isnull = sctx->isnull; dctx->notnull = sctx->notnull; dctx->isrange = sctx->isrange; SFilterRangeNode *r = sctx->rs; SFilterRangeNode *dr = dctx->rs; - + while (r) { APPEND_RANGE(dctx, dr, &r->ra); if (dr == NULL) { @@ -649,7 +649,7 @@ int32_t filterFinishRange(void* h) { if (FILTER_GET_FLAG(ctx->options, FLT_OPTION_TIMESTAMP)) { SFilterRangeNode *r = ctx->rs; SFilterRangeNode *rn = NULL; - + while (r && r->next) { int64_t tmp = 1; operateVal(&tmp, &r->ra.e, &tmp, OP_TYPE_ADD, ctx->type); @@ -658,10 +658,10 @@ int32_t filterFinishRange(void* h) { SIMPLE_COPY_VALUES((char *)&r->next->ra.s, (char *)&r->ra.s); FREE_RANGE(ctx, r); r = rn; - + continue; } - + r = r->next; } } @@ -673,13 +673,13 @@ int32_t filterFinishRange(void* h) { int32_t filterGetRangeNum(void* h, int32_t* num) { filterFinishRange(h); - + SFilterRangeCtx *ctx = (SFilterRangeCtx *)h; *num = 0; SFilterRangeNode *r = ctx->rs; - + while (r) { ++(*num); r = r->next; @@ -695,7 +695,7 @@ int32_t filterGetRangeRes(void* h, SFilterRange *ra) { SFilterRangeCtx *ctx = (SFilterRangeCtx *)h; uint32_t num = 0; SFilterRangeNode* r = ctx->rs; - + while (r) { if (num) { ra->e = r->ra.e; @@ -712,7 +712,7 @@ int32_t filterGetRangeRes(void* h, SFilterRange *ra) { qError("no range result"); return TSDB_CODE_QRY_APP_ERROR; } - + return TSDB_CODE_SUCCESS; } @@ -740,7 +740,7 @@ int32_t filterSourceRangeFromCtx(SFilterRangeCtx *ctx, void *sctx, int32_t optr, if (!(optr == LOGIC_COND_TYPE_OR && ctx->notnull)) { filterAddRangeCtx(ctx, src, optr); } - + if (FILTER_GET_FLAG(ctx->status, MR_ST_ALL)) { *all = true; } @@ -755,11 +755,11 @@ int32_t filterFreeRangeCtx(void* h) { if (h == NULL) { return TSDB_CODE_SUCCESS; } - + SFilterRangeCtx *ctx = (SFilterRangeCtx *)h; SFilterRangeNode *r = ctx->rs; SFilterRangeNode *rn = NULL; - + while (r) { rn = r->next; taosMemoryFree(r); @@ -785,10 +785,10 @@ int32_t filterDetachCnfGroup(SFilterGroup *gp1, SFilterGroup *gp2, SArray* group gp.unitNum = gp1->unitNum + gp2->unitNum; gp.unitIdxs = taosMemoryCalloc(gp.unitNum, sizeof(*gp.unitIdxs)); memcpy(gp.unitIdxs, gp1->unitIdxs, gp1->unitNum * sizeof(*gp.unitIdxs)); - memcpy(gp.unitIdxs + gp1->unitNum, gp2->unitIdxs, gp2->unitNum * sizeof(*gp.unitIdxs)); + memcpy(gp.unitIdxs + gp1->unitNum, gp2->unitIdxs, gp2->unitNum * sizeof(*gp.unitIdxs)); gp.unitFlags = NULL; - + taosArrayPush(group, &gp); return TSDB_CODE_SUCCESS; @@ -802,7 +802,7 @@ int32_t filterDetachCnfGroups(SArray* group, SArray* left, SArray* right) { if (taosArrayGetSize(left) <= 0) { if (taosArrayGetSize(right) <= 0) { fltError("both groups are empty"); - FLT_ERR_RET(TSDB_CODE_QRY_APP_ERROR); + FLT_ERR_RET(TSDB_CODE_QRY_APP_ERROR); } SFilterGroup *gp = NULL; @@ -813,7 +813,7 @@ int32_t filterDetachCnfGroups(SArray* group, SArray* left, SArray* right) { return TSDB_CODE_SUCCESS; } - if (taosArrayGetSize(right) <= 0) { + if (taosArrayGetSize(right) <= 0) { SFilterGroup *gp = NULL; while ((gp = (SFilterGroup *)taosArrayPop(left)) != NULL) { taosArrayPush(group, gp); @@ -821,10 +821,10 @@ int32_t filterDetachCnfGroups(SArray* group, SArray* left, SArray* right) { return TSDB_CODE_SUCCESS; } - + for (int32_t l = 0; l < leftSize; ++l) { SFilterGroup *gp1 = taosArrayGet(left, l); - + for (int32_t r = 0; r < rightSize; ++r) { SFilterGroup *gp2 = taosArrayGet(right, r); @@ -878,15 +878,15 @@ int32_t filterAddField(SFilterInfo *info, void *desc, void **data, int32_t type, idx = filterGetFiledByData(info, type, *data, dataLen); } } - + if (idx < 0) { idx = *num; if (idx >= info->fields[type].size) { info->fields[type].size += FILTER_DEFAULT_FIELD_SIZE; info->fields[type].fields = taosMemoryRealloc(info->fields[type].fields, info->fields[type].size * sizeof(SFilterField)); } - - info->fields[type].fields[idx].flag = type; + + info->fields[type].fields[idx].flag = type; info->fields[type].fields[idx].desc = desc; info->fields[type].fields[idx].data = data ? *data : NULL; @@ -900,7 +900,7 @@ int32_t filterAddField(SFilterInfo *info, void *desc, void **data, int32_t type, if (info->pctx.valHash == NULL) { info->pctx.valHash = taosHashInit(FILTER_DEFAULT_GROUP_SIZE * FILTER_DEFAULT_VALUE_SIZE, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, false); } - + taosHashPut(info->pctx.valHash, *data, dataLen, &idx, sizeof(idx)); } } else { @@ -911,7 +911,7 @@ int32_t filterAddField(SFilterInfo *info, void *desc, void **data, int32_t type, fid->type = type; fid->idx = idx; - + return TSDB_CODE_SUCCESS; } @@ -929,11 +929,11 @@ int32_t filterAddFieldFromNode(SFilterInfo *info, SNode *node, SFilterFieldId *f fltError("empty node"); FLT_ERR_RET(TSDB_CODE_QRY_APP_ERROR); } - + if (nodeType(node) != QUERY_NODE_COLUMN && nodeType(node) != QUERY_NODE_VALUE && nodeType(node) != QUERY_NODE_NODE_LIST) { FLT_ERR_RET(TSDB_CODE_QRY_APP_ERROR); } - + int32_t type; void *v; @@ -946,7 +946,7 @@ int32_t filterAddFieldFromNode(SFilterInfo *info, SNode *node, SFilterFieldId *f } filterAddField(info, v, NULL, type, fid, 0, true); - + return TSDB_CODE_SUCCESS; } @@ -973,7 +973,7 @@ int32_t filterAddUnit(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, SFi } SFilterUnit *u = &info->units[info->unitNum]; - + u->compare.optr = optr; u->left = *left; if (right) { @@ -981,7 +981,7 @@ int32_t filterAddUnit(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, SFi } if (u->right.type == FLD_TYPE_VALUE) { - SFilterField *val = FILTER_UNIT_RIGHT_FIELD(info, u); + SFilterField *val = FILTER_UNIT_RIGHT_FIELD(info, u); assert(FILTER_GET_FLAG(val->flag, FLD_TYPE_VALUE)); } else { int32_t paramNum = scalarGetOperatorParamNum(optr); @@ -990,10 +990,10 @@ int32_t filterAddUnit(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, SFi return TSDB_CODE_QRY_APP_ERROR; } } - + SFilterField *col = FILTER_UNIT_LEFT_FIELD(info, u); assert(FILTER_GET_FLAG(col->flag, FLD_TYPE_COLUMN)); - + info->units[info->unitNum].compare.type = FILTER_GET_COL_FIELD_TYPE(col); info->units[info->unitNum].compare.precision = FILTER_GET_COL_FIELD_PRECISION(col); @@ -1001,12 +1001,12 @@ int32_t filterAddUnit(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, SFi if (FILTER_GET_FLAG(info->options, FLT_OPTION_NEED_UNIQE)) { int64_t v = 0; - FILTER_PACKAGE_UNIT_HASH_KEY(&v, optr, left->idx, right ? right->idx : -1); + FILTER_PACKAGE_UNIT_HASH_KEY(&v, optr, left->idx, right ? right->idx : -1); taosHashPut(info->pctx.unitHash, &v, sizeof(v), uidx, sizeof(*uidx)); } - + ++info->unitNum; - + return TSDB_CODE_SUCCESS; } @@ -1017,7 +1017,7 @@ int32_t filterAddUnitToGroup(SFilterGroup *group, uint32_t unitIdx) { group->unitSize += FILTER_DEFAULT_UNIT_SIZE; group->unitIdxs = taosMemoryRealloc(group->unitIdxs, group->unitSize * sizeof(*group->unitIdxs)); } - + group->unitIdxs[group->unitNum++] = unitIdx; return TSDB_CODE_SUCCESS; @@ -1040,10 +1040,10 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) { SScalarParam out = {.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData))}; out.columnData->info.type = type; out.columnData->info.bytes = tDataTypes[type].bytes; - + for (int32_t i = 0; i < listNode->pNodeList->length; ++i) { SValueNode *valueNode = (SValueNode *)cell->pNode; - if (valueNode->node.resType.type != type) { + if (valueNode->node.resType.type != type) { int32_t overflow = 0; code = doConvertDataType(valueNode, &out, &overflow); if (code) { @@ -1055,7 +1055,7 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) { cell = cell->pNext; continue; } - + len = tDataTypes[type].bytes; filterAddField(info, NULL, (void**) &out.columnData->pData, FLD_TYPE_VALUE, &right, len, true); @@ -1066,13 +1066,13 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) { FLT_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } memcpy(data, nodesGetValueFromNode(valueNode), tDataTypes[type].bytes); - filterAddField(info, NULL, (void**) &data, FLD_TYPE_VALUE, &right, len, true); + filterAddField(info, NULL, (void**) &data, FLD_TYPE_VALUE, &right, len, true); } filterAddUnit(info, OP_TYPE_EQUAL, &left, &right, &uidx); - + SFilterGroup fgroup = {0}; filterAddUnitToGroup(&fgroup, uidx); - + taosArrayPush(group, &fgroup); cell = cell->pNext; @@ -1081,14 +1081,14 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) { taosMemoryFree(out.columnData); } else { filterAddFieldFromNode(info, node->pRight, &right); - + FLT_ERR_RET(filterAddUnit(info, node->opType, &left, &right, &uidx)); SFilterGroup fgroup = {0}; filterAddUnitToGroup(&fgroup, uidx); - + taosArrayPush(group, &fgroup); } - + return TSDB_CODE_SUCCESS; } @@ -1100,7 +1100,7 @@ int32_t filterAddUnitFromUnit(SFilterInfo *dst, SFilterInfo *src, SFilterUnit* u filterAddField(dst, FILTER_UNIT_COL_DESC(src, u), NULL, FLD_TYPE_COLUMN, &left, 0, false); SFilterField *t = FILTER_UNIT_LEFT_FIELD(src, u); - + if (u->right.type == FLD_TYPE_VALUE) { void *data = FILTER_UNIT_VAL_DATA(src, u); if (IS_VAR_DATA_TYPE(type)) { @@ -1116,7 +1116,7 @@ int32_t filterAddUnitFromUnit(SFilterInfo *dst, SFilterInfo *src, SFilterUnit* u filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, false); } - flag = FLD_DATA_NO_FREE; + flag = FLD_DATA_NO_FREE; t = FILTER_UNIT_RIGHT_FIELD(src, u); FILTER_SET_FLAG(t->flag, flag); } else { @@ -1152,7 +1152,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan return TSDB_CODE_SUCCESS; } - if (ctx->notnull) { + if (ctx->notnull) { assert(ctx->isnull == false && ctx->isrange == false); filterAddUnit(dst, OP_TYPE_IS_NOT_NULL, &left, NULL, &uidx); filterAddUnitToGroup(g, uidx); @@ -1167,7 +1167,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan assert(ctx->rs && ctx->rs->next == NULL); SFilterRange *ra = &ctx->rs->ra; - + assert(!((FILTER_GET_FLAG(ra->sflag, RANGE_FLG_NULL)) && (FILTER_GET_FLAG(ra->eflag, RANGE_FLG_NULL)))); if ((!FILTER_GET_FLAG(ra->sflag, RANGE_FLG_NULL)) && (!FILTER_GET_FLAG(ra->eflag, RANGE_FLG_NULL))) { @@ -1178,7 +1178,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); filterAddUnit(dst, OP_TYPE_EQUAL, &left, &right, &uidx); filterAddUnitToGroup(g, uidx); - return TSDB_CODE_SUCCESS; + return TSDB_CODE_SUCCESS; } else { void *data = taosMemoryMalloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data, &ra->s); @@ -1186,14 +1186,14 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan void *data2 = taosMemoryMalloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data2, &ra->e); filterAddField(dst, NULL, &data2, FLD_TYPE_VALUE, &right2, tDataTypes[type].bytes, true); - + filterAddUnit(dst, FILTER_GET_FLAG(ra->sflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_GREATER_THAN : OP_TYPE_GREATER_EQUAL, &left, &right, &uidx); filterAddUnitRight(dst, FILTER_GET_FLAG(ra->eflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_LOWER_THAN : OP_TYPE_LOWER_EQUAL, &right2, uidx); filterAddUnitToGroup(g, uidx); - return TSDB_CODE_SUCCESS; + return TSDB_CODE_SUCCESS; } } - + if (!FILTER_GET_FLAG(ra->sflag, RANGE_FLG_NULL)) { void *data = taosMemoryMalloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data, &ra->s); @@ -1208,28 +1208,28 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); filterAddUnit(dst, FILTER_GET_FLAG(ra->eflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_LOWER_THAN : OP_TYPE_LOWER_EQUAL, &left, &right, &uidx); filterAddUnitToGroup(g, uidx); - } + } - return TSDB_CODE_SUCCESS; - } + return TSDB_CODE_SUCCESS; + } // OR PROCESS - + SFilterGroup ng = {0}; g = &ng; assert(ctx->isnull || ctx->notnull || ctx->isrange); - + if (ctx->isnull) { filterAddUnit(dst, OP_TYPE_IS_NULL, &left, NULL, &uidx); - filterAddUnitToGroup(g, uidx); + filterAddUnitToGroup(g, uidx); taosArrayPush(res, g); } - + if (ctx->notnull) { assert(!ctx->isrange); memset(g, 0, sizeof(*g)); - + filterAddUnit(dst, OP_TYPE_IS_NOT_NULL, &left, NULL, &uidx); filterAddUnitToGroup(g, uidx); taosArrayPush(res, g); @@ -1242,7 +1242,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan } SFilterRangeNode *r = ctx->rs; - + while (r) { memset(g, 0, sizeof(*g)); @@ -1261,19 +1261,19 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan void *data2 = taosMemoryMalloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data2, &r->ra.e); filterAddField(dst, NULL, &data2, FLD_TYPE_VALUE, &right2, tDataTypes[type].bytes, true); - + filterAddUnit(dst, FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_GREATER_THAN : OP_TYPE_GREATER_EQUAL, &left, &right, &uidx); filterAddUnitRight(dst, FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_LOWER_THAN : OP_TYPE_LOWER_EQUAL, &right2, uidx); filterAddUnitToGroup(g, uidx); } taosArrayPush(res, g); - + r = r->next; - + continue; } - + if (!FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_NULL)) { void *data = taosMemoryMalloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data, &r->ra.s); @@ -1281,10 +1281,10 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan filterAddUnit(dst, FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_GREATER_THAN : OP_TYPE_GREATER_EQUAL, &left, &right, &uidx); filterAddUnitToGroup(g, uidx); } - + if (!FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_NULL)) { void *data = taosMemoryMalloc(sizeof(int64_t)); - SIMPLE_COPY_VALUES(data, &r->ra.e); + SIMPLE_COPY_VALUES(data, &r->ra.e); filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); filterAddUnit(dst, FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_EXCLUDE) ? OP_TYPE_LOWER_THAN : OP_TYPE_LOWER_EQUAL, &left, &right, &uidx); filterAddUnitToGroup(g, uidx); @@ -1307,7 +1307,7 @@ static void filterFreeGroup(void *pItem) { if (pItem == NULL) { return; } - + SFilterGroup* p = (SFilterGroup*) pItem; taosMemoryFreeClear(p->unitIdxs); taosMemoryFreeClear(p->unitFlags); @@ -1329,17 +1329,17 @@ EDealRes fltTreeToGroup(SNode* pNode, void* pContext) { for (int32_t i = 0; i < node->pParameterList->length; ++i) { newGroup = taosArrayInit(4, sizeof(SFilterGroup)); resGroup = taosArrayInit(4, sizeof(SFilterGroup)); - + SFltBuildGroupCtx tctx = {.info = ctx->info, .group = newGroup}; nodesWalkExpr(cell->pNode, fltTreeToGroup, (void *)&tctx); FLT_ERR_JRET(tctx.code); - + FLT_ERR_JRET(filterDetachCnfGroups(resGroup, preGroup, newGroup)); - + taosArrayDestroyEx(newGroup, filterFreeGroup); newGroup = NULL; taosArrayDestroyEx(preGroup, filterFreeGroup); - + preGroup = resGroup; resGroup = NULL; @@ -1349,7 +1349,7 @@ EDealRes fltTreeToGroup(SNode* pNode, void* pContext) { taosArrayAddAll(ctx->group, preGroup); taosArrayDestroy(preGroup); - + return DEAL_RES_IGNORE_CHILD; } @@ -1358,23 +1358,23 @@ EDealRes fltTreeToGroup(SNode* pNode, void* pContext) { for (int32_t i = 0; i < node->pParameterList->length; ++i) { nodesWalkExpr(cell->pNode, fltTreeToGroup, (void *)pContext); FLT_ERR_JRET(ctx->code); - + cell = cell->pNext; } - + return DEAL_RES_IGNORE_CHILD; } ctx->code = TSDB_CODE_QRY_APP_ERROR; - + fltError("invalid condition type, type:%d", node->condType); return DEAL_RES_ERROR; } if (QUERY_NODE_OPERATOR == nType) { - FLT_ERR_JRET(fltAddGroupUnitFromNode(ctx->info, pNode, ctx->group)); - + FLT_ERR_JRET(fltAddGroupUnitFromNode(ctx->info, pNode, ctx->group)); + return DEAL_RES_IGNORE_CHILD; } @@ -1497,7 +1497,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) SValueNode *var = (SValueNode *)field->desc; SDataType *dType = &var->node.resType; if (dType->type == TSDB_DATA_TYPE_VALUE_ARRAY) { - qDebug("VAL%d => [type:TS][val:[%" PRIi64"] - [%" PRId64 "]]", i, *(int64_t *)field->data, *(((int64_t *)field->data) + 1)); + qDebug("VAL%d => [type:TS][val:[%" PRIi64"] - [%" PRId64 "]]", i, *(int64_t *)field->data, *(((int64_t *)field->data) + 1)); } else { qDebug("VAL%d => [type:%d][val:%" PRIx64"]", i, dType->type, var->datum.i); //TODO } @@ -1513,7 +1513,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) int32_t len = 0; int32_t tlen = 0; char str[512] = {0}; - + SFilterField *left = FILTER_UNIT_LEFT_FIELD(info, unit); SColumnNode *refNode = (SColumnNode *)left->desc; if (unit->compare.optr >= 0 && unit->compare.optr <= OP_TYPE_JSON_CONTAINS){ @@ -1538,7 +1538,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) if (unit->compare.optr2 >= 0 && unit->compare.optr2 <= OP_TYPE_JSON_CONTAINS){ sprintf(str + strlen(str), "[%d][%d] %s [", refNode->dataBlockId, refNode->slotId, gOptrStr[unit->compare.optr2].str); } - + if (unit->right2.type == FLD_TYPE_VALUE && FILTER_UNIT_OPTR(unit) != OP_TYPE_IN) { SFilterField *right = FILTER_UNIT_RIGHT2_FIELD(info, unit); char *data = right->data; @@ -1552,7 +1552,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) } strcat(str, "]"); } - + qDebug("%s", str); //TODO } @@ -1576,10 +1576,10 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) for (uint32_t i = 0; i < info->colRangeNum; ++i) { SFilterRangeCtx *ctx = info->colRange[i]; qDebug("Column ID[%d] RANGE: isnull[%d],notnull[%d],range[%d]", ctx->colId, ctx->isnull, ctx->notnull, ctx->isrange); - if (ctx->isrange) { + if (ctx->isrange) { SFilterRangeNode *r = ctx->rs; while (r) { - char str[256] = {0}; + char str[256] = {0}; int32_t tlen = 0; if (FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_NULL)) { strcat(str,"(NULL)"); @@ -1596,8 +1596,8 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) fltConverToStr(str + strlen(str), ctx->type, &r->ra.e, tlen > 32 ? 32 : tlen, &tlen); FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_EXCLUDE) ? strcat(str,")") : strcat(str,"]"); } - qDebug("range: %s", str); - + qDebug("range: %s", str); + r = r->next; } } @@ -1640,7 +1640,7 @@ void filterFreeColInfo(void *data) { if (info->type == RANGE_TYPE_VAR_HASH) { //TODO } else if (info->type == RANGE_TYPE_MR_CTX) { - filterFreeRangeCtx(info->info); + filterFreeRangeCtx(info->info); } else if (info->type == RANGE_TYPE_UNIT) { taosArrayDestroy((SArray *)info->info); } @@ -1714,14 +1714,14 @@ void filterFreeInfo(SFilterInfo *info) { for (uint32_t f = 0; f < info->fields[i].num; ++f) { filterFreeField(&info->fields[i].fields[f], i); } - + taosMemoryFreeClear(info->fields[i].fields); } for (uint32_t i = 0; i < info->groupNum; ++i) { - filterFreeGroup(&info->groups[i]); + filterFreeGroup(&info->groups[i]); } - + taosMemoryFreeClear(info->groups); taosMemoryFreeClear(info->units); @@ -1745,7 +1745,7 @@ void filterFreeInfo(SFilterInfo *info) { int32_t filterHandleValueExtInfo(SFilterUnit* unit, char extInfo) { assert(extInfo > 0 || extInfo < 0); - + uint8_t optr = FILTER_UNIT_OPTR(unit); switch (optr) { case OP_TYPE_GREATER_THAN: @@ -1774,7 +1774,7 @@ int32_t fltInitValFieldData(SFilterInfo *info) { assert(unit->compare.optr == FILTER_DUMMY_EMPTY_OPTR || scalarGetOperatorParamNum(unit->compare.optr) == 1); continue; } - + SFilterField* right = FILTER_UNIT_RIGHT_FIELD(info, unit); assert(FILTER_GET_FLAG(right->flag, FLD_TYPE_VALUE)); @@ -1782,7 +1782,7 @@ int32_t fltInitValFieldData(SFilterInfo *info) { uint32_t type = FILTER_UNIT_DATA_TYPE(unit); int8_t precision = FILTER_UNIT_DATA_PRECISION(unit); SFilterField* fi = right; - + SValueNode* var = (SValueNode *)fi->desc; if (var == NULL) { assert(fi->data != NULL); @@ -1797,7 +1797,7 @@ int32_t fltInitValFieldData(SFilterInfo *info) { } FILTER_SET_FLAG(fi->flag, FLD_DATA_IS_HASH); - + continue; } @@ -1950,11 +1950,11 @@ int32_t filterAddUnitRange(SFilterInfo *info, SFilterUnit* u, SFilterRangeCtx *c assert(type == TSDB_DATA_TYPE_BOOL); if (GET_INT8_VAL(val)) { SIMPLE_COPY_VALUES(&ra.s, &tmp); - SIMPLE_COPY_VALUES(&ra.e, &tmp); + SIMPLE_COPY_VALUES(&ra.e, &tmp); } else { *(bool *)&tmp = true; SIMPLE_COPY_VALUES(&ra.s, &tmp); - SIMPLE_COPY_VALUES(&ra.e, &tmp); + SIMPLE_COPY_VALUES(&ra.e, &tmp); } break; case OP_TYPE_EQUAL: @@ -1964,7 +1964,7 @@ int32_t filterAddUnitRange(SFilterInfo *info, SFilterUnit* u, SFilterRangeCtx *c default: assert(0); } - + filterAddRange(ctx, &ra, optr); return TSDB_CODE_SUCCESS; @@ -1978,13 +1978,13 @@ int32_t filterCompareRangeCtx(SFilterRangeCtx *ctx1, SFilterRangeCtx *ctx2, bool SFilterRangeNode *r1 = ctx1->rs; SFilterRangeNode *r2 = ctx2->rs; - + while (r1 && r2) { FLT_CHK_JMP(r1->ra.sflag != r2->ra.sflag); FLT_CHK_JMP(r1->ra.eflag != r2->ra.eflag); FLT_CHK_JMP(r1->ra.s != r2->ra.s); FLT_CHK_JMP(r1->ra.e != r2->ra.e); - + r1 = r1->next; r2 = r2->next; } @@ -2006,7 +2006,7 @@ int32_t filterMergeUnits(SFilterInfo *info, SFilterGroupCtx* gRes, uint32_t colI int32_t size = (int32_t)taosArrayGetSize(colArray); int32_t type = gRes->colInfo[colIdx].dataType; SFilterRangeCtx* ctx = filterInitRangeCtx(type, 0); - + for (uint32_t i = 0; i < size; ++i) { SFilterUnit* u = taosArrayGetP(colArray, i); uint8_t optr = FILTER_UNIT_OPTR(u); @@ -2045,7 +2045,7 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t uint32_t *colIdx = taosMemoryMalloc(info->fields[FLD_TYPE_COLUMN].num * sizeof(uint32_t)); uint32_t colIdxi = 0; uint32_t gResIdx = 0; - + for (uint32_t i = 0; i < info->groupNum; ++i) { SFilterGroup* g = info->groups + i; @@ -2053,7 +2053,7 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gRes[gResIdx]->colInfo = taosMemoryCalloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(SFilterColInfo)); colIdxi = 0; empty = false; - + for (uint32_t j = 0; j < g->unitNum; ++j) { SFilterUnit* u = FILTER_GROUP_UNIT(info, g, j); uint32_t cidx = FILTER_UNIT_COL_IDX(u); @@ -2067,7 +2067,7 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t FILTER_SET_FLAG(info->status, FI_STATUS_REWRITE); } } - + FILTER_PUSH_UNIT(gRes[gResIdx]->colInfo[cidx], u); } @@ -2093,10 +2093,10 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t FILTER_SET_FLAG(info->status, FI_STATUS_REWRITE); filterFreeGroupCtx(gRes[gResIdx]); gRes[gResIdx] = NULL; - + continue; } - + gRes[gResIdx]->colNum = colIdxi; FILTER_COPY_IDX(&gRes[gResIdx]->colIdx, colIdx, colIdxi); ++gResIdx; @@ -2105,7 +2105,7 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t taosMemoryFreeClear(colIdx); *gResNum = gResIdx; - + if (gResIdx == 0) { FILTER_SET_FLAG(info->status, FI_STATUS_EMPTY); } @@ -2116,12 +2116,12 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t void filterCheckColConflict(SFilterGroupCtx* gRes1, SFilterGroupCtx* gRes2, bool *conflict) { uint32_t idx1 = 0, idx2 = 0, m = 0, n = 0; bool equal = false; - + for (; m < gRes1->colNum; ++m) { idx1 = gRes1->colIdx[m]; equal = false; - + for (; n < gRes2->colNum; ++n) { idx2 = gRes2->colIdx[n]; if (idx1 < idx2) { @@ -2146,7 +2146,7 @@ void filterCheckColConflict(SFilterGroupCtx* gRes1, SFilterGroupCtx* gRes2, bool return; } } - + ++n; equal = true; break; @@ -2185,7 +2185,7 @@ int32_t filterMergeTwoGroupsImpl(SFilterInfo *info, SFilterRangeCtx **ctx, int32 int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx** gRes1, SFilterGroupCtx** gRes2, bool *all) { bool conflict = false; - + filterCheckColConflict(*gRes1, *gRes2, &conflict); if (conflict) { return TSDB_CODE_SUCCESS; @@ -2203,7 +2203,7 @@ int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx** gRes1, SFilter for (; m < (*gRes1)->colNum; ++m) { idx1 = (*gRes1)->colIdx[m]; - + for (; n < (*gRes2)->colNum; ++n) { idx2 = (*gRes2)->colIdx[n]; @@ -2212,9 +2212,9 @@ int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx** gRes1, SFilter } assert(idx1 == idx2); - + ++merNum; - + filterMergeTwoGroupsImpl(info, &ctx, LOGIC_COND_TYPE_OR, idx1, *gRes1, *gRes2, NULL, all); FLT_CHK_JMP(*all); @@ -2231,7 +2231,7 @@ int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx** gRes1, SFilter if (equal) { ++equal1; } - + filterCompareRangeCtx(ctx, (*gRes2)->colInfo[idx2].info, &equal); if (equal) { ++equal2; @@ -2251,7 +2251,7 @@ int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx** gRes1, SFilter FLT_CHK_JMP(equal1 != merNum); colCtx.colIdx = idx1; - colCtx.ctx = ctx; + colCtx.ctx = ctx; ctx = NULL; taosArrayPush(colCtxs, &colCtx); } @@ -2273,17 +2273,17 @@ int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx** gRes1, SFilter int32_t ctxSize = (int32_t)taosArrayGetSize(colCtxs); SFilterColCtx *pctx = NULL; - + for (int32_t i = 0; i < ctxSize; ++i) { pctx = taosArrayGet(colCtxs, i); colInfo = &(*gRes1)->colInfo[pctx->colIdx]; - + filterFreeColInfo(colInfo); FILTER_PUSH_CTX((*gRes1)->colInfo[pctx->colIdx], pctx->ctx); } taosArrayDestroy(colCtxs); - + return TSDB_CODE_SUCCESS; _return: @@ -2310,7 +2310,7 @@ int32_t filterMergeGroups(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t *gR taosSort(gRes, *gResNum, POINTER_BYTES, filterCompareGroupCtx); int32_t pEnd = 0, cStart = 0, cEnd = 0; - uint32_t pColNum = 0, cColNum = 0; + uint32_t pColNum = 0, cColNum = 0; int32_t movedNum = 0; bool all = false; @@ -2336,7 +2336,7 @@ int32_t filterMergeGroups(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t *gR if (n < ((*gResNum) - 1)) { memmove(&gRes[n], &gRes[n+1], (*gResNum-n-1) * POINTER_BYTES); } - + --cEnd; --(*gResNum); ++movedNum; @@ -2352,12 +2352,12 @@ int32_t filterMergeGroups(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t *gR filterMergeTwoGroups(info, &gRes[m], &gRes[n], &all); FLT_CHK_JMP(all); - + if (gRes[n] == NULL) { if (n < ((*gResNum) - 1)) { memmove(&gRes[n], &gRes[n+1], (*gResNum-n-1) * POINTER_BYTES); } - + --cEnd; --(*gResNum); ++movedNum; @@ -2374,13 +2374,13 @@ int32_t filterMergeGroups(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t *gR if (i >= (*gResNum)) { break; } - + cStart = i; - cColNum = gRes[i]->colNum; + cColNum = gRes[i]->colNum; } return TSDB_CODE_SUCCESS; - + _return: FILTER_SET_FLAG(info->status, FI_STATUS_ALL); @@ -2411,11 +2411,11 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum qDebug("no need rewrite"); return TSDB_CODE_SUCCESS; } - + SFilterInfo oinfo = *info; FILTER_SET_FLAG(oinfo.status, FI_STATUS_CLONED); - + SArray* group = taosArrayInit(FILTER_DEFAULT_GROUP_SIZE, sizeof(SFilterGroup)); SFilterGroupCtx *res = NULL; SFilterColInfo *colInfo = NULL; @@ -2423,7 +2423,7 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum uint32_t uidx = 0; memset(info, 0, sizeof(*info)); - + info->colRangeNum = oinfo.colRangeNum; info->colRange = oinfo.colRange; oinfo.colRangeNum = 0; @@ -2439,25 +2439,25 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum optr = (res->colNum > 1) ? LOGIC_COND_TYPE_AND : LOGIC_COND_TYPE_OR; SFilterGroup ng = {0}; - + for (uint32_t m = 0; m < res->colNum; ++m) { colInfo = &res->colInfo[res->colIdx[m]]; if (FILTER_NO_MERGE_DATA_TYPE(colInfo->dataType)) { assert(colInfo->type == RANGE_TYPE_UNIT); int32_t usize = (int32_t)taosArrayGetSize((SArray *)colInfo->info); - + for (int32_t n = 0; n < usize; ++n) { SFilterUnit* u = taosArrayGetP((SArray *)colInfo->info, n); - + filterAddUnitFromUnit(info, &oinfo, u, &uidx); filterAddUnitToGroup(&ng, uidx); } - + continue; } - + assert(colInfo->type == RANGE_TYPE_MR_CTX); - + filterAddGroupUnitFromCtx(info, &oinfo, colInfo->info, res->colIdx[m], &ng, optr, group); } @@ -2498,7 +2498,7 @@ int32_t filterGenerateColRange(SFilterInfo *info, SFilterGroupCtx** gRes, int32_ } assert(idxNum[i] == gResNum); - + if (idxs == NULL) { idxs = taosMemoryCalloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(*idxs)); } @@ -2537,7 +2537,7 @@ int32_t filterGenerateColRange(SFilterInfo *info, SFilterGroupCtx** gRes, int32_ if (all) { filterFreeRangeCtx(info->colRange[m]); info->colRange[m] = NULL; - + if (m < (info->colRangeNum - 1)) { memmove(&info->colRange[m], &info->colRange[m + 1], (info->colRangeNum - m - 1) * POINTER_BYTES); memmove(&idxs[m], &idxs[m + 1], (info->colRangeNum - m - 1) * sizeof(*idxs)); @@ -2546,10 +2546,10 @@ int32_t filterGenerateColRange(SFilterInfo *info, SFilterGroupCtx** gRes, int32_ --info->colRangeNum; --m; - FLT_CHK_JMP(info->colRangeNum <= 0); + FLT_CHK_JMP(info->colRangeNum <= 0); } - ++n; + ++n; break; } } @@ -2589,7 +2589,7 @@ int32_t filterGenerateComInfo(SFilterInfo *info) { info->cunits[i].optr = FILTER_UNIT_OPTR(unit); info->cunits[i].colData = NULL; info->cunits[i].colId = FILTER_UNIT_COL_ID(info, unit); - + if (unit->right.type == FLD_TYPE_VALUE) { info->cunits[i].valData = FILTER_UNIT_VAL_DATA(info, unit); } else { @@ -2600,11 +2600,11 @@ int32_t filterGenerateComInfo(SFilterInfo *info) { } else { info->cunits[i].valData2 = info->cunits[i].valData; } - + info->cunits[i].dataSize = FILTER_UNIT_COL_SIZE(info, unit); info->cunits[i].dataType = FILTER_UNIT_DATA_TYPE(unit); } - + return TSDB_CODE_SUCCESS; } @@ -2624,7 +2624,7 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3 int32_t rmUnit = 0; memset(info->blkUnitRes, 0, sizeof(*info->blkUnitRes) * info->unitNum); - + for (uint32_t k = 0; k < info->unitNum; ++k) { int32_t index = -1; SFilterComUnit *cunit = &info->cunits[k]; @@ -2663,7 +2663,7 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3 rmUnit = 1; continue; } - + info->blkUnitRes[k] = -1; rmUnit = 1; continue; @@ -2684,7 +2684,7 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3 if (cunit->dataType == TSDB_DATA_TYPE_FLOAT) { minv = (float)(*(double *)(&pDataBlockst->min)); maxv = (float)(*(double *)(&pDataBlockst->max)); - + minVal = &minv; maxVal = &maxv; } else { @@ -2708,7 +2708,7 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3 if (minRes && maxRes) { continue; } - + info->blkUnitRes[k] = -1; rmUnit = 1; } @@ -2727,10 +2727,10 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3 info->blkUnitRes[k] = -1; rmUnit = 1; } - + continue; } - + info->blkUnitRes[k] = -1; rmUnit = 1; } @@ -2744,17 +2744,17 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3 } info->blkGroupNum = info->groupNum; - + uint32_t *unitNum = info->blkUnits; uint32_t *unitIdx = unitNum + 1; int32_t all = 0, empty = 0; - + for (uint32_t g = 0; g < info->groupNum; ++g) { SFilterGroup *group = &info->groups[g]; *unitNum = group->unitNum; - all = 0; + all = 0; empty = 0; - + for (uint32_t u = 0; u < group->unitNum; ++u) { uint32_t uidx = group->unitIdxs[u]; if (info->blkUnitRes[uidx] == 1) { @@ -2773,14 +2773,14 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SColumnDataAgg *pDataStatis, int3 if (*unitNum == 0) { --info->blkGroupNum; assert(empty || all); - + if (empty) { FILTER_SET_FLAG(info->blkFlag, FI_STATUS_BLK_EMPTY); } else { FILTER_SET_FLAG(info->blkFlag, FI_STATUS_BLK_ALL); goto _return; } - + continue; } @@ -2808,18 +2808,18 @@ bool filterExecuteBasedOnStatisImpl(void *pinfo, int32_t numOfRows, int8_t** p, if (*p == NULL) { *p = taosMemoryCalloc(numOfRows, sizeof(int8_t)); } - + for (int32_t i = 0; i < numOfRows; ++i) { //FILTER_UNIT_CLR_F(info); unitIdx = info->blkUnits; - + for (uint32_t g = 0; g < info->blkGroupNum; ++g) { uint32_t unitNum = *(unitIdx++); for (uint32_t u = 0; u < unitNum; ++u) { SFilterComUnit *cunit = &info->cunits[*(unitIdx + u)]; void *colData = colDataGetData((SColumnInfoData *)cunit->colData, i); - + //if (FILTER_UNIT_GET_F(info, uidx)) { // p[i] = FILTER_UNIT_GET_R(info, uidx); //} else { @@ -2837,7 +2837,7 @@ bool filterExecuteBasedOnStatisImpl(void *pinfo, int32_t numOfRows, int8_t** p, } else { (*p)[i] = filterDoCompare(gDataCompare[cunit->func], cunit->optr, colData, cunit->valData); } - + //FILTER_UNIT_SET_R(info, uidx, p[i]); //FILTER_UNIT_SET_F(info, uidx); } @@ -2856,7 +2856,7 @@ bool filterExecuteBasedOnStatisImpl(void *pinfo, int32_t numOfRows, int8_t** p, if ((*p)[i] == 0) { all = false; - } + } } return all; @@ -2865,11 +2865,11 @@ bool filterExecuteBasedOnStatisImpl(void *pinfo, int32_t numOfRows, int8_t** p, int32_t filterExecuteBasedOnStatis(SFilterInfo *info, int32_t numOfRows, int8_t** p, SColumnDataAgg *statis, int16_t numOfCols, bool* all) { - if (statis && numOfRows >= FILTER_RM_UNIT_MIN_ROWS) { + if (statis && numOfRows >= FILTER_RM_UNIT_MIN_ROWS) { info->blkFlag = 0; - + filterRmUnitByRange(info, statis, numOfCols, numOfRows); - + if (info->blkFlag) { if (FILTER_GET_FLAG(info->blkFlag, FI_STATUS_BLK_ALL)) { *all = true; @@ -2880,7 +2880,7 @@ int32_t filterExecuteBasedOnStatis(SFilterInfo *info, int32_t numOfRows, int8_t* } assert(info->unitNum > 1); - + *all = filterExecuteBasedOnStatisImpl(info, numOfRows, p, statis, numOfCols); goto _return; @@ -2891,7 +2891,7 @@ int32_t filterExecuteBasedOnStatis(SFilterInfo *info, int32_t numOfRows, int8_t* _return: info->blkFlag = 0; - + return TSDB_CODE_SUCCESS; } @@ -2913,7 +2913,7 @@ static FORCE_INLINE bool filterExecuteImplIsNull(void *pinfo, int32_t numOfRows, if (*p == NULL) { *p = taosMemoryCalloc(numOfRows, sizeof(int8_t)); } - + for (int32_t i = 0; i < numOfRows; ++i) { uint32_t uidx = info->groups[0].unitIdxs[0]; void *colData = colDataGetData((SColumnInfoData *)info->cunits[uidx].colData, i); @@ -2921,7 +2921,7 @@ static FORCE_INLINE bool filterExecuteImplIsNull(void *pinfo, int32_t numOfRows, if ((*p)[i] == 0) { all = false; - } + } } return all; @@ -2937,7 +2937,7 @@ static FORCE_INLINE bool filterExecuteImplNotNull(void *pinfo, int32_t numOfRows if (*p == NULL) { *p = taosMemoryCalloc(numOfRows, sizeof(int8_t)); } - + for (int32_t i = 0; i < numOfRows; ++i) { uint32_t uidx = info->groups[0].unitIdxs[0]; void *colData = colDataGetData((SColumnInfoData *)info->cunits[uidx].colData, i); @@ -2967,8 +2967,8 @@ bool filterExecuteImplRange(void *pinfo, int32_t numOfRows, int8_t** p, SColumnD if (*p == NULL) { *p = taosMemoryCalloc(numOfRows, sizeof(int8_t)); } - - for (int32_t i = 0; i < numOfRows; ++i) { + + for (int32_t i = 0; i < numOfRows; ++i) { void *colData = colDataGetData((SColumnInfoData *)info->cunits[0].colData, i); SColumnInfoData* pData = info->cunits[0].colData; if (colData == NULL || colDataIsNull_s(pData, i)) { @@ -2977,7 +2977,7 @@ bool filterExecuteImplRange(void *pinfo, int32_t numOfRows, int8_t** p, SColumnD } (*p)[i] = (*rfunc)(colData, colData, valData, valData2, func); - + if ((*p)[i] == 0) { all = false; } @@ -2993,11 +2993,11 @@ bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, int8_t** p, SColumnDa if (filterExecuteBasedOnStatis(info, numOfRows, p, statis, numOfCols, &all) == 0) { return all; } - + if (*p == NULL) { *p = taosMemoryCalloc(numOfRows, sizeof(int8_t)); } - + for (int32_t i = 0; i < numOfRows; ++i) { uint32_t uidx = info->groups[0].unitIdxs[0]; void *colData = colDataGetData((SColumnInfoData *)info->cunits[uidx].colData, i); @@ -3042,17 +3042,17 @@ bool filterExecuteImpl(void *pinfo, int32_t numOfRows, int8_t** p, SColumnDataAg if (*p == NULL) { *p = taosMemoryCalloc(numOfRows, sizeof(int8_t)); } - + for (int32_t i = 0; i < numOfRows; ++i) { //FILTER_UNIT_CLR_F(info); - + for (uint32_t g = 0; g < info->groupNum; ++g) { SFilterGroup *group = &info->groups[g]; for (uint32_t u = 0; u < group->unitNum; ++u) { uint32_t uidx = group->unitIdxs[u]; SFilterComUnit *cunit = &info->cunits[uidx]; void *colData = colDataGetData((SColumnInfoData *)(cunit->colData), i); - + //if (FILTER_UNIT_GET_F(info, uidx)) { // p[i] = FILTER_UNIT_GET_R(info, uidx); //} else { @@ -3082,7 +3082,7 @@ bool filterExecuteImpl(void *pinfo, int32_t numOfRows, int8_t** p, SColumnDataAg (*p)[i] = filterDoCompare(gDataCompare[cunit->func], cunit->optr, colData, cunit->valData); } } - + //FILTER_UNIT_SET_R(info, uidx, p[i]); //FILTER_UNIT_SET_F(info, uidx); } @@ -3099,7 +3099,7 @@ bool filterExecuteImpl(void *pinfo, int32_t numOfRows, int8_t** p, SColumnDataAg if ((*p)[i] == 0) { all = false; - } + } } return all; @@ -3133,11 +3133,11 @@ int32_t filterSetExecFunc(SFilterInfo *info) { if (info->cunits[0].rfunc >= 0) { info->func = filterExecuteImplRange; - return TSDB_CODE_SUCCESS; + return TSDB_CODE_SUCCESS; } info->func = filterExecuteImplMisc; - return TSDB_CODE_SUCCESS; + return TSDB_CODE_SUCCESS; } @@ -3145,7 +3145,7 @@ int32_t filterSetExecFunc(SFilterInfo *info) { int32_t filterPreprocess(SFilterInfo *info) { SFilterGroupCtx** gRes = taosMemoryCalloc(info->groupNum, sizeof(SFilterGroupCtx *)); int32_t gResNum = 0; - + filterMergeGroupUnits(info, gRes, &gResNum); filterMergeGroups(info, gRes, &gResNum); @@ -3155,11 +3155,11 @@ int32_t filterPreprocess(SFilterInfo *info) { goto _return; } - + if (FILTER_GET_FLAG(info->status, FI_STATUS_EMPTY)) { fltInfo("Final - FilterInfo: [EMPTY]"); goto _return; - } + } filterGenerateColRange(info, gRes, gResNum); @@ -3180,7 +3180,7 @@ _return: } taosMemoryFreeClear(gRes); - + return TSDB_CODE_SUCCESS; } @@ -3208,7 +3208,7 @@ int32_t fltSetColFieldDataImpl(SFilterInfo *info, void *param, filer_get_col_fro int32_t fltInitFromNode(SNode* tree, SFilterInfo *info, uint32_t options) { int32_t code = TSDB_CODE_SUCCESS; - + SArray* group = taosArrayInit(FILTER_DEFAULT_GROUP_SIZE, sizeof(SFilterGroup)); filterInitUnitsFields(info); @@ -3226,13 +3226,13 @@ int32_t fltInitFromNode(SNode* tree, SFilterInfo *info, uint32_t options) { filterDumpInfoToString(info, "Before preprocess", 0); FLT_ERR_JRET(filterPreprocess(info)); - + FLT_CHK_JMP(FILTER_GET_FLAG(info->status, FI_STATUS_ALL)); if (FILTER_GET_FLAG(info->status, FI_STATUS_EMPTY)) { return code; } - } + } info->unitRes = taosMemoryMalloc(info->unitNum * sizeof(*info->unitRes)); info->unitFlags = taosMemoryMalloc(info->unitNum * sizeof(*info->unitFlags)); @@ -3253,10 +3253,10 @@ bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg *pDataStatis, int32_t if (FILTER_ALL_RES(info)) { return true; } - + bool ret = true; void *minVal, *maxVal; - + for (uint32_t k = 0; k < info->colRangeNum; ++k) { int32_t index = -1; SFilterRangeCtx *ctx = info->colRange[k]; @@ -3306,7 +3306,7 @@ bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg *pDataStatis, int32_t if (ctx->type == TSDB_DATA_TYPE_FLOAT) { minv = (float)(*(double *)(&pDataBlockst->min)); maxv = (float)(*(double *)(&pDataBlockst->max)); - + minVal = &minv; maxVal = &maxv; } else { @@ -3321,7 +3321,7 @@ bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg *pDataStatis, int32_t } r = r->next; } - + if (!ret) { return ret; } @@ -3357,10 +3357,10 @@ int32_t filterGetTimeRangeImpl(SFilterInfo *info, STimeWindow *win, bool * SFilterUnit *unit = &info->units[uidx]; uint8_t raOptr = FILTER_UNIT_OPTR(unit); - + filterAddRangeOptr(cur, raOptr, LOGIC_COND_TYPE_AND, &empty, NULL); FLT_CHK_JMP(empty); - + if (FILTER_NO_MERGE_OPTR(raOptr)) { continue; } @@ -3393,10 +3393,10 @@ int32_t filterGetTimeRangeImpl(SFilterInfo *info, STimeWindow *win, bool * *isStrict = false; qDebug("more than one time range, num:%d", num); } - + SFilterRange tra; filterGetRangeRes(prev, &tra); - win->skey = tra.s; + win->skey = tra.s; win->ekey = tra.e; if (FILTER_GET_FLAG(tra.sflag, RANGE_FLG_EXCLUDE)) { win->skey++; @@ -3428,7 +3428,7 @@ _return: int32_t filterGetTimeRange(SNode *pNode, STimeWindow *win, bool *isStrict) { SFilterInfo *info = NULL; int32_t code = 0; - + *isStrict = true; FLT_ERR_RET(filterInitFromNode(pNode, &info, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP)); @@ -3453,7 +3453,7 @@ int32_t filterConverNcharColumns(SFilterInfo* info, int32_t rows, bool *gotNchar if (FILTER_EMPTY_RES(info) || FILTER_ALL_RES(info)) { return TSDB_CODE_SUCCESS; } - + for (uint32_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { SFilterField* fi = &info->fields[FLD_TYPE_COLUMN].fields[i]; int32_t type = FILTER_GET_COL_FIELD_TYPE(fi); @@ -3485,7 +3485,7 @@ int32_t filterConverNcharColumns(SFilterInfo* info, int32_t rows, bool *gotNchar } fi->data = nfi.data; - + *gotNchar = true; } } @@ -3536,11 +3536,11 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { stat->code = TSDB_CODE_QRY_INVALID_INPUT; return DEAL_RES_ERROR; } - + if ((QUERY_NODE_OPERATOR != nodeType(cell->pNode)) && (QUERY_NODE_LOGIC_CONDITION != nodeType(cell->pNode))) { stat->scalarMode = true; } - + cell = cell->pNext; } @@ -3553,11 +3553,11 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { stat->scalarMode = true; return DEAL_RES_CONTINUE; } - + if (!FILTER_GET_FLAG(stat->info->options, FLT_OPTION_TIMESTAMP)) { return DEAL_RES_CONTINUE; } - + if (TSDB_DATA_TYPE_BINARY != valueNode->node.resType.type && TSDB_DATA_TYPE_NCHAR != valueNode->node.resType.type) { return DEAL_RES_CONTINUE; } @@ -3568,7 +3568,7 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { stat->code = code; return DEAL_RES_ERROR; } - + return DEAL_RES_CONTINUE; } @@ -3586,7 +3586,7 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { stat->precision = colNode->node.resType.precision; return DEAL_RES_CONTINUE; } - + if (QUERY_NODE_NODE_LIST == nodeType(*pNode)) { SNodeListNode *listNode = (SNodeListNode *)*pNode; if (QUERY_NODE_VALUE != nodeType(listNode->pNodeList->pHead->pNode)) { @@ -3624,7 +3624,7 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { return DEAL_RES_CONTINUE; } - if (FILTER_GET_FLAG(stat->info->options, FLT_OPTION_TIMESTAMP) && + if (FILTER_GET_FLAG(stat->info->options, FLT_OPTION_TIMESTAMP) && (node->opType >= OP_TYPE_NOT_EQUAL) && (node->opType != OP_TYPE_IS_NULL && node->opType != OP_TYPE_IS_NOT_NULL)) { stat->scalarMode = true; return DEAL_RES_CONTINUE; @@ -3636,7 +3636,7 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { stat->code = TSDB_CODE_QRY_APP_ERROR; return DEAL_RES_ERROR; } - + if (QUERY_NODE_COLUMN != nodeType(node->pLeft)) { stat->scalarMode = true; return DEAL_RES_CONTINUE; @@ -3656,7 +3656,7 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { if ((QUERY_NODE_COLUMN != nodeType(node->pRight)) && (QUERY_NODE_VALUE != nodeType(node->pRight)) && (QUERY_NODE_NODE_LIST != nodeType(node->pRight))) { stat->scalarMode = true; return DEAL_RES_CONTINUE; - } + } if (nodeType(node->pLeft) == nodeType(node->pRight)) { stat->scalarMode = true; @@ -3699,7 +3699,7 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { if (OP_TYPE_IN != node->opType) { SColumnNode *refNode = (SColumnNode *)node->pLeft; SValueNode *valueNode = (SValueNode *)node->pRight; - if (FILTER_GET_FLAG(stat->info->options, FLT_OPTION_TIMESTAMP) + if (FILTER_GET_FLAG(stat->info->options, FLT_OPTION_TIMESTAMP) && TSDB_DATA_TYPE_UBIGINT == valueNode->node.resType.type && valueNode->datum.u <= INT64_MAX) { valueNode->node.resType.type = TSDB_DATA_TYPE_BIGINT; } @@ -3720,12 +3720,12 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { } return DEAL_RES_CONTINUE; - } - + } + fltError("invalid node type for filter, type:%d", nodeType(*pNode)); - + stat->code = TSDB_CODE_QRY_INVALID_INPUT; - + return DEAL_RES_ERROR; } @@ -3738,7 +3738,7 @@ int32_t fltReviseNodes(SFilterInfo *pInfo, SNode** pNode, SFltTreeStat *pStat) { int32_t nodeNum = taosArrayGetSize(pStat->nodeList); for (int32_t i = 0; i < nodeNum; ++i) { SValueNode *valueNode = *(SValueNode **)taosArrayGet(pStat->nodeList, i); - + FLT_ERR_JRET(sclConvertToTsValueNode(pStat->precision, valueNode)); } @@ -3757,7 +3757,7 @@ int32_t fltOptimizeNodes(SFilterInfo *pInfo, SNode** pNode, SFltTreeStat *pStat) int32_t fltGetDataFromColId(void *param, int32_t id, void **data) { int32_t numOfCols = ((SFilterColumnParam *)param)->numOfCols; SArray* pDataBlock = ((SFilterColumnParam *)param)->pDataBlock; - + for (int32_t j = 0; j < numOfCols; ++j) { SColumnInfoData* pColInfo = taosArrayGet(pDataBlock, j); if (id == pColInfo->info.colId) { @@ -3776,7 +3776,7 @@ int32_t fltGetDataFromSlotId(void *param, int32_t id, void **data) { fltError("invalid slot id, id:%d, numOfCols:%d, arraySize:%d", id, numOfCols, (int32_t)taosArrayGetSize(pDataBlock)); return TSDB_CODE_QRY_APP_ERROR; } - + SColumnInfoData* pColInfo = taosArrayGet(pDataBlock, id); *data = pColInfo; @@ -3802,7 +3802,7 @@ int32_t filterSetDataFromColId(SFilterInfo *info, void *param) { int32_t filterInitFromNode(SNode* pNode, SFilterInfo **pInfo, uint32_t options) { int32_t code = 0; SFilterInfo *info = NULL; - + if (pNode == NULL || pInfo == NULL) { fltError("invalid param"); FLT_ERR_RET(TSDB_CODE_QRY_APP_ERROR); @@ -3822,7 +3822,7 @@ int32_t filterInitFromNode(SNode* pNode, SFilterInfo **pInfo, uint32_t options) SFltTreeStat stat = {0}; stat.precision = -1; stat.info = info; - + FLT_ERR_JRET(fltReviseNodes(info, &pNode, &stat)); info->scalarMode = stat.scalarMode; @@ -3834,11 +3834,11 @@ int32_t filterInitFromNode(SNode* pNode, SFilterInfo **pInfo, uint32_t options) info->sclCtx.node = pNode; FLT_ERR_JRET(fltOptimizeNodes(info, &info->sclCtx.node, &stat)); } - + return code; _return: - + filterFreeInfo(*pInfo); *pInfo = NULL; @@ -3929,6 +3929,26 @@ static EConditionType classifyCondition(SNode* pNode) { : (cxt.hasTagIndexCol ? COND_TYPE_TAG_INDEX : COND_TYPE_TAG))); } +static bool isCondColumnsFromMultiTable(SNode* pCond) { + SNodeList* pCondCols = nodesMakeList(); + int32_t code = nodesCollectColumnsFromNode(pCond, NULL, COLLECT_COL_TYPE_ALL, &pCondCols); + if (code == TSDB_CODE_SUCCESS) { + if (LIST_LENGTH(pCondCols) >= 2) { + SColumnNode* pFirstCol = (SColumnNode*)nodesListGetNode(pCondCols, 0); + SNode* pColNode = NULL; + FOREACH(pColNode, pCondCols) { + if (strcmp(((SColumnNode*)pColNode)->dbName, pFirstCol->dbName) != 0 || + strcmp(((SColumnNode*)pColNode)->tableAlias, pFirstCol->tableAlias) != 0) { + nodesDestroyList(pCondCols); + return true; + } + } + } + nodesDestroyList(pCondCols); + } + return false; +} + static int32_t partitionLogicCond(SNode** pCondition, SNode** pPrimaryKeyCond, SNode** pTagIndexCond, SNode** pTagCond, SNode** pOtherCond) { SLogicConditionNode* pLogicCond = (SLogicConditionNode*)(*pCondition); @@ -3941,31 +3961,37 @@ static int32_t partitionLogicCond(SNode** pCondition, SNode** pPrimaryKeyCond, S SNodeList* pOtherConds = NULL; SNode* pCond = NULL; FOREACH(pCond, pLogicCond->pParameterList) { - switch (classifyCondition(pCond)) { - case COND_TYPE_PRIMARY_KEY: - if (NULL != pPrimaryKeyCond) { - code = nodesListMakeAppend(&pPrimaryKeyConds, nodesCloneNode(pCond)); - } - break; - case COND_TYPE_TAG_INDEX: - if (NULL != pTagIndexCond) { - code = nodesListMakeAppend(&pTagIndexConds, nodesCloneNode(pCond)); - } - if (NULL != pTagCond) { - code = nodesListMakeAppend(&pTagConds, nodesCloneNode(pCond)); - } - break; - case COND_TYPE_TAG: - if (NULL != pTagCond) { - code = nodesListMakeAppend(&pTagConds, nodesCloneNode(pCond)); - } - break; - case COND_TYPE_NORMAL: - default: - if (NULL != pOtherCond) { - code = nodesListMakeAppend(&pOtherConds, nodesCloneNode(pCond)); - } - break; + if (isCondColumnsFromMultiTable(pCond)) { + if (NULL != pOtherCond) { + code = nodesListMakeAppend(&pOtherConds, nodesCloneNode(pCond)); + } + } else { + switch (classifyCondition(pCond)) { + case COND_TYPE_PRIMARY_KEY: + if (NULL != pPrimaryKeyCond) { + code = nodesListMakeAppend(&pPrimaryKeyConds, nodesCloneNode(pCond)); + } + break; + case COND_TYPE_TAG_INDEX: + if (NULL != pTagIndexCond) { + code = nodesListMakeAppend(&pTagIndexConds, nodesCloneNode(pCond)); + } + if (NULL != pTagCond) { + code = nodesListMakeAppend(&pTagConds, nodesCloneNode(pCond)); + } + break; + case COND_TYPE_TAG: + if (NULL != pTagCond) { + code = nodesListMakeAppend(&pTagConds, nodesCloneNode(pCond)); + } + break; + case COND_TYPE_NORMAL: + default: + if (NULL != pOtherCond) { + code = nodesListMakeAppend(&pOtherConds, nodesCloneNode(pCond)); + } + break; + } } if (TSDB_CODE_SUCCESS != code) { break; @@ -4026,43 +4052,50 @@ int32_t filterPartitionCond(SNode** pCondition, SNode** pPrimaryKeyCond, SNode** } bool needOutput = false; - switch (classifyCondition(*pCondition)) { - case COND_TYPE_PRIMARY_KEY: - if (NULL != pPrimaryKeyCond) { - *pPrimaryKeyCond = *pCondition; - needOutput = true; - } - break; - case COND_TYPE_TAG_INDEX: - if (NULL != pTagIndexCond) { - *pTagIndexCond = *pCondition; - needOutput = true; - } - if (NULL != pTagCond) { - SNode* pTempCond = *pCondition; - if (NULL != pTagIndexCond) { - pTempCond = nodesCloneNode(*pCondition); - if (NULL == pTempCond) { - return TSDB_CODE_OUT_OF_MEMORY; - } + if (isCondColumnsFromMultiTable(*pCondition)) { + if (NULL != pOtherCond) { + *pOtherCond = *pCondition; + needOutput = true; + } + } else { + switch (classifyCondition(*pCondition)) { + case COND_TYPE_PRIMARY_KEY: + if (NULL != pPrimaryKeyCond) { + *pPrimaryKeyCond = *pCondition; + needOutput = true; } - *pTagCond = pTempCond; - needOutput = true; - } - break; - case COND_TYPE_TAG: - if (NULL != pTagCond) { - *pTagCond = *pCondition; - needOutput = true; - } - break; - case COND_TYPE_NORMAL: - default: - if (NULL != pOtherCond) { - *pOtherCond = *pCondition; - needOutput = true; - } - break; + break; + case COND_TYPE_TAG_INDEX: + if (NULL != pTagIndexCond) { + *pTagIndexCond = *pCondition; + needOutput = true; + } + if (NULL != pTagCond) { + SNode *pTempCond = *pCondition; + if (NULL != pTagIndexCond) { + pTempCond = nodesCloneNode(*pCondition); + if (NULL == pTempCond) { + return TSDB_CODE_OUT_OF_MEMORY; + } + } + *pTagCond = pTempCond; + needOutput = true; + } + break; + case COND_TYPE_TAG: + if (NULL != pTagCond) { + *pTagCond = *pCondition; + needOutput = true; + } + break; + case COND_TYPE_NORMAL: + default: + if (NULL != pOtherCond) { + *pOtherCond = *pCondition; + needOutput = true; + } + break; + } } if (needOutput) { *pCondition = NULL; diff --git a/source/util/src/terror.c b/source/util/src/terror.c index f20c5d8593..63ee8cb90a 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -560,6 +560,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_PAR_ONLY_SUPPORT_SINGLE_TABLE, "Only support single TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_SMA_INDEX, "Invalid sma index") TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_SELECTED_EXPR, "Invalid SELECTed expression") TAOS_DEFINE_ERROR(TSDB_CODE_PAR_GET_META_ERROR, "Fail to get table info") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_NOT_UNIQUE_TABLE_ALIAS, "Not unique table/alias") TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INTERNAL_ERROR, "Parser internal error") //planner diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 462cf8cfc6..6115d21173 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -133,7 +133,7 @@ ./test.sh -f tsim/parser/join_manyblocks.sim # TD-18018 ./test.sh -f tsim/parser/join_multitables.sim ./test.sh -f tsim/parser/join_multivnode.sim -# TD-17707 ./test.sh -f tsim/parser/join.sim +./test.sh -f tsim/parser/join.sim ./test.sh -f tsim/parser/last_cache.sim ./test.sh -f tsim/parser/last_groupby.sim ./test.sh -f tsim/parser/lastrow.sim diff --git a/tests/script/tsim/parser/join.sim b/tests/script/tsim/parser/join.sim index 0f41ebd178..8ad5946a54 100644 --- a/tests/script/tsim/parser/join.sim +++ b/tests/script/tsim/parser/join.sim @@ -320,7 +320,7 @@ sql_error select count(join_tb1.c3), last(join_tb1.c3) from $tb1 , $tb2 where jo sql_error select count(join_tb3.*) from $tb1 , $tb2 where join_tb1.ts = join_tb0.ts and join_tb1.ts <= 100002 and join_tb0.c7 = true; sql_error select first(join_tb1.*) from $tb1 , $tb2 where join_tb1.ts = join_tb0.ts and join_tb1.ts <= 100002 or join_tb0.c7 = true; sql_error select join_tb3.* from $tb1 , $tb2 where join_tb1.ts = join_tb0.ts and join_tb1.ts <= 100002 and join_tb0.c7 = true; -sql_error select join_tb1.* from $tb1 , $tb2 where join_tb1.ts = join_tb0.ts and join_tb1.ts = join_tb0.c1; +sql select join_tb1.* from $tb1 , $tb2 where join_tb1.ts = join_tb0.ts and join_tb1.ts = join_tb0.c1; sql_error select join_tb1.* from $tb1 , $tb2 where join_tb1.ts = join_tb0.c1; sql_error select join_tb1.* from $tb1 , $tb2 where join_tb1.c7 = join_tb0.c1; sql_error select join_tb1.* from $tb1 , $tb2 where join_tb1.ts > join_tb0.ts; @@ -407,32 +407,32 @@ if $data00 != 396.000000000 then endi # first/last -sql select count(join_mt0.c1), sum(join_mt1.c2), first(join_mt0.c5), last(join_mt1.c7) from join_mt0, join_mt1 where join_mt0.t1=join_mt1.t1 and join_mt0.ts=join_mt1.ts and join_mt0.t1=1 interval(10a) order by join_mt0.ts asc; +sql select count(join_mt0.c1), sum(join_mt1.c2), first(join_mt0.c5), last(join_mt1.c7) from join_mt0, join_mt1 where join_mt0.t1=join_mt1.t1 and join_mt0.ts=join_mt1.ts and join_mt0.t1=1 interval(10a) order by _wstart asc; $val = 100 if $rows != $val then print $rows return -1 endi - +print $data00 $data01 $data02 $val = 10 -if $data01 != $val then +if $data00 != $val then return -1 endi $val = 45.000000000 -print $data02 -if $data02 != $val then +print $data01 +if $data01 != $val then return -1 endi $val = 0 -if $data03 != 0 then +if $data02 != 0 then return -1 endi # order by first/last -sql select count(join_mt0.c1), sum(join_mt1.c2), first(join_mt0.c5), last(join_mt1.c7) from join_mt0, join_mt1 where join_mt0.t1=join_mt1.t1 and join_mt0.ts=join_mt1.ts and join_mt0.t1=1 interval(10a) order by join_mt0.ts desc; +sql select count(join_mt0.c1), sum(join_mt1.c2), first(join_mt0.c5), last(join_mt1.c7) from join_mt0, join_mt1 where join_mt0.t1=join_mt1.t1 and join_mt0.ts=join_mt1.ts and join_mt0.t1=1 interval(10a) order by _wstart desc; $val = 100 if $rows != $val then @@ -453,13 +453,13 @@ print =================>"group by not supported" #======================limit offset=================================== # tag values not int -sql_error select count(*) from join_mt0, join_mt1 where join_mt0.ts=join_mt1.ts and join_mt0.t2=join_mt1.t2; +sql select count(*) from join_mt0, join_mt1 where join_mt0.ts=join_mt1.ts and join_mt0.t2=join_mt1.t2; # tag type not identical -sql_error select count(*) from join_mt0, join_mt1 where join_mt1.t2 = join_mt0.t1 and join_mt1.ts=join_mt0.ts; +sql select count(*) from join_mt0, join_mt1 where join_mt1.t2 = join_mt0.t1 and join_mt1.ts=join_mt0.ts; # table/super table join -sql_error select count(join_mt0.c1) from join_mt0, join_tb1 where join_mt0.ts=join_tb1.ts +sql select count(join_mt0.c1) from join_mt0, join_tb1 where join_mt0.ts=join_tb1.ts # multi-condition @@ -471,7 +471,7 @@ sql_error select count(join_mt0.c1), count(join_mt0.c2) from join_mt0, join_mt0 sql_error select sum(join_mt1.c2) from join_mt0, join_mt1 where join_mt0.t1=join_mt1.t1; # missing tag equals -sql_error select count(join_mt1.c3) from join_mt0, join_mt1 where join_mt0.ts=join_mt1.ts; +sql select count(join_mt1.c3) from join_mt0, join_mt1 where join_mt0.ts=join_mt1.ts; # tag values are identical error sql create table m1(ts timestamp, k int) tags(a int); @@ -486,7 +486,7 @@ sql insert into tm2 using m1 tags(1) values(1000000, 1)(2000000, 2); sql insert into um1 using m2 tags(1) values(1000001, 10)(2000000, 20); sql insert into um2 using m2 tags(9) values(1000001, 10)(2000000, 20); -sql_error select count(*) from m1,m2 where m1.a=m2.a and m1.ts=m2.ts; +sql select count(*) from m1,m2 where m1.a=m2.a and m1.ts=m2.ts; print ====> empty table/empty super-table join test, add for no result join test sql create database ux1; From 5ad27aabe72e8cb37ffb484487249209087a2a5c Mon Sep 17 00:00:00 2001 From: slzhou Date: Mon, 1 Aug 2022 17:47:31 +0800 Subject: [PATCH 2/2] fix: fix join error to remove the extra join --- source/libs/executor/src/joinoperator.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/source/libs/executor/src/joinoperator.c b/source/libs/executor/src/joinoperator.c index 17b81cdb82..4134ce5dbf 100644 --- a/source/libs/executor/src/joinoperator.c +++ b/source/libs/executor/src/joinoperator.c @@ -323,8 +323,6 @@ static void doMergeJoinImpl(struct SOperatorInfo* pOperator, SSDataBlock* pRes) } if (leftTs == rightTs) { - mergeJoinJoinLeftRight(pOperator, pRes, nrows, pJoinInfo->pLeft, pJoinInfo->leftPos, pJoinInfo->pRight, - pJoinInfo->rightPos); mergeJoinJoinDownstreamTsRanges(pOperator, leftTs, pRes, &nrows); } else if (asc && leftTs < rightTs || !asc && leftTs > rightTs) { pJoinInfo->leftPos += 1;