diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index c6a6dd81473d75a319fb19ebc6bfa906eebbf6b0..64c811ca184893704e19b67b3e915b01dbc25d54 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -61,14 +61,14 @@ static int metaSaveJsonVarToIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const if (tTagToValArray((const STag *)data, &pTagVals) != 0) { return -1; } - char key[512] = {0}; SIndexMultiTerm *terms = indexMultiTermCreate(); int16_t nCols = taosArrayGetSize(pTagVals); for (int i = 0; i < nCols; i++) { STagVal *pTagVal = (STagVal *)taosArrayGet(pTagVals, i); char type = pTagVal->type; - sprintf(key, "%s_%s", tagName, pTagVal->pKey); + + char * key = pTagVal->pKey; int32_t nKey = strlen(key); SIndexTerm *term = NULL; diff --git a/source/libs/index/src/indexCache.c b/source/libs/index/src/indexCache.c index c1fb086fa098a03e8ad28fa0ee43f72caba3f207..1d8aa995be7e818e684b2604a42702847df6283e 100644 --- a/source/libs/index/src/indexCache.c +++ b/source/libs/index/src/indexCache.c @@ -123,12 +123,11 @@ static int32_t cacheSearchCompareFunc(void* cache, SIndexTerm* term, SIdxTRslt* if (cache == NULL) { return 0; } - - _cache_range_compare cmpFn = indexGetCompare(type); - MemTable* mem = cache; IndexCache* pCache = mem->pCache; + _cache_range_compare cmpFn = indexGetCompare(type); + CacheTerm* pCt = taosMemoryCalloc(1, sizeof(CacheTerm)); pCt->colVal = term->colVal; pCt->colType = term->colType; @@ -267,13 +266,20 @@ static int32_t cacheSearchCompareFunc_JSON(void* cache, SIndexTerm* term, SIdxTR int skip = 0; char* exBuf = NULL; - if (INDEX_TYPE_CONTAIN_EXTERN_TYPE(term->colType, TSDB_DATA_TYPE_JSON)) { + if (type == CONTAINS) { + SIndexTerm tm = {.suid = term->suid, + .operType = term->operType, + .colType = term->colType, + .colName = term->colVal, + .nColName = term->nColVal}; + exBuf = indexPackJsonDataPrefix(&tm, &skip); + pCt->colVal = exBuf; + } else { exBuf = indexPackJsonDataPrefix(term, &skip); pCt->colVal = exBuf; } char* key = indexCacheTermGet(pCt); - // SSkipListIterator* iter = tSkipListCreateIter(mem->mem); SSkipListIterator* iter = tSkipListCreateIterFromVal(mem->mem, key, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC); while (tSkipListIterNext(iter)) { SSkipListNode* node = tSkipListIterGet(iter); @@ -281,14 +287,19 @@ static int32_t cacheSearchCompareFunc_JSON(void* cache, SIndexTerm* term, SIdxTR break; } CacheTerm* c = (CacheTerm*)SL_GET_NODE_DATA(node); - // printf("json val: %s\n", c->colVal); - if (0 != strncmp(c->colVal, pCt->colVal, skip)) { - break; + TExeCond cond = CONTINUE; + if (type == CONTAINS) { + if (0 == strncmp(c->colVal, pCt->colVal, skip)) { + cond = MATCH; + } + } else { + if (0 != strncmp(c->colVal, pCt->colVal, skip)) { + break; + } + char* p = taosMemoryCalloc(1, strlen(c->colVal) + 1); + memcpy(p, c->colVal, strlen(c->colVal)); + TExeCond cond = cmpFn(p + skip, term->colVal, dType); } - char* p = taosMemoryCalloc(1, strlen(c->colVal) + 1); - memcpy(p, c->colVal, strlen(c->colVal)); - - TExeCond cond = cmpFn(p + skip, term->colVal, dType); if (cond == MATCH) { if (c->operaType == ADD_VALUE) { INDEX_MERGE_ADD_DEL(tr->del, tr->add, c->uid) @@ -302,7 +313,6 @@ static int32_t cacheSearchCompareFunc_JSON(void* cache, SIndexTerm* term, SIdxTR } else if (cond == BREAK) { break; } - taosMemoryFree(p); } taosMemoryFree(pCt); diff --git a/source/libs/index/src/indexFilter.c b/source/libs/index/src/indexFilter.c index fd701134addd91fa390dbce6252e6bd3dfc3ba3d..7c060fe10fdc7724ebf8d50c898a30e1d790e6b2 100644 --- a/source/libs/index/src/indexFilter.c +++ b/source/libs/index/src/indexFilter.c @@ -173,10 +173,8 @@ static int32_t sifInitJsonParam(SNode *node, SIFParam *param, SIFCtx *ctx) { param->colId = l->colId; param->colValType = l->node.resType.type; memcpy(param->dbName, l->dbName, sizeof(l->dbName)); -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wformat-overflow" - sprintf(param->colName, "%s_%s", l->colName, r->literal); -#pragma GCC diagnostic pop + memcpy(param->colName, r->literal, strlen(r->literal)); + // sprintf(param->colName, "%s_%s", l->colName, r->literal); param->colValType = r->typeData; return 0; // memcpy(param->colName, l->colName, sizeof(l->colName)); @@ -505,7 +503,6 @@ static int32_t sifExecOper(SOperatorNode *node, SIFCtx *ctx, SIFParam *output) { int32_t nParam = sifGetOperParamNum(node->opType); if (nParam <= 1) { output->status = SFLT_NOT_INDEX; - SIF_ERR_RET(code); return code; } if (node->opType == OP_TYPE_JSON_GET_VALUE) { diff --git a/source/libs/index/src/indexTfile.c b/source/libs/index/src/indexTfile.c index 0145df4676d9431e2f2bd62b4352db7da292e8c3..34f685db3a9c046602780df03b27b233d199e230 100644 --- a/source/libs/index/src/indexTfile.c +++ b/source/libs/index/src/indexTfile.c @@ -456,7 +456,17 @@ static int32_t tfSearchCompareFunc_JSON(void* reader, SIndexTerm* tem, SIdxTRslt int ret = 0; int skip = 0; - char* p = indexPackJsonDataPrefix(tem, &skip); + char* p = NULL; + if (ctype == CONTAINS) { + SIndexTerm tm = {.suid = tem->suid, + .operType = tem->operType, + .colType = tem->colType, + .colName = tem->colVal, + .nColName = tem->nColVal}; + p = indexPackJsonDataPrefix(&tm, &skip); + } else { + p = indexPackJsonDataPrefix(tem, &skip); + } _cache_range_compare cmpFn = indexGetCompare(ctype); @@ -470,18 +480,20 @@ static int32_t tfSearchCompareFunc_JSON(void* reader, SIndexTerm* tem, SIdxTRslt while ((rt = streamWithStateNextWith(st, NULL)) != NULL) { FstSlice* s = &rt->data; - int32_t sz = 0; - char* ch = (char*)fstSliceData(s, &sz); - char* tmp = taosMemoryCalloc(1, sz + 1); - memcpy(tmp, ch, sz); - - if (0 != strncmp(tmp, p, skip)) { - swsResultDestroy(rt); - taosMemoryFree(tmp); - break; + int32_t sz = 0; + char* ch = (char*)fstSliceData(s, &sz); + TExeCond cond = CONTINUE; + if (ctype == CONTAINS) { + if (0 != strncmp(ch, p, skip)) { + cond = MATCH; + } + } else { + if (0 != strncmp(ch, p, skip)) { + swsResultDestroy(rt); + break; + } + cond = cmpFn(ch + skip, tem->colVal, INDEX_TYPE_GET_TYPE(tem->colType)); } - - TExeCond cond = cmpFn(tmp + skip, tem->colVal, INDEX_TYPE_GET_TYPE(tem->colType)); if (MATCH == cond) { tfileReaderLoadTableIds((TFileReader*)reader, rt->out.out, tr->total); } else if (CONTINUE == cond) { @@ -489,7 +501,6 @@ static int32_t tfSearchCompareFunc_JSON(void* reader, SIndexTerm* tem, SIdxTRslt swsResultDestroy(rt); break; } - taosMemoryFree(tmp); swsResultDestroy(rt); } streamWithStateDestroy(st);