add index to ins_tables
This commit is contained in:
parent
f82e6b41ca
commit
681b973cae
|
@ -86,8 +86,12 @@ struct SMeta {
|
||||||
TTB* pSuidIdx;
|
TTB* pSuidIdx;
|
||||||
// ivt idx and idx
|
// ivt idx and idx
|
||||||
void* pTagIvtIdx;
|
void* pTagIvtIdx;
|
||||||
TTB* pTagIdx;
|
|
||||||
TTB* pTtlIdx;
|
TTB* pTagIdx;
|
||||||
|
TTB* pTtlIdx;
|
||||||
|
|
||||||
|
TTB* pCtimeIdx; // table created time idx
|
||||||
|
TTB* pNcolIdx; // ncol of table idx, normal table only
|
||||||
|
|
||||||
TTB* pSmaIdx;
|
TTB* pSmaIdx;
|
||||||
|
|
||||||
|
@ -142,6 +146,16 @@ typedef struct {
|
||||||
int64_t smaUid;
|
int64_t smaUid;
|
||||||
} SSmaIdxKey;
|
} SSmaIdxKey;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int64_t ctime;
|
||||||
|
tb_uid_t uid;
|
||||||
|
} SCtimeIdxKey;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int16_t ncol;
|
||||||
|
tb_uid_t uid;
|
||||||
|
} SNcolIdxKey;
|
||||||
|
|
||||||
// metaTable ==================
|
// metaTable ==================
|
||||||
int metaCreateTagIdxKey(tb_uid_t suid, int32_t cid, const void* pTagData, int32_t nTagData, int8_t type, tb_uid_t uid,
|
int metaCreateTagIdxKey(tb_uid_t suid, int32_t cid, const void* pTagData, int32_t nTagData, int8_t type, tb_uid_t uid,
|
||||||
STagIdxKey** ppTagIdxKey, int32_t* nTagIdxKey);
|
STagIdxKey** ppTagIdxKey, int32_t* nTagIdxKey);
|
||||||
|
|
|
@ -24,6 +24,9 @@ static int uidIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kL
|
||||||
static int smaIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
static int smaIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
||||||
static int taskIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
static int taskIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
||||||
|
|
||||||
|
static int ctimeIdxCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
||||||
|
static int ncolIdxCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
||||||
|
|
||||||
static int32_t metaInitLock(SMeta *pMeta) { return taosThreadRwlockInit(&pMeta->lock, NULL); }
|
static int32_t metaInitLock(SMeta *pMeta) { return taosThreadRwlockInit(&pMeta->lock, NULL); }
|
||||||
static int32_t metaDestroyLock(SMeta *pMeta) { return taosThreadRwlockDestroy(&pMeta->lock); }
|
static int32_t metaDestroyLock(SMeta *pMeta) { return taosThreadRwlockDestroy(&pMeta->lock); }
|
||||||
|
|
||||||
|
@ -139,6 +142,20 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta) {
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// idx table create time
|
||||||
|
ret = tdbTbOpen("ctime.idx", sizeof(SCtimeIdxKey), 0, ctimeIdxCmpr, pMeta->pEnv, &pMeta->pCtimeIdx);
|
||||||
|
if (ret < 0) {
|
||||||
|
metaError("vgId:%d, failed to open meta ctime index since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
|
|
||||||
|
// idx num of col, normal table only
|
||||||
|
ret = tdbTbOpen("ncol.idx", sizeof(SNcolIdxKey), 0, ncolIdxCmpr, pMeta->pEnv, &pMeta->pNcolIdx);
|
||||||
|
if (ret < 0) {
|
||||||
|
metaError("vgId:%d, failed to open meta ncol index since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
|
|
||||||
ret = tdbTbOpen("stream.task.db", sizeof(int64_t), -1, taskIdxKeyCmpr, pMeta->pEnv, &pMeta->pStreamDb);
|
ret = tdbTbOpen("stream.task.db", sizeof(int64_t), -1, taskIdxKeyCmpr, pMeta->pEnv, &pMeta->pStreamDb);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
metaError("vgId:%d, failed to open meta stream task index since %s", TD_VID(pVnode), tstrerror(terrno));
|
metaError("vgId:%d, failed to open meta stream task index since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||||
|
@ -166,6 +183,8 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta) {
|
||||||
_err:
|
_err:
|
||||||
if (pMeta->pIdx) metaCloseIdx(pMeta);
|
if (pMeta->pIdx) metaCloseIdx(pMeta);
|
||||||
if (pMeta->pStreamDb) tdbTbClose(pMeta->pStreamDb);
|
if (pMeta->pStreamDb) tdbTbClose(pMeta->pStreamDb);
|
||||||
|
if (pMeta->pNcolIdx) tdbTbClose(pMeta->pNcolIdx);
|
||||||
|
if (pMeta->pCtimeIdx) tdbTbClose(pMeta->pCtimeIdx);
|
||||||
if (pMeta->pSmaIdx) tdbTbClose(pMeta->pSmaIdx);
|
if (pMeta->pSmaIdx) tdbTbClose(pMeta->pSmaIdx);
|
||||||
if (pMeta->pTtlIdx) tdbTbClose(pMeta->pTtlIdx);
|
if (pMeta->pTtlIdx) tdbTbClose(pMeta->pTtlIdx);
|
||||||
if (pMeta->pTagIvtIdx) indexClose(pMeta->pTagIvtIdx);
|
if (pMeta->pTagIvtIdx) indexClose(pMeta->pTagIvtIdx);
|
||||||
|
@ -391,6 +410,43 @@ static int ttlIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kL
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int ctimeIdxCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
|
||||||
|
SCtimeIdxKey *pCtimeIdxKey1 = (SCtimeIdxKey *)pKey1;
|
||||||
|
SCtimeIdxKey *pCtimeIdxKey2 = (SCtimeIdxKey *)pKey2;
|
||||||
|
if (pCtimeIdxKey1->ctime > pCtimeIdxKey2->ctime) {
|
||||||
|
return 1;
|
||||||
|
} else if (pCtimeIdxKey1->ctime < pCtimeIdxKey2->ctime) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pCtimeIdxKey1->uid > pCtimeIdxKey2->uid) {
|
||||||
|
return 1;
|
||||||
|
} else if (pCtimeIdxKey1->uid < pCtimeIdxKey2->uid) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ncolIdxCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
|
||||||
|
SNcolIdxKey *pNcolIdxKey1 = (SNcolIdxKey *)pKey1;
|
||||||
|
SNcolIdxKey *pNcolIdxKey2 = (SNcolIdxKey *)pKey2;
|
||||||
|
|
||||||
|
if (pNcolIdxKey1->ncol > pNcolIdxKey2->ncol) {
|
||||||
|
return 1;
|
||||||
|
} else if (pNcolIdxKey1->ncol < pNcolIdxKey2->ncol) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pNcolIdxKey1->uid > pNcolIdxKey2->uid) {
|
||||||
|
return 1;
|
||||||
|
} else if (pNcolIdxKey1->uid < pNcolIdxKey2->uid) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int smaIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
|
static int smaIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
|
||||||
SSmaIdxKey *pSmaIdxKey1 = (SSmaIdxKey *)pKey1;
|
SSmaIdxKey *pSmaIdxKey1 = (SSmaIdxKey *)pKey1;
|
||||||
SSmaIdxKey *pSmaIdxKey2 = (SSmaIdxKey *)pKey2;
|
SSmaIdxKey *pSmaIdxKey2 = (SSmaIdxKey *)pKey2;
|
||||||
|
|
|
@ -26,6 +26,11 @@ static int metaUpdateCtbIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||||
static int metaUpdateSuidIdx(SMeta *pMeta, const SMetaEntry *pME);
|
static int metaUpdateSuidIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||||
static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry);
|
static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry);
|
||||||
static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type);
|
static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type);
|
||||||
|
// opt ins_tables query
|
||||||
|
static int metaUpdateCtimeIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||||
|
static int metaDeleteCtimeIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||||
|
static int metaUpdateNcolIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||||
|
static int metaDeleteNcolIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||||
|
|
||||||
static void metaGetEntryInfo(const SMetaEntry *pEntry, SMetaInfo *pInfo) {
|
static void metaGetEntryInfo(const SMetaEntry *pEntry, SMetaInfo *pInfo) {
|
||||||
pInfo->uid = pEntry->uid;
|
pInfo->uid = pEntry->uid;
|
||||||
|
@ -547,6 +552,28 @@ static void metaBuildTtlIdxKey(STtlIdxKey *ttlKey, const SMetaEntry *pME) {
|
||||||
ttlKey->dtime = ctime / 1000 + ttlDays * tsTtlUnit;
|
ttlKey->dtime = ctime / 1000 + ttlDays * tsTtlUnit;
|
||||||
ttlKey->uid = pME->uid;
|
ttlKey->uid = pME->uid;
|
||||||
}
|
}
|
||||||
|
static int metaBuildCtimeIdxKey(SCtimeIdxKey *ctimeKey, const SMetaEntry *pME) {
|
||||||
|
int64_t ctime;
|
||||||
|
if (pME->type == TSDB_CHILD_TABLE) {
|
||||||
|
ctime = pME->ctbEntry.ctime;
|
||||||
|
} else if (pME->type == TSDB_NORMAL_TABLE) {
|
||||||
|
ctime = pME->ntbEntry.ctime;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctimeKey->ctime = ctime;
|
||||||
|
ctimeKey->uid = pME->uid;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int metaBuildNColIdxKey(SNcolIdxKey *ncolKey, const SMetaEntry *pME) {
|
||||||
|
if (pME->type != TSDB_NORMAL_TABLE) return -1;
|
||||||
|
|
||||||
|
ncolKey->ncol = pME->ntbEntry.schemaRow.nCols;
|
||||||
|
ncolKey->uid = pME->uid;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int metaDeleteTtlIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
static int metaDeleteTtlIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||||
STtlIdxKey ttlKey = {0};
|
STtlIdxKey ttlKey = {0};
|
||||||
|
@ -602,6 +629,9 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) {
|
||||||
tdbTbDelete(pMeta->pNameIdx, e.name, strlen(e.name) + 1, &pMeta->txn);
|
tdbTbDelete(pMeta->pNameIdx, e.name, strlen(e.name) + 1, &pMeta->txn);
|
||||||
tdbTbDelete(pMeta->pUidIdx, &uid, sizeof(uid), &pMeta->txn);
|
tdbTbDelete(pMeta->pUidIdx, &uid, sizeof(uid), &pMeta->txn);
|
||||||
|
|
||||||
|
if (e.type == TSDB_CHILD_TABLE || e.type == TSDB_NORMAL_TABLE) metaDeleteCtimeIdx(pMeta, &e);
|
||||||
|
if (e.type == TSDB_NORMAL_TABLE) metaDeleteNcolIdx(pMeta, &e);
|
||||||
|
|
||||||
if (e.type != TSDB_SUPER_TABLE) metaDeleteTtlIdx(pMeta, &e);
|
if (e.type != TSDB_SUPER_TABLE) metaDeleteTtlIdx(pMeta, &e);
|
||||||
|
|
||||||
if (e.type == TSDB_CHILD_TABLE) {
|
if (e.type == TSDB_CHILD_TABLE) {
|
||||||
|
@ -628,6 +658,37 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
// opt ins_tables
|
||||||
|
int metaUpdateCtimeIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||||
|
SCtimeIdxKey ctimeKey = {0};
|
||||||
|
if (metaBuildCtimeIdxKey(&ctimeKey, pME) < 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return tdbTbInsert(pMeta->pCtimeIdx, &ctimeKey, sizeof(ctimeKey), NULL, 0, &pMeta->txn);
|
||||||
|
}
|
||||||
|
|
||||||
|
int metaDeleteCtimeIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||||
|
SCtimeIdxKey ctimeKey = {0};
|
||||||
|
if (metaBuildCtimeIdxKey(&ctimeKey, pME) < 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return tdbTbDelete(pMeta->pCtimeIdx, &ctimeKey, sizeof(ctimeKey), &pMeta->txn);
|
||||||
|
}
|
||||||
|
int metaUpdateNcolIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||||
|
SNcolIdxKey ncolKey = {0};
|
||||||
|
if (metaBuildNColIdxKey(&ncolKey, pME) < 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return tdbTbInsert(pMeta->pNcolIdx, &ncolKey, sizeof(ncolKey), NULL, 0, &pMeta->txn);
|
||||||
|
}
|
||||||
|
|
||||||
|
int metaDeleteNcolIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||||
|
SNcolIdxKey ncolKey = {0};
|
||||||
|
if (metaBuildNColIdxKey(&ncolKey, pME) < 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return tdbTbDelete(pMeta->pNcolIdx, &ncolKey, sizeof(ncolKey), &pMeta->txn);
|
||||||
|
}
|
||||||
|
|
||||||
static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq, STableMetaRsp *pMetaRsp) {
|
static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq, STableMetaRsp *pMetaRsp) {
|
||||||
void *pVal = NULL;
|
void *pVal = NULL;
|
||||||
|
@ -1325,6 +1386,12 @@ int metaHandleEntry(SMeta *pMeta, const SMetaEntry *pME) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (metaUpdateCtimeIdx(pMeta, pME) < 0) goto _err;
|
||||||
|
|
||||||
|
if (pME->type == TSDB_NORMAL_TABLE) {
|
||||||
|
if (metaUpdateNcolIdx(pMeta, pME) < 0) goto _err;
|
||||||
|
}
|
||||||
|
|
||||||
if (pME->type != TSDB_SUPER_TABLE) {
|
if (pME->type != TSDB_SUPER_TABLE) {
|
||||||
if (metaUpdateTtlIdx(pMeta, pME) < 0) goto _err;
|
if (metaUpdateTtlIdx(pMeta, pME) < 0) goto _err;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue