Merge pull request #22427 from taosdata/feature/rebuildIndex0

rebuild index at tag0
This commit is contained in:
Haojun Liao 2023-08-16 09:47:43 +08:00 committed by GitHub
commit 63bc50a723
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 302 additions and 125 deletions

View File

@ -32,6 +32,8 @@ void taosSeedRand(uint32_t seed);
uint32_t taosRand(void);
uint32_t taosRandR(uint32_t* pSeed);
void taosRandStr(char* str, int32_t size);
void taosRandStr2(char* str, int32_t size);
uint32_t taosSafeRand(void);
#ifdef __cplusplus

View File

@ -142,7 +142,8 @@ int32_t colDataSetVal(SColumnInfoData* pColumnInfoData, uint32_t rowIndex, const
return 0;
}
int32_t colDataReassignVal(SColumnInfoData* pColumnInfoData, uint32_t dstRowIdx, uint32_t srcRowIdx, const char* pData) {
int32_t colDataReassignVal(SColumnInfoData* pColumnInfoData, uint32_t dstRowIdx, uint32_t srcRowIdx,
const char* pData) {
int32_t type = pColumnInfoData->info.type;
if (IS_VAR_DATA_TYPE(type)) {
int32_t dataLen = 0;
@ -164,7 +165,6 @@ int32_t colDataReassignVal(SColumnInfoData* pColumnInfoData, uint32_t dstRowIdx,
return 0;
}
static int32_t colDataReserve(SColumnInfoData* pColumnInfoData, size_t newSize) {
if (!IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) {
return TSDB_CODE_SUCCESS;
@ -190,7 +190,8 @@ static int32_t colDataReserve(SColumnInfoData* pColumnInfoData, size_t newSize)
static int32_t doCopyNItems(struct SColumnInfoData* pColumnInfoData, int32_t currentRow, const char* pData,
int32_t itemLen, int32_t numOfRows, bool trimValue) {
if (pColumnInfoData->info.bytes < itemLen) {
uWarn("column/tag actual data len %d is bigger than schema len %d, trim it:%d", itemLen, pColumnInfoData->info.bytes, trimValue);
uWarn("column/tag actual data len %d is bigger than schema len %d, trim it:%d", itemLen,
pColumnInfoData->info.bytes, trimValue);
if (trimValue) {
itemLen = pColumnInfoData->info.bytes;
} else {
@ -230,8 +231,8 @@ static int32_t doCopyNItems(struct SColumnInfoData* pColumnInfoData, int32_t cur
return TSDB_CODE_SUCCESS;
}
int32_t colDataSetNItems(SColumnInfoData* pColumnInfoData, uint32_t currentRow, const char* pData,
uint32_t numOfRows, bool trimValue) {
int32_t colDataSetNItems(SColumnInfoData* pColumnInfoData, uint32_t currentRow, const char* pData, uint32_t numOfRows,
bool trimValue) {
int32_t len = pColumnInfoData->info.bytes;
if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) {
len = varDataTLen(pData);
@ -698,8 +699,7 @@ int32_t blockDataFromBuf(SSDataBlock* pBlock, const char* buf) {
return TSDB_CODE_SUCCESS;
}
static bool colDataIsNNull(const SColumnInfoData* pColumnInfoData, int32_t startIndex,
uint32_t nRows) {
static bool colDataIsNNull(const SColumnInfoData* pColumnInfoData, int32_t startIndex, uint32_t nRows) {
if (!pColumnInfoData->hasNull) {
return false;
}
@ -880,7 +880,6 @@ int32_t dataBlockCompar(const void* p1, const void* p2, const void* param) {
}
static int32_t blockDataAssign(SColumnInfoData* pCols, const SSDataBlock* pDataBlock, const int32_t* index) {
size_t numOfCols = taosArrayGetSize(pDataBlock->pDataBlock);
for (int32_t i = 0; i < numOfCols; ++i) {
SColumnInfoData* pDst = &pCols[i];
@ -1131,6 +1130,7 @@ static int32_t doEnsureCapacity(SColumnInfoData* pColumn, const SDataBlockInfo*
if (tmp == NULL) {
return TSDB_CODE_OUT_OF_MEMORY;
}
// memset(tmp, 0, numOfRows * pColumn->info.bytes);
// copy back the existed data
if (pColumn->pData != NULL) {
@ -1780,8 +1780,8 @@ char* dumpBlockData(SSDataBlock* pDataBlock, const char* flag, char** pDataBuf)
int32_t rows = pDataBlock->info.rows;
int32_t len = 0;
len += snprintf(dumpBuf + len, size - len,
"===stream===%s|block type %d|child id %d|group id:%" PRIu64 "|uid:%" PRId64
"|rows:%" PRId64 "|version:%" PRIu64 "|cal start:%" PRIu64 "|cal end:%" PRIu64 "|tbl:%s\n",
"===stream===%s|block type %d|child id %d|group id:%" PRIu64 "|uid:%" PRId64 "|rows:%" PRId64
"|version:%" PRIu64 "|cal start:%" PRIu64 "|cal end:%" PRIu64 "|tbl:%s\n",
flag, (int32_t)pDataBlock->info.type, pDataBlock->info.childId, pDataBlock->info.id.groupId,
pDataBlock->info.id.uid, pDataBlock->info.rows, pDataBlock->info.version,
pDataBlock->info.calWin.skey, pDataBlock->info.calWin.ekey, pDataBlock->info.parTbName);
@ -2181,7 +2181,8 @@ int32_t blockEncode(const SSDataBlock* pBlock, char* data, int32_t numOfCols) {
}
colSizes[col] = htonl(colSizes[col]);
// uError("blockEncode col bytes:%d, type:%d, size:%d, htonl size:%d", pColRes->info.bytes, pColRes->info.type, htonl(colSizes[col]), colSizes[col]);
// uError("blockEncode col bytes:%d, type:%d, size:%d, htonl size:%d", pColRes->info.bytes, pColRes->info.type,
// htonl(colSizes[col]), colSizes[col]);
}
*actualLen = dataLen;
@ -2310,7 +2311,8 @@ void trimDataBlock(SSDataBlock* pBlock, int32_t totalRows, const bool* pBoolList
if (colDataIsNull_var(pDst, j)) {
colDataSetNull_var(pDst, numOfRows);
} else {
// fix address sanitizer error. p1 may point to memory that will change during realloc of colDataSetVal, first copy it to p2
// fix address sanitizer error. p1 may point to memory that will change during realloc of colDataSetVal, first
// copy it to p2
char* p1 = colDataGetVarData(pDst, j);
int32_t len = 0;
if (pDst->info.type == TSDB_DATA_TYPE_JSON) {

View File

@ -79,9 +79,12 @@ int32_t mndInitIdx(SMnode *pMnode) {
return sdbSetTable(pMnode->pSdb, table);
}
static int32_t mndFindSuperTableTagId(const SStbObj *pStb, const char *tagName) {
static int32_t mndFindSuperTableTagId(const SStbObj *pStb, const char *tagName, int8_t *hasIdx) {
for (int32_t tag = 0; tag < pStb->numOfTags; tag++) {
if (strcasecmp(pStb->pTags[tag].name, tagName) == 0) {
if (IS_IDX_ON(&pStb->pTags[tag])) {
*hasIdx = 1;
}
return tag;
}
}
@ -597,7 +600,8 @@ static int32_t mndSetUpdateIdxStbCommitLogs(SMnode *pMnode, STrans *pTrans, SStb
pNew->updateTime = taosGetTimestampMs();
pNew->lock = 0;
int32_t tag = mndFindSuperTableTagId(pOld, tagName);
int8_t hasIdx = 0;
int32_t tag = mndFindSuperTableTagId(pOld, tagName, &hasIdx);
if (tag < 0) {
terrno = TSDB_CODE_MND_TAG_NOT_EXIST;
return -1;
@ -612,14 +616,14 @@ static int32_t mndSetUpdateIdxStbCommitLogs(SMnode *pMnode, STrans *pTrans, SStb
SSchema *pTag = pNew->pTags + tag;
if (on == 1) {
if (IS_IDX_ON(pTag)) {
if (hasIdx && tag != 0) {
terrno = TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST;
return -1;
} else {
SSCHMEA_SET_IDX_ON(pTag);
}
} else {
if (!IS_IDX_ON(pTag)) {
if (hasIdx == 0) {
terrno = TSDB_CODE_MND_SMA_NOT_EXIST;
} else {
SSCHMEA_SET_IDX_OFF(pTag);
@ -667,7 +671,42 @@ _OVER:
mndTransDrop(pTrans);
return code;
}
int8_t mndCheckIndexNameByTagName(SMnode *pMnode, SIdxObj *pIdxObj) {
// build index on first tag, and no index name;
int8_t exist = 0;
SDbObj *pDb = NULL;
if (strlen(pIdxObj->db) > 0) {
pDb = mndAcquireDb(pMnode, pIdxObj->db);
if (pDb == NULL) return 0;
}
SSmaAndTagIter *pIter = NULL;
SIdxObj *pIdx = NULL;
SSdb *pSdb = pMnode->pSdb;
while (1) {
pIter = sdbFetch(pSdb, SDB_IDX, pIter, (void **)&pIdx);
if (pIter == NULL) break;
if (NULL != pDb && pIdx->dbUid != pDb->uid) {
sdbRelease(pSdb, pIdx);
continue;
}
if (pIdxObj->stbUid != pIdx->stbUid) {
sdbRelease(pSdb, pIdx);
continue;
}
if (strncmp(pIdxObj->colName, pIdx->colName, TSDB_COL_NAME_LEN) == 0) {
sdbCancelFetch(pSdb, pIter);
sdbRelease(pSdb, pIdx);
exist = 1;
break;
}
sdbRelease(pSdb, pIdx);
}
mndReleaseDb(pMnode, pDb);
return exist;
}
static int32_t mndAddIndex(SMnode *pMnode, SRpcMsg *pReq, SCreateTagIndexReq *req, SDbObj *pDb, SStbObj *pStb) {
int32_t code = -1;
SIdxObj idxObj = {0};
@ -681,11 +720,20 @@ static int32_t mndAddIndex(SMnode *pMnode, SRpcMsg *pReq, SCreateTagIndexReq *re
idxObj.stbUid = pStb->uid;
idxObj.dbUid = pStb->dbUid;
int32_t tag = mndFindSuperTableTagId(pStb, req->colName);
int8_t hasIdx = 0;
int32_t tag = mndFindSuperTableTagId(pStb, req->colName, &hasIdx);
if (tag < 0) {
terrno = TSDB_CODE_MND_TAG_NOT_EXIST;
return -1;
} else if (tag == 0) {
}
int8_t exist = 0;
if (tag == 0 && hasIdx == 1) {
exist = mndCheckIndexNameByTagName(pMnode, &idxObj);
if (exist) {
terrno = TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST;
return -1;
}
} else if (hasIdx == 1) {
terrno = TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST;
return -1;
}
@ -695,11 +743,11 @@ static int32_t mndAddIndex(SMnode *pMnode, SRpcMsg *pReq, SCreateTagIndexReq *re
return -1;
}
SSchema *pTag = pStb->pTags + tag;
if (IS_IDX_ON(pTag)) {
terrno = TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST;
return -1;
}
// SSchema *pTag = pStb->pTags + tag;
// if (IS_IDX_ON(pTag)) {
// terrno = TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST;
// return -1;
// }
code = mndAddIndexImpl(pMnode, pReq, pDb, pStb, &idxObj);
return code;
@ -806,8 +854,8 @@ int32_t mndDropIdxsByStb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *p
if (pIdx->stbUid == pStb->uid) {
if (mndSetDropIdxCommitLogs(pMnode, pTrans, pIdx) != 0) {
sdbCancelFetch(pSdb, pIter);
sdbRelease(pSdb, pIdx);
sdbCancelFetch(pSdb, pIdx);
return -1;
}
}

View File

@ -18,6 +18,7 @@
#include "mndDb.h"
#include "mndDnode.h"
#include "mndIndex.h"
#include "mndIndexComm.h"
#include "mndInfoSchema.h"
#include "mndMnode.h"
#include "mndPerfSchema.h"
@ -857,11 +858,39 @@ static int32_t mndCreateStb(SMnode *pMnode, SRpcMsg *pReq, SMCreateStbReq *pCrea
SStbObj stbObj = {0};
int32_t code = -1;
char fullIdxName[TSDB_INDEX_FNAME_LEN * 2] = {0};
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_DB_INSIDE, pReq, "create-stb");
if (pTrans == NULL) goto _OVER;
mInfo("trans:%d, used to create stb:%s", pTrans->id, pCreate->name);
if (mndBuildStbFromReq(pMnode, &stbObj, pCreate, pDb) != 0) goto _OVER;
char randStr[24] = {0};
taosRandStr2(randStr, tListLen(randStr) - 1);
SSchema *pSchema = &(stbObj.pTags[0]);
sprintf(fullIdxName, "%s.%s_%s", pDb->name, pSchema->name, randStr);
SSIdx idx = {0};
if (mndAcquireGlobalIdx(pMnode, fullIdxName, SDB_IDX, &idx) == 0 && idx.pIdx != NULL) {
terrno = TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST;
mndReleaseIdx(pMnode, idx.pIdx);
goto _OVER;
}
SIdxObj idxObj = {0};
memcpy(idxObj.name, fullIdxName, TSDB_INDEX_FNAME_LEN);
memcpy(idxObj.stb, stbObj.name, TSDB_TABLE_FNAME_LEN);
memcpy(idxObj.db, stbObj.db, TSDB_DB_FNAME_LEN);
memcpy(idxObj.colName, pSchema->name, TSDB_COL_NAME_LEN);
idxObj.createdTime = taosGetTimestampMs();
idxObj.uid = mndGenerateUid(fullIdxName, strlen(fullIdxName));
idxObj.stbUid = stbObj.uid;
idxObj.dbUid = stbObj.dbUid;
if (mndSetCreateIdxCommitLogs(pMnode, pTrans, &idxObj) < 0) goto _OVER;
if (mndAddStbToTrans(pMnode, pTrans, pDb, &stbObj) < 0) goto _OVER;
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
code = 0;
@ -1478,7 +1507,8 @@ static int32_t mndAlterStbTagBytes(SMnode *pMnode, const SStbObj *pOld, SStbObj
SSchema *pTag = pNew->pTags + tag;
if (!(pTag->type == TSDB_DATA_TYPE_BINARY || pTag->type == TSDB_DATA_TYPE_NCHAR || pTag->type == TSDB_DATA_TYPE_GEOMETRY)) {
if (!(pTag->type == TSDB_DATA_TYPE_BINARY || pTag->type == TSDB_DATA_TYPE_NCHAR ||
pTag->type == TSDB_DATA_TYPE_GEOMETRY)) {
terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
return -1;
}
@ -1598,7 +1628,8 @@ static int32_t mndAlterStbColumnBytes(SMnode *pMnode, const SStbObj *pOld, SStbO
}
SSchema *pCol = pNew->pColumns + col;
if (!(pCol->type == TSDB_DATA_TYPE_BINARY || pCol->type == TSDB_DATA_TYPE_NCHAR || pCol->type == TSDB_DATA_TYPE_GEOMETRY)) {
if (!(pCol->type == TSDB_DATA_TYPE_BINARY || pCol->type == TSDB_DATA_TYPE_NCHAR ||
pCol->type == TSDB_DATA_TYPE_GEOMETRY)) {
terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
return -1;
}
@ -3182,7 +3213,6 @@ static int32_t mndRetrieveStbCol(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB
SSdb *pSdb = pMnode->pSdb;
SStbObj *pStb = NULL;
int32_t numOfRows = 0;
if (!pShow->sysDbRsp) {
numOfRows = buildSysDbColsInfo(pBlock, pShow->db, pShow->filterTb);

View File

@ -1186,7 +1186,7 @@ int32_t metaFilterTableIds(void *pVnode, SMetaFltParam *arg, SArray *pUids) {
ret = -1;
for (int i = 0; i < oStbEntry.stbEntry.schemaTag.nCols; i++) {
SSchema *schema = oStbEntry.stbEntry.schemaTag.pSchema + i;
if (schema->colId == param->cid && param->type == schema->type && (IS_IDX_ON(schema) || i == 0)) {
if (schema->colId == param->cid && param->type == schema->type && (IS_IDX_ON(schema))) {
ret = 0;
}
}

View File

@ -450,12 +450,13 @@ int metaAddIndexToSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
goto _err;
}
if (IS_IDX_ON(pNew) && !IS_IDX_ON(pOld)) {
if (diffIdx != -1) goto _err;
// if (diffIdx != -1) goto _err;
diffIdx = i;
break;
}
}
if (diffIdx == -1 || diffIdx == 0) {
if (diffIdx == -1) {
goto _err;
}
@ -586,7 +587,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 (i != 0 || IS_IDX_ON(schema)) {
if (IS_IDX_ON(schema)) {
pCol = schema;
}
break;
@ -2094,7 +2095,7 @@ static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry) {
} else {
for (int i = 0; i < pTagSchema->nCols; i++) {
pTagColumn = &pTagSchema->pSchema[i];
if (i != 0 && !IS_IDX_ON(pTagColumn)) continue;
if (!IS_IDX_ON(pTagColumn)) continue;
STagVal tagVal = {.cid = pTagColumn->colId};
tTagGet((const STag *)pCtbEntry->ctbEntry.pTags, &tagVal);

View File

@ -864,7 +864,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 = ((0 == tagFlag) || (pColSchema != NULL && IS_IDX_ON(pColSchema)));
pCol->hasIndex = (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) {

View File

@ -84,3 +84,12 @@ void taosRandStr(char* str, int32_t size) {
str[i] = set[taosRand() % len];
}
}
void taosRandStr2(char* str, int32_t size) {
const char* set = "abcdefghijklmnopqrstuvwxyz0123456789";
int32_t len = 36;
for (int32_t i = 0; i < size; ++i) {
str[i] = set[taosRand() % len];
}
}

View File

@ -1204,6 +1204,9 @@
,,y,script,./test.sh -f tsim/tag/drop_tag.sim
,,y,script,./test.sh -f tsim/tag/tbNameIn.sim
,,y,script,./test.sh -f tmp/monitor.sim
,,y,script,./test.sh -f tsim/tagindex/add_index.sim
,,n,script,./test.sh -f tsim/tagindex/sma_and_tag_index.sim
#develop test
,,n,develop-test,python3 ./test.py -f 2-query/table_count_scan.py

View File

@ -52,9 +52,21 @@ sql create sma index sma_index_name1 on stb function(max(c1),max(c2),min(c1)) in
print --> show sma
sql show indexes from stb from d1;
if $rows != 1 then
if $rows != 2 then
return -1
endi
if $data[0][6] == tag_index then
if $data[1][0] != sma_index_name1 then
return -1
endi
if $data[1][1] != d1 then
return -1
endi
if $data[1][2] != stb then
return -1
endi
else
if $data[0][0] != sma_index_name1 then
return -1
endi
@ -64,6 +76,10 @@ endi
if $data[0][2] != stb then
return -1
endi
endi
print --> drop stb
sql drop table stb;
@ -78,9 +94,21 @@ sql create sma index sma_index_name1 on stb function(max(c1),max(c2),min(c1)) in
print --> show sma
sql show indexes from stb from d1;
if $rows != 1 then
if $rows != 2 then
return -1
endi
if $data[0][6] == tag_index then
if $data[1][0] != sma_index_name1 then
return -1
endi
if $data[1][1] != d1 then
return -1
endi
if $data[1][2] != stb then
return -1
endi
else
if $data[0][0] != sma_index_name1 then
return -1
endi
@ -90,6 +118,7 @@ endi
if $data[0][2] != stb then
return -1
endi
endi
print --> drop stb
sql drop table stb;

View File

@ -7,7 +7,7 @@ print ======== step0
$dbPrefix = ta_3_db
$tbPrefix = ta_3_tb
$mtPrefix = ta_3_mt
$tbNum = 500
$tbNum = 50
$rowNum = 20
$totalNum = 200
@ -48,12 +48,16 @@ while $i < $tbNum
$i = $i + 1
endw
sql_error create index ti1 on $mtPrefix (t1)
sql create index ti2 on $mtPrefix (t2)
sql create index ti5 on $mtPrefix (t5)
print ==== test name conflict
#
sql_error create index ti1 on $mtPrefix(t1)
sql_error create index ti11 on $mtPrefix(t1)
sql_error create index ti3 on $mtPrefix(t2)
sql_error create index ti2 on $mtPrefix(t2)
@ -73,6 +77,15 @@ while $i < $tbNum
$i = $i + 1
endw
$i = 0
while $i < $tbNum
sql select * from $mtPrefix where t1= $i ;
if $rows != 1 then
return -1
endi
$i = $i + 1
endw
print ===== test operator great equal
@ -250,7 +263,7 @@ endw
print === show index
sql select * from information_schema.ins_indexes
if $rows != 1 then
if $rows != 2 then
return -1
endi
@ -259,12 +272,41 @@ print === drop index ti2
sql drop index ti2
print === drop not exist index
sql select * from information_schema.ins_indexes
if $rows != 1 then
return -1
endi
sql drop index $data[0][0]
if $rows != 0 then
return -1
endi
sql_error drop index t2
sql_error drop index t3
sql create index ti0 on $mtPrefix (t1)
$i = $interval
while $i < $limit
sql select * from $mtPrefix where t1 <= $i ;
$tmp = $i - $interval
$tmp = $tmp + 1
if $rows != $tmp then
return -1
endi
$i = $i + 1
endw
sql_error create index ti0 on $mtPrefix (t1)
sql_error create index ti2 on $mtPrefix (t1)
sql_error create index t2i on ta_3_tb17 (t2)

View File

@ -69,7 +69,7 @@ sql create sma index smat2i on $mtPrefix function(max(c1)) interval(6m,10s) slid
sql select * from information_schema.ins_indexes
if $rows != 2 then
if $rows != 3 then
return -1
endi
@ -84,7 +84,7 @@ while $i < 5
endw
sql select * from information_schema.ins_indexes
if $rows != 6 then
if $rows != 7 then
return -1
endi
@ -114,13 +114,13 @@ sql use $dbPrefix
sql create table if not exists $mtPrefix (ts timestamp, c1 int) tags (t1 int, t2 int, t3 int, t4 int, t5 int)
sql create index tagt2i on $mtPrefix (t2)
sql select * from information_schema.ins_indexes
if $rows != 1 then
if $rows != 2 then
return -1
endi
sql alter table $mtPrefix drop tag t2
sql select * from information_schema.ins_indexes
if $rows != 0 then
if $rows != 1 then
return -1
endi
@ -128,18 +128,22 @@ endi
print ==== rename tag name, and update index colName
sql create index tagt3i on $mtPrefix (t3)
sql select * from information_schema.ins_indexes
if $rows != 1 then
if $rows != 2 then
return -1
endi
sql alter table $mtPrefix rename tag t3 txxx
sql select * from information_schema.ins_indexes
if $rows != 1 then
if $rows != 2 then
return -1
endi
if $data05 != txxx then
return -1
if $data05 == txxx then
print "manual created index"
elif $data15 == txxx then
print "auto created index at tag0"
else
return -1;
endi
@ -153,7 +157,7 @@ sql create table if not exists $mtPrefix (ts timestamp, c1 int) tags (t1 int, t2
sql create index tagt3i on $mtPrefix (t3)
sql select * from information_schema.ins_indexes
if $rows != 2 then
if $rows != 4 then
return -1
endi

View File

@ -59,14 +59,18 @@ class TDTestCase:
tdSql.checkData(1, 2, 2)
def check_indexes(self):
tdSql.checkRows(1)
tdSql.checkRows(2)
for i in range(2):
col_name = tdSql.getData(i, 5)
if col_name == "t0":
continue
tdSql.checkCols(7)
tdSql.checkData(0, 0, 'idx1')
tdSql.checkData(0, 1, 'db')
tdSql.checkData(0, 2, 'stb')
tdSql.checkData(0, 3, None)
tdSql.checkData(0, 5, 't1')
tdSql.checkData(0, 6, 'tag_index')
tdSql.checkData(i, 0, 'idx1')
tdSql.checkData(i, 1, 'db')
tdSql.checkData(i, 2, 'stb')
tdSql.checkData(i, 3, None)
tdSql.checkData(i, 5, 't1')
tdSql.checkData(i, 6, 'tag_index')
def run(self):
tdSql.execute(f'create database db')

View File

@ -118,12 +118,15 @@ class TDTestCase:
def show_tagidx(self, stbname):
sql = f'select index_name,column_name from information_schema.ins_indexes where db_name="db"'
tdSql.query(sql)
rows = len(self.tag_dict.keys())-1
rows = len(self.tag_dict.keys())
tdSql.checkRows(rows)
for i in range(rows):
col_name = tdSql.getData(i, 1)
idx_name = f'idx_{col_name}'
# skip first tag
if col_name == "t1":
continue
tdSql.checkData(i, 0, idx_name)
tdLog.info(f' show {rows} tag indexs ok.')
@ -201,7 +204,7 @@ class TDTestCase:
# check idx result is 0
sql = f'select index_name,column_name from information_schema.ins_indexes where db_name="db"'
tdSql.query(sql)
tdSql.checkRows(0)
tdSql.checkRows(1)
tdLog.info(f' drop {cnt} tag indexs ok.')
# create long name idx