diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 2d055acd2fbcb137cc7cc6ca5361cb2ea96e90c1..0e8b3cf949d58de9ab1d4c7b70bad6ee4d0a3a72 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -15,17 +15,18 @@ #include "meta.h" -static int metaSaveJsonVarToIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSchema *pSchema); -static int metaDelJsonVarFromIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSchema *pSchema); -static int metaSaveToTbDb(SMeta *pMeta, const SMetaEntry *pME); -static int metaUpdateUidIdx(SMeta *pMeta, const SMetaEntry *pME); -static int metaUpdateNameIdx(SMeta *pMeta, const SMetaEntry *pME); -static int metaUpdateTtlIdx(SMeta *pMeta, const SMetaEntry *pME); -static int metaSaveToSkmDb(SMeta *pMeta, const SMetaEntry *pME); -static int metaUpdateCtbIdx(SMeta *pMeta, const SMetaEntry *pME); -static int metaUpdateSuidIdx(SMeta *pMeta, const SMetaEntry *pME); -static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry); -static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type); +static int metaSaveJsonVarToIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSchema *pSchema); +static int metaDelJsonVarFromIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSchema *pSchema); +static int metaSaveToTbDb(SMeta *pMeta, const SMetaEntry *pME); +static int metaUpdateUidIdx(SMeta *pMeta, const SMetaEntry *pME); +static int metaUpdateNameIdx(SMeta *pMeta, const SMetaEntry *pME); +static int metaUpdateTtlIdx(SMeta *pMeta, const SMetaEntry *pME); +static int metaSaveToSkmDb(SMeta *pMeta, const SMetaEntry *pME); +static int metaUpdateCtbIdx(SMeta *pMeta, const SMetaEntry *pME); +static int metaUpdateSuidIdx(SMeta *pMeta, const SMetaEntry *pME); +static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry); +static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type); +static void metaDestroyTagIdxKey(STagIdxKey *pTagIdxKey); static void metaGetEntryInfo(const SMetaEntry *pEntry, SMetaInfo *pInfo) { pInfo->uid = pEntry->uid; @@ -594,6 +595,28 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) { const SSchema *pTagColumn = &stbEntry.stbEntry.schemaTag.pSchema[0]; if (pTagColumn->type == TSDB_DATA_TYPE_JSON) { metaDelJsonVarFromIdx(pMeta, &e, pTagColumn); + } else { + STagIdxKey *pTagIdxKey = NULL; + int32_t nTagIdxKey; + + const void *pTagData = NULL; + int32_t nTagData = 0; + + STagVal tagVal = {.cid = pTagColumn->colId}; + tTagGet((const STag *)e.ctbEntry.pTags, &tagVal); + if (IS_VAR_DATA_TYPE(pTagColumn->type)) { + pTagData = tagVal.pData; + nTagData = (int32_t)tagVal.nData; + } else { + pTagData = &(tagVal.i64); + nTagData = tDataTypes[pTagColumn->type].bytes; + } + + if (metaCreateTagIdxKey(e.ctbEntry.suid, pTagColumn->colId, pTagData, nTagData, pTagColumn->type, uid, + &pTagIdxKey, &nTagIdxKey) == 0) { + tdbTbDelete(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, &pMeta->txn); + } + metaDestroyTagIdxKey(pTagIdxKey); } tDecoderClear(&tdc); } diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 8ad2deeba9bd16f93d885e2111cca32a0ed4ad97..fc139a15338f3a0617cac56d8fe4cbc546f338ff 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -445,5 +445,7 @@ ./test.sh -f tsim/tag/set.sim ./test.sh -f tsim/tag/smallint.sim ./test.sh -f tsim/tag/tinyint.sim +./test.sh -f tsim/tag/drop_tag.sim + #======================b1-end=============== diff --git a/tests/script/tsim/tag/drop_tag.sim b/tests/script/tsim/tag/drop_tag.sim new file mode 100644 index 0000000000000000000000000000000000000000..03892039f92dfdd74fda175ea942dfa752ba6c2a --- /dev/null +++ b/tests/script/tsim/tag/drop_tag.sim @@ -0,0 +1,84 @@ + +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start +sql connect + + +$dbPrefix = ta_bib_db +$tbPrefix = ta_bib_tb +$mtPrefix = ta_bib_mt +$tbNum = 10 +$rowNum = 20 +$totalNum = 200 + +print =============== step1 +$i = 0 +$db = $dbPrefix . $i +$mt = $mtPrefix . $i + +sql drop database if exists $db + +sql create database $db vgroups 1 +sql use $db + +print ======== test bigint +sql create table if not exists st( ts timestamp, order_id bigint) tags (account_id bigint) + +sql create table t1 using st tags(111) +sql create table t2 using st tags(222) + +sql insert into t1(ts, order_id) values(1648791213001, 1) +sql insert into t2(ts, order_id) values(1648791213002, 2) +sql select account_id,count(*) from st where account_id = 111 group by account_id + +sql drop table t1 + +sql create table t1 using st tags(111) + +sql insert into t1(ts, order_id) values(1648791213001, 1) +sql insert into t2(ts, order_id) values(1648791213002, 2) + +sql select account_id,count(*) from st where account_id = 111 group by account_id + +if $rows != 1 then + return -1 +endi + +print ======== test varchar + +sql drop stable st + +sql create table if not exists st( ts timestamp, order_id bigint) tags (account_id binary(16)) + +sql create table t1 using st tags("aac") +sql create table t2 using st tags("abc") + +sql insert into t1(ts, order_id) values(1648791213001, 1) +sql insert into t2(ts, order_id) values(1648791213002, 2) +sql select account_id,count(*) from st where account_id = "aac" group by account_id + +sql drop table t1 + +sql create table t1 using st tags("aac") + +sql insert into t1(ts, order_id) values(1648791213001, 1) +sql insert into t2(ts, order_id) values(1648791213002, 2) + +sql select account_id,count(*) from st where account_id = "aac" group by account_id + +if $rows != 1 then + return -1 +endi + +print ====== test empty table +sql drop table t1 + +sql select account_id,count(*) from st where account_id = "aac" group by account_id +if $rows != 0 then + return -1 +endi + + +sql drop database $db +