From 5315500287e2240b0671d310c4d94d4aa93c3391 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 9 Feb 2023 16:09:46 +0800 Subject: [PATCH] fix filter error --- source/dnode/mnode/impl/src/mndIndex.c | 4 + source/dnode/vnode/src/meta/metaTable.c | 4 +- source/libs/parser/src/parTranslater.c | 2 +- tests/script/tsim/tagindex/add_index.sim | 123 +++++++++++++++++++++-- 4 files changed, 123 insertions(+), 10 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndIndex.c b/source/dnode/mnode/impl/src/mndIndex.c index 3886d4a258..66b59236eb 100644 --- a/source/dnode/mnode/impl/src/mndIndex.c +++ b/source/dnode/mnode/impl/src/mndIndex.c @@ -823,7 +823,11 @@ static int32_t mndAddIndex(SMnode *pMnode, SRpcMsg *pReq, SCreateTagIndexReq *re if (tag < 0) { terrno = TSDB_CODE_MND_TAG_NOT_EXIST; return -1; + } else if (tag == 0) { + terrno = TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST; + return -1; } + col_id_t colId = pStb->pTags[tag].colId; if (mndCheckColAndTagModifiable(pMnode, pStb->name, pStb->uid, colId) != 0) { return -1; diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 5953157591..a40f0afde1 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -452,7 +452,7 @@ int metaAddIndexToSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { } } - if (diffIdx == -1) { + if (diffIdx == -1 && diffIdx == 0) { goto _err; } @@ -566,7 +566,7 @@ int metaDropIndexFromSTable(SMeta *pMeta, int64_t version, SDropIndexReq *pReq) for (int i = 0; i < oStbEntry.stbEntry.schemaTag.nCols; i++) { SSchema *schema = oStbEntry.stbEntry.schemaTag.pSchema + i; if (0 == strncmp(schema->name, pReq->colName, sizeof(pReq->colName))) { - if (IS_IDX_ON(schema)) { + if (i != 0 || IS_IDX_ON(schema)) { pCol = schema; } break; diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 0626ea5e23..ce1ca64c9e 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -784,7 +784,7 @@ static void setColumnInfoBySchema(const SRealTableNode* pTable, const SSchema* p pCol->tableType = pTable->pMeta->tableType; pCol->colId = pColSchema->colId; pCol->colType = (tagFlag >= 0 ? COLUMN_TYPE_TAG : COLUMN_TYPE_COLUMN); - pCol->hasIndex = IS_IDX_ON(pColSchema); + pCol->hasIndex = ((0 == tagFlag) || (pColSchema != NULL && IS_IDX_ON(pColSchema))); pCol->node.resType.type = pColSchema->type; pCol->node.resType.bytes = pColSchema->bytes; if (TSDB_DATA_TYPE_TIMESTAMP == pCol->node.resType.type) { diff --git a/tests/script/tsim/tagindex/add_index.sim b/tests/script/tsim/tagindex/add_index.sim index 4bd4594303..f6dd74eeae 100644 --- a/tests/script/tsim/tagindex/add_index.sim +++ b/tests/script/tsim/tagindex/add_index.sim @@ -43,14 +43,25 @@ print =============== insert data into each table $i = 0 while $i < $tbNum $tb = $tbPrefix . $i - sql insert into $tb values(now, 10); + sql insert into $tb values(now, $i ); $i = $i + 1 endw sql create index ti2 on $mtPrefix (t2) -# equal +print ==== test name conflict +# +sql_error create index ti3 on $mtPrefix(t2) + +sql_error create index ti2 on $mtPrefix(t2) +sql_error create index ti2 on $mtPrefix(t1) +sql_error create index ti2 on $mtPrefix(t3) +sql_error create index ti2 on $mtPrefix(txx) + + +print ===== test operator equal + $i = 0 while $i < $tbNum sql select * from $mtPrefix where t2= $i ; @@ -60,6 +71,9 @@ while $i < $tbNum $i = $i + 1 endw + + +print ===== test operator great equal # great equal than $i = 0 while $i < $tbNum @@ -71,21 +85,19 @@ while $i < $tbNum $i = $i + 1 endw -# great than +print ===== test operator great $i = 0 while $i < $tbNum sql select * from $mtPrefix where t2 > $i ; $tmp = $tbNum - $i + $tmp = $tmp - 1 if $rows != $tmp then - print $rows - print $i - print $tmp return -1 endi $i = $i + 1 endw -# lower equal than +print ===== test operator lower $i = 0 while $i < $tbNum sql select * from $mtPrefix where t2 <= $i ; @@ -96,6 +108,7 @@ while $i < $tbNum $i = $i + 1 endw +print ===== test operator lower than # lower equal than $i = 0 while $i < $tbNum @@ -107,9 +120,105 @@ while $i < $tbNum $i = $i + 1 endw +print ===== add table after index created +$interval = $tbNum + $tbNum +$i = $interval +$limit = $interval + $tbNum +while $i < $limit + $tb = $tbPrefix . $i + sql insert into $tb using $mtPrefix tags( $i , $i , $i , $i , $i ) values( now, $i ) + $i = $i + 1 +endw + + + +print ===== add table after index created (opeator great equal than) +# great equal than +$i = $interval +while $i < $limit + sql select * from $mtPrefix where t2 >= $i ; + $tmp = $limit - $i + if $rows != $tmp then + return -1 + endi + $i = $i + 1 +endw + + +print ===== add table after index created (opeator great than) +# great than +$i = $interval +while $i < $limit + sql select * from $mtPrefix where t2 > $i ; + $tmp = $limit - $i + $tmp = $tmp - 1 + if $rows != $tmp then + return -1 + endi + $i = $i + 1 +endw + +print ===== drop table after index created + +# drop table +$dropTbNum = $tbNum / 2 +$i = 0 + +while $i < $tbNum + $tb = $tbPrefix . $i + sql drop table $tb + $i = $i + 1 +endw + +print ===== drop table after index created(opeator lower than) + +# lower equal than +$i = $interval +while $i < $limit + sql select * from $mtPrefix where t2 < $i ; + $tmp = $i - $interval + if $rows != $tmp then + return -1 + endi + $i = $i + 1 +endw + + +print ===== drop table after index created(opeator lower equal than) + +# lower equal than +$i = $interval +while $i < $limit + sql select * from $mtPrefix where t2 <= $i ; + + $tmp = $i - $interval + $tmp = $tmp + 1 + if $rows != $tmp then + return -1 + endi + $i = $i + 1 +endw + + +print === show index + +sql select * from information_schema.ins_indexes +if $rows != 1 then + return -1 +endi + + +print === drop index ti2 +sql drop index ti2 + +print === drop not exist index +sql_error drop index t2 +sql_error drop index t3 +sql_error create index ti0 on $mtPrefix (t1) +sql_error create index t2i on ta_3_tb17 (t2) system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file -- GitLab