add/drop dynamic idx
This commit is contained in:
parent
0bea3475fb
commit
0bef283062
|
@ -635,31 +635,38 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) {
|
||||||
|
|
||||||
tDecoderInit(&tdc, tData, tLen);
|
tDecoderInit(&tdc, tData, tLen);
|
||||||
metaDecodeEntry(&tdc, &stbEntry);
|
metaDecodeEntry(&tdc, &stbEntry);
|
||||||
const SSchema *pTagColumn = &stbEntry.stbEntry.schemaTag.pSchema[0];
|
|
||||||
if (pTagColumn->type == TSDB_DATA_TYPE_JSON) {
|
SSchema *pTagColumn = NULL;
|
||||||
|
SSchemaWrapper *pTagSchema = &stbEntry.stbEntry.schemaTag;
|
||||||
|
if (pTagSchema->nCols == 1 && pTagSchema->pSchema[0].type == TSDB_DATA_TYPE_JSON) {
|
||||||
|
pTagColumn = &stbEntry.stbEntry.schemaTag.pSchema[0];
|
||||||
metaDelJsonVarFromIdx(pMeta, &e, pTagColumn);
|
metaDelJsonVarFromIdx(pMeta, &e, pTagColumn);
|
||||||
} else {
|
} else {
|
||||||
STagIdxKey *pTagIdxKey = NULL;
|
for (int i = 0; i < pTagSchema->nCols; i++) {
|
||||||
int32_t nTagIdxKey;
|
pTagColumn = &stbEntry.stbEntry.schemaTag.pSchema[i];
|
||||||
|
if (!IS_INDX_ON(pTagColumn)) continue;
|
||||||
|
STagIdxKey *pTagIdxKey = NULL;
|
||||||
|
int32_t nTagIdxKey;
|
||||||
|
|
||||||
const void *pTagData = NULL;
|
const void *pTagData = NULL;
|
||||||
int32_t nTagData = 0;
|
int32_t nTagData = 0;
|
||||||
|
|
||||||
STagVal tagVal = {.cid = pTagColumn->colId};
|
STagVal tagVal = {.cid = pTagColumn->colId};
|
||||||
tTagGet((const STag *)e.ctbEntry.pTags, &tagVal);
|
tTagGet((const STag *)e.ctbEntry.pTags, &tagVal);
|
||||||
if (IS_VAR_DATA_TYPE(pTagColumn->type)) {
|
if (IS_VAR_DATA_TYPE(pTagColumn->type)) {
|
||||||
pTagData = tagVal.pData;
|
pTagData = tagVal.pData;
|
||||||
nTagData = (int32_t)tagVal.nData;
|
nTagData = (int32_t)tagVal.nData;
|
||||||
} else {
|
} else {
|
||||||
pTagData = &(tagVal.i64);
|
pTagData = &(tagVal.i64);
|
||||||
nTagData = tDataTypes[pTagColumn->type].bytes;
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
tDecoderClear(&tdc);
|
||||||
}
|
}
|
||||||
|
@ -1379,6 +1386,12 @@ static int metaDropTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterT
|
||||||
terrno = TSDB_CODE_VND_COL_NOT_EXISTS;
|
terrno = TSDB_CODE_VND_COL_NOT_EXISTS;
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (IS_INDX_ON(pCol)) {
|
||||||
|
terrno = TSDB_CODE_VND_COL_ALREADY_EXISTS;
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
|
|
||||||
SArray *tagIdxList = taosArrayInit(512, sizeof(SMetaPair));
|
SArray *tagIdxList = taosArrayInit(512, sizeof(SMetaPair));
|
||||||
|
|
||||||
TBC *pTagIdxc = NULL;
|
TBC *pTagIdxc = NULL;
|
||||||
|
@ -1408,7 +1421,7 @@ static int metaDropTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterT
|
||||||
|
|
||||||
taosArrayDestroy(tagIdxList);
|
taosArrayDestroy(tagIdxList);
|
||||||
|
|
||||||
// drop index
|
// set pCol->flags; INDEX_ON
|
||||||
return 0;
|
return 0;
|
||||||
_err:
|
_err:
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1590,36 +1603,43 @@ static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry) {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
pTagColumn = &stbEntry.stbEntry.schemaTag.pSchema[0];
|
SSchemaWrapper *pTagSchema = &stbEntry.stbEntry.schemaTag;
|
||||||
|
if (pTagSchema->nCols == 1 && pTagSchema->pSchema[0].type == TSDB_DATA_TYPE_JSON) {
|
||||||
|
STagVal tagVal = {.cid = pTagColumn->colId};
|
||||||
|
pTagColumn = &stbEntry.stbEntry.schemaTag.pSchema[0];
|
||||||
|
|
||||||
STagVal tagVal = {.cid = pTagColumn->colId};
|
|
||||||
if (pTagColumn->type != TSDB_DATA_TYPE_JSON) {
|
|
||||||
tTagGet((const STag *)pCtbEntry->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;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// pTagData = pCtbEntry->ctbEntry.pTags;
|
|
||||||
// nTagData = ((const STag *)pCtbEntry->ctbEntry.pTags)->len;
|
|
||||||
pTagData = pCtbEntry->ctbEntry.pTags;
|
pTagData = pCtbEntry->ctbEntry.pTags;
|
||||||
nTagData = ((const STag *)pCtbEntry->ctbEntry.pTags)->len;
|
nTagData = ((const STag *)pCtbEntry->ctbEntry.pTags)->len;
|
||||||
ret = metaSaveJsonVarToIdx(pMeta, pCtbEntry, pTagColumn);
|
ret = metaSaveJsonVarToIdx(pMeta, pCtbEntry, pTagColumn);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
} else {
|
||||||
if (pTagData != NULL) {
|
for (int i = 0; i < pTagSchema->nCols; i++) {
|
||||||
if (metaCreateTagIdxKey(pCtbEntry->ctbEntry.suid, pTagColumn->colId, pTagData, nTagData, pTagColumn->type,
|
pTagColumn = &pTagSchema->pSchema[i];
|
||||||
pCtbEntry->uid, &pTagIdxKey, &nTagIdxKey) < 0) {
|
if (!IS_INDX_ON(pTagColumn)) continue;
|
||||||
ret = -1;
|
|
||||||
goto end;
|
STagVal tagVal = {.cid = pTagColumn->colId};
|
||||||
|
tTagGet((const STag *)pCtbEntry->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 (pTagData != NULL) {
|
||||||
|
if (metaCreateTagIdxKey(pCtbEntry->ctbEntry.suid, pTagColumn->colId, pTagData, nTagData, pTagColumn->type,
|
||||||
|
pCtbEntry->uid, &pTagIdxKey, &nTagIdxKey) < 0) {
|
||||||
|
ret = -1;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
tdbTbUpsert(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, NULL, 0, pMeta->txn);
|
||||||
|
}
|
||||||
|
metaDestroyTagIdxKey(pTagIdxKey);
|
||||||
}
|
}
|
||||||
tdbTbUpsert(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, NULL, 0, pMeta->txn);
|
|
||||||
}
|
}
|
||||||
end:
|
end:
|
||||||
metaDestroyTagIdxKey(pTagIdxKey);
|
// metaDestroyTagIdxKey(pTagIdxKey);
|
||||||
tDecoderClear(&dc);
|
tDecoderClear(&dc);
|
||||||
tdbFree(pData);
|
tdbFree(pData);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Reference in New Issue