diff --git a/src/query/src/qast.c b/src/query/src/qast.c index 7b97e6f9c599b0f599a9bc32577a6f5443b0dec6..903d49a0d9321a6c1042a78900f26c4c2ee8cc54 100644 --- a/src/query/src/qast.c +++ b/src/query/src/qast.c @@ -783,13 +783,17 @@ static void exprTreeTraverseImpl(tExprNode *pExpr, SArray *pResult, SBinaryFilte taosArrayCopy(pResult, array); } -static void tSQLBinaryTraverseOnSkipList(tExprNode *pExpr, SArray *pResult, SSkipList *pSkipList, - SBinaryFilterSupp *param) { + +static void tSQLBinaryTraverseOnSkipList( + tExprNode *pExpr, + SArray *pResult, + SSkipList *pSkipList, + SBinaryFilterSupp *param +) { SSkipListIterator* iter = tSkipListCreateIter(pSkipList); while (tSkipListIterNext(iter)) { SSkipListNode *pNode = tSkipListIterGet(iter); - if (filterItem(pExpr, pNode, param)) { taosArrayPush(pResult, SL_GET_NODE_DATA(pNode)); } diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index 58fd4eb6535b971324667562fe5011e8c8cce8b1..4b565567ab4815164a29cd67d049eab343dbdd39 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -1357,16 +1357,26 @@ bool tSkipListNodeFilterCallback(const void* pNode, void* param) { STable* pTable = *(STable**)(SL_GET_NODE_DATA((SSkipListNode*)pNode)); - char* val = dataRowTuple(pTable->tagVal); // todo not only the first column + char* val = NULL; int8_t type = pInfo->sch.type; + + if (pInfo->colIndex == TSDB_TBNAME_COLUMN_INDEX) { + val = pTable->name; + type = TSDB_DATA_TYPE_BINARY; + } else { + val = dataRowTuple(pTable->tagVal); // todo not only the first column + } int32_t ret = 0; - if (pInfo->q.nType == TSDB_DATA_TYPE_BINARY || pInfo->q.nType == TSDB_DATA_TYPE_NCHAR) { - ret = pInfo->compare(val, pInfo->q.pz); + if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) { + if (pInfo->optr == TSDB_RELATION_IN) { + ret = pInfo->compare(val, pInfo->q.arr); + } else { + ret = pInfo->compare(val, pInfo->q.pz); + } } else { tVariant t = {0}; tVariantCreateFromBinary(&t, val, (uint32_t)pInfo->sch.bytes, type); - ret = pInfo->compare(&t.i64Key, &pInfo->q.i64Key); } @@ -1393,7 +1403,7 @@ bool tSkipListNodeFilterCallback(const void* pNode, void* param) { return ret == 0; } case TSDB_RELATION_IN: { - + return ret == 1; } default: @@ -1474,8 +1484,8 @@ int32_t tsdbQueryByTagsCond( expr = calloc(1, sizeof(tExprNode)); expr->nodeType = TSQL_NODE_EXPR; expr->_node.optr = tagNameRelType; - expr->_node.pLeft = tbnameExpr; - expr->_node.pRight = tagExpr; + expr->_node.pLeft = tagExpr; + expr->_node.pRight = tbnameExpr; } } diff --git a/src/util/src/tarray.c b/src/util/src/tarray.c index ef57c2432f4953a006a6aac78ba12b240f50b455..51684e767cd517bda0d7b69e04e2fc3c3fac4acd 100755 --- a/src/util/src/tarray.c +++ b/src/util/src/tarray.c @@ -77,10 +77,11 @@ void* taosArrayPush(SArray* pArray, void* pData) { } void* taosArrayPop(SArray* pArray) { - if (pArray == NULL || pArray->size == 0) { + assert( pArray != NULL ); + + if (pArray->size == 0) { return NULL; } - pArray->size -= 1; return TARRAY_GET_ELEM(pArray, pArray->size); } diff --git a/src/util/src/tcompare.c b/src/util/src/tcompare.c index 98e0c9c9a20623249223d9189595ca26f24eb886..4d78a8cf0adada9841bd70b006d5ceb588faa4b6 100644 --- a/src/util/src/tcompare.c +++ b/src/util/src/tcompare.c @@ -215,7 +215,7 @@ static UNUSED_FUNC int32_t compareStrPatternComp(const void* pLeft, const void* return (ret == TSDB_PATTERN_MATCH) ? 0 : 1; } -static int32_t compareStrInList(const void* pLeft, const void* pRight) { +static int32_t compareFindStrInArray(const void* pLeft, const void* pRight) { const SArray* arr = (const SArray*)pRight; return taosArraySearchString(arr, pLeft) == NULL ? 0 : 1; } @@ -277,7 +277,7 @@ __compar_fn_t getComparFunc(int32_t type, int32_t filterDataType, int32_t optr) } else if (optr == TSDB_RELATION_IN) { assert(filterDataType == TSDB_DATA_TYPE_ARRAY); - comparFn = compareStrInList; + comparFn = compareFindStrInArray; } else { /* normal relational comparFn */ assert(filterDataType == TSDB_DATA_TYPE_BINARY);