diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 3a0c50a96b..4c845eb938 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -265,10 +265,8 @@ int32_t* taosGetErrno(); // #define TSDB_CODE_MND_INVALID_COLUMN_LENGTH TAOS_DEF_ERROR_CODE(0, 0x0377) // 2.x #define TSDB_CODE_MND_INVALID_FUNC_COMMENT TAOS_DEF_ERROR_CODE(0, 0x0378) #define TSDB_CODE_MND_INVALID_FUNC_RETRIEVE TAOS_DEF_ERROR_CODE(0, 0x0379) -#define TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x037A) -#define TSDB_CODE_MND_TAG_INDEX_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x037B) + - // mnode-db #define TSDB_CODE_MND_DB_NOT_SELECTED TAOS_DEF_ERROR_CODE(0, 0x0380) @@ -370,6 +368,11 @@ int32_t* taosGetErrno(); #define TSDB_CODE_MND_SMA_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0481) #define TSDB_CODE_MND_INVALID_SMA_OPTION TAOS_DEF_ERROR_CODE(0, 0x0482) +// mnode-tag-indxe + +#define TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0483) +#define TSDB_CODE_MND_TAG_INDEX_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0484) + // dnode // #define TSDB_CODE_DND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0400) // 2.x // #define TSDB_CODE_DND_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0401) // 2.x diff --git a/source/dnode/mnode/impl/src/mndIndex.c b/source/dnode/mnode/impl/src/mndIndex.c index 49d2bf439d..983ea28515 100644 --- a/source/dnode/mnode/impl/src/mndIndex.c +++ b/source/dnode/mnode/impl/src/mndIndex.c @@ -420,6 +420,8 @@ static int32_t mndProcessCreateIdxReq(SRpcMsg *pReq) { SSIdx idx = {0}; if (mndAcquireGlobalIdx(pMnode, createReq.idxName, SDB_IDX, &idx) == 0) { pIdx = idx.pIdx; + } else { + goto _OVER; } if (pIdx != NULL) { terrno = TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST; @@ -748,6 +750,8 @@ int32_t mndProcessDropTagIdxReq(SRpcMsg *pReq) { SSIdx idx = {0}; if (mndAcquireGlobalIdx(pMnode, req.name, SDB_IDX, &idx) == 0) { pIdx = idx.pIdx; + } else { + goto _OVER; } if (pIdx == NULL) { if (req.igNotExists) { diff --git a/source/dnode/mnode/impl/src/mndIndexCom.c b/source/dnode/mnode/impl/src/mndIndexCom.c index 849c220f55..454c92e40b 100644 --- a/source/dnode/mnode/impl/src/mndIndexCom.c +++ b/source/dnode/mnode/impl/src/mndIndexCom.c @@ -40,6 +40,8 @@ int mndAcquireGlobalIdx(SMnode *pMnode, char *name, int type, SSIdx *idx) { idx->pIdx = pSma; } else { // type == SDB_IDX mndReleaseSma(pMnode, pSma); + terrno = TSDB_CODE_MND_SMA_ALREADY_EXIST; + return -1; } } else { if (type == SDB_IDX) { @@ -47,6 +49,8 @@ int mndAcquireGlobalIdx(SMnode *pMnode, char *name, int type, SSIdx *idx) { idx->pIdx = pIdx; } else { mndReleaseIdx(pMnode, pIdx); + terrno = TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST; + return -1; } } return 0; diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index fb9a4e52d6..a9a0560205 100644 --- a/source/dnode/mnode/impl/src/mndSma.c +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -57,7 +57,7 @@ static int32_t mndRetrieveIdx(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc static int32_t mndProcessDropIdxReq(SRpcMsg *pReq) { int ret = mndProcessDropSmaReq(pReq); - if (terrno == TSDB_CODE_MND_SMA_NOT_EXIST) { + if (terrno == TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST) { terrno = 0; ret = mndProcessDropTagIdxReq(pReq); } @@ -735,6 +735,8 @@ static int32_t mndProcessCreateSmaReq(SRpcMsg *pReq) { SSIdx idx = {0}; if (mndAcquireGlobalIdx(pMnode, createReq.name, SDB_SMA, &idx) == 0) { pSma = idx.pIdx; + } else { + goto _OVER; } if (pSma != NULL) { @@ -985,6 +987,8 @@ static int32_t mndProcessDropSmaReq(SRpcMsg *pReq) { SSIdx idx = {0}; if (mndAcquireGlobalIdx(pMnode, dropReq.name, SDB_SMA, &idx) == 0) { pSma = idx.pIdx; + } else { + goto _OVER; } if (pSma == NULL) { if (dropReq.igNotExists) { @@ -1027,6 +1031,9 @@ static int32_t mndGetSma(SMnode *pMnode, SUserIndexReq *indexReq, SUserIndexRsp SSIdx idx = {0}; if (0 == mndAcquireGlobalIdx(pMnode, indexReq->indexFName, SDB_SMA, &idx)) { pSma = idx.pIdx; + } else { + *exist = false; + return 0; } if (pSma == NULL) { diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c index c8779c69ec..a4201117d6 100644 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -1295,8 +1295,12 @@ int32_t metaFilterTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) { int count = 0; int32_t valid = 0; + bool found = false; static const int8_t TRY_ERROR_LIMIT = 1; + + /// src: [[suid, cid1, type1]....[suid, cid2, type2]....[suid, cid3, type3]...] + /// target: [suid, cid2, type2] do { void *entryKey = NULL, *entryVal = NULL; int32_t nEntryKey, nEntryVal; @@ -1313,6 +1317,7 @@ int32_t metaFilterTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) { if (p == NULL) break; if (p->type != pCursor->type || p->suid != pCursor->suid || p->cid != pCursor->cid) { + if (found == true) break; count++; valid = param->reverse ? tdbTbcMoveToPrev(pCursor->pCur) : tdbTbcMoveToNext(pCursor->pCur); if (valid < 0) { @@ -1332,6 +1337,7 @@ int32_t metaFilterTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) { tuid = *(tb_uid_t *)(p->data + tDataTypes[pCursor->type].bytes); } taosArrayPush(pUids, &tuid); + found = true; } else { if (param->equal == true) { if (count > TRY_ERROR_LIMIT) break; diff --git a/source/libs/executor/src/sysscanoperator.c b/source/libs/executor/src/sysscanoperator.c index fd23357002..73abbe2f89 100644 --- a/source/libs/executor/src/sysscanoperator.c +++ b/source/libs/executor/src/sysscanoperator.c @@ -199,8 +199,8 @@ int32_t sysFilte__TableName(void* arg, SNode* pNode, SArray* result) { SOperatorNode* pOper = (SOperatorNode*)pNode; SValueNode* pVal = (SValueNode*)pOper->pRight; - bool reverse = false; - bool equal = false; + + bool reverse = false, equal = false; __optSysFilter func = optSysGetFilterFunc(pOper->opType, &reverse, &equal); if (func == NULL) return -1; @@ -220,8 +220,7 @@ int32_t sysFilte__CreateTime(void* arg, SNode* pNode, SArray* result) { SOperatorNode* pOper = (SOperatorNode*)pNode; SValueNode* pVal = (SValueNode*)pOper->pRight; - bool reverse = false; - bool equal = false; + bool reverse = false, equal = false; __optSysFilter func = optSysGetFilterFunc(pOper->opType, &reverse, &equal); if (func == NULL) return -1; diff --git a/source/libs/index/src/indexFilter.c b/source/libs/index/src/indexFilter.c index b659abc6e8..0d13db2f35 100644 --- a/source/libs/index/src/indexFilter.c +++ b/source/libs/index/src/indexFilter.c @@ -476,7 +476,7 @@ static int32_t sifDoIndex(SIFParam *left, SIFParam *right, int8_t operType, SIFP ret = indexJsonSearch(arg->ivtIdx, mtm, output->result); indexMultiTermQueryDestroy(mtm); } else { - bool reverse, equal; + bool reverse = false, equal = false; FilterFunc filterFunc = sifGetFilterFunc(qtype, &reverse, &equal); SMetaFltParam param = {.suid = arg->suid, diff --git a/tests/script/tsim/tagindex/add_index.sim b/tests/script/tsim/tagindex/add_index.sim index 4f40aa7397..4e883ef150 100644 --- a/tests/script/tsim/tagindex/add_index.sim +++ b/tests/script/tsim/tagindex/add_index.sim @@ -7,7 +7,7 @@ print ======== step0 $dbPrefix = ta_3_db $tbPrefix = ta_3_tb $mtPrefix = ta_3_mt -$tbNum = 101 +$tbNum = 100 $rowNum = 20 $totalNum = 200 diff --git a/tests/script/tsim/tagindex/sma_and_tag_index.sim b/tests/script/tsim/tagindex/sma_and_tag_index.sim index 3aa14b6117..76de7b4c34 100644 --- a/tests/script/tsim/tagindex/sma_and_tag_index.sim +++ b/tests/script/tsim/tagindex/sma_and_tag_index.sim @@ -7,7 +7,7 @@ print ======== step0 $dbPrefix = ta_3_db $tbPrefix = ta_3_tb $mtPrefix = ta_3_mt -$tbNum = 101 +$tbNum = 1 $rowNum = 20 $totalNum = 200 @@ -48,10 +48,21 @@ while $i < $tbNum endw -sql create index ti2 on $mtPrefix (t2) +print --> create sma and tag index, global name conflict +sql create sma index t2i on $mtPrefix function(max(c1)) interval(6m,10s) sliding(6m); +sql_error create index t2i on $mtPrefix (t2) +sql drop index t2i + + +#print --> create tagindex and sma index, global name conflict +sql create index t2i on $mtPrefix (t2) +sql_error create sma index t2i on $mtPrefix function(max(c1)) interval(6m,10s) sliding(6m); + +sql drop index t2i + print ==== test name conflict -# + sql_error create index ti3 on $mtPrefix(t2) sql_error create index ti2 on $mtPrefix(t2) @@ -60,22 +71,4 @@ sql_error create index ti2 on $mtPrefix(t3) sql_error create index ti2 on $mtPrefix(txx) - - - - - - - - - -print === show index - -sql select * from information_schema.ins_indexes -if $rows != 1 then - return -1 -endi - - - system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file