enh: fix index bug
This commit is contained in:
parent
a4cd6bfb9b
commit
39244e08ea
|
@ -31,7 +31,7 @@ void metaReaderClear(SMetaReader *pReader) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int metaGetTableEntryByVersion(SMetaReader *pReader, int64_t version, tb_uid_t uid) {
|
int metaGetTableEntryByVersion(SMetaReader *pReader, int64_t version, tb_uid_t uid) {
|
||||||
SMeta *pMeta = pReader->pMeta;
|
SMeta * pMeta = pReader->pMeta;
|
||||||
STbDbKey tbDbKey = {.version = version, .uid = uid};
|
STbDbKey tbDbKey = {.version = version, .uid = uid};
|
||||||
|
|
||||||
// query table.db
|
// query table.db
|
||||||
|
@ -54,7 +54,7 @@ _err:
|
||||||
}
|
}
|
||||||
|
|
||||||
int metaGetTableEntryByUid(SMetaReader *pReader, tb_uid_t uid) {
|
int metaGetTableEntryByUid(SMetaReader *pReader, tb_uid_t uid) {
|
||||||
SMeta *pMeta = pReader->pMeta;
|
SMeta * pMeta = pReader->pMeta;
|
||||||
int64_t version;
|
int64_t version;
|
||||||
|
|
||||||
// query uid.idx
|
// query uid.idx
|
||||||
|
@ -68,7 +68,7 @@ int metaGetTableEntryByUid(SMetaReader *pReader, tb_uid_t uid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int metaGetTableEntryByName(SMetaReader *pReader, const char *name) {
|
int metaGetTableEntryByName(SMetaReader *pReader, const char *name) {
|
||||||
SMeta *pMeta = pReader->pMeta;
|
SMeta * pMeta = pReader->pMeta;
|
||||||
tb_uid_t uid;
|
tb_uid_t uid;
|
||||||
|
|
||||||
// query name.idx
|
// query name.idx
|
||||||
|
@ -82,7 +82,7 @@ int metaGetTableEntryByName(SMetaReader *pReader, const char *name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
tb_uid_t metaGetTableEntryUidByName(SMeta *pMeta, const char *name) {
|
tb_uid_t metaGetTableEntryUidByName(SMeta *pMeta, const char *name) {
|
||||||
void *pData = NULL;
|
void * pData = NULL;
|
||||||
int nData = 0;
|
int nData = 0;
|
||||||
tb_uid_t uid = 0;
|
tb_uid_t uid = 0;
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ void metaCloseTbCursor(SMTbCursor *pTbCur) {
|
||||||
|
|
||||||
int metaTbCursorNext(SMTbCursor *pTbCur) {
|
int metaTbCursorNext(SMTbCursor *pTbCur) {
|
||||||
int ret;
|
int ret;
|
||||||
void *pBuf;
|
void * pBuf;
|
||||||
STbCfg tbCfg;
|
STbCfg tbCfg;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -155,7 +155,7 @@ int metaTbCursorNext(SMTbCursor *pTbCur) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline) {
|
SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline) {
|
||||||
void *pData = NULL;
|
void * pData = NULL;
|
||||||
int nData = 0;
|
int nData = 0;
|
||||||
int64_t version;
|
int64_t version;
|
||||||
SSchemaWrapper schema = {0};
|
SSchemaWrapper schema = {0};
|
||||||
|
@ -215,11 +215,11 @@ _err:
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SMCtbCursor {
|
struct SMCtbCursor {
|
||||||
SMeta *pMeta;
|
SMeta * pMeta;
|
||||||
TBC *pCur;
|
TBC * pCur;
|
||||||
tb_uid_t suid;
|
tb_uid_t suid;
|
||||||
void *pKey;
|
void * pKey;
|
||||||
void *pVal;
|
void * pVal;
|
||||||
int kLen;
|
int kLen;
|
||||||
int vLen;
|
int vLen;
|
||||||
};
|
};
|
||||||
|
@ -290,10 +290,10 @@ tb_uid_t metaCtbCursorNext(SMCtbCursor *pCtbCur) {
|
||||||
|
|
||||||
STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver) {
|
STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver) {
|
||||||
// SMetaReader mr = {0};
|
// SMetaReader mr = {0};
|
||||||
STSchema *pTSchema = NULL;
|
STSchema * pTSchema = NULL;
|
||||||
SSchemaWrapper *pSW = NULL;
|
SSchemaWrapper *pSW = NULL;
|
||||||
STSchemaBuilder sb = {0};
|
STSchemaBuilder sb = {0};
|
||||||
SSchema *pSchema;
|
SSchema * pSchema;
|
||||||
|
|
||||||
pSW = metaGetTableSchema(pMeta, uid, sver, 0);
|
pSW = metaGetTableSchema(pMeta, uid, sver, 0);
|
||||||
if (!pSW) return NULL;
|
if (!pSW) return NULL;
|
||||||
|
@ -319,11 +319,11 @@ int metaGetTbNum(SMeta *pMeta) {
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
SMeta *pMeta;
|
SMeta * pMeta;
|
||||||
TBC *pCur;
|
TBC * pCur;
|
||||||
tb_uid_t uid;
|
tb_uid_t uid;
|
||||||
void *pKey;
|
void * pKey;
|
||||||
void *pVal;
|
void * pVal;
|
||||||
int kLen;
|
int kLen;
|
||||||
int vLen;
|
int vLen;
|
||||||
} SMSmaCursor;
|
} SMSmaCursor;
|
||||||
|
@ -395,7 +395,7 @@ tb_uid_t metaSmaCursorNext(SMSmaCursor *pSmaCur) {
|
||||||
|
|
||||||
STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid, bool deepCopy) {
|
STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid, bool deepCopy) {
|
||||||
STSmaWrapper *pSW = NULL;
|
STSmaWrapper *pSW = NULL;
|
||||||
SArray *pSmaIds = NULL;
|
SArray * pSmaIds = NULL;
|
||||||
|
|
||||||
if (!(pSmaIds = metaGetSmaIdsByTable(pMeta, uid))) {
|
if (!(pSmaIds = metaGetSmaIdsByTable(pMeta, uid))) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -419,7 +419,7 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid, bool deepCopy) {
|
||||||
metaReaderInit(&mr, pMeta, 0);
|
metaReaderInit(&mr, pMeta, 0);
|
||||||
int64_t smaId;
|
int64_t smaId;
|
||||||
int smaIdx = 0;
|
int smaIdx = 0;
|
||||||
STSma *pTSma = NULL;
|
STSma * pTSma = NULL;
|
||||||
for (int i = 0; i < pSW->number; ++i) {
|
for (int i = 0; i < pSW->number; ++i) {
|
||||||
smaId = *(tb_uid_t *)taosArrayGet(pSmaIds, i);
|
smaId = *(tb_uid_t *)taosArrayGet(pSmaIds, i);
|
||||||
if (metaGetTableEntryByUid(&mr, smaId) < 0) {
|
if (metaGetTableEntryByUid(&mr, smaId) < 0) {
|
||||||
|
@ -467,7 +467,7 @@ _err:
|
||||||
}
|
}
|
||||||
|
|
||||||
STSma *metaGetSmaInfoByIndex(SMeta *pMeta, int64_t indexUid) {
|
STSma *metaGetSmaInfoByIndex(SMeta *pMeta, int64_t indexUid) {
|
||||||
STSma *pTSma = NULL;
|
STSma * pTSma = NULL;
|
||||||
SMetaReader mr = {0};
|
SMetaReader mr = {0};
|
||||||
metaReaderInit(&mr, pMeta, 0);
|
metaReaderInit(&mr, pMeta, 0);
|
||||||
if (metaGetTableEntryByUid(&mr, indexUid) < 0) {
|
if (metaGetTableEntryByUid(&mr, indexUid) < 0) {
|
||||||
|
@ -489,7 +489,7 @@ STSma *metaGetSmaInfoByIndex(SMeta *pMeta, int64_t indexUid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SArray *metaGetSmaIdsByTable(SMeta *pMeta, tb_uid_t uid) {
|
SArray *metaGetSmaIdsByTable(SMeta *pMeta, tb_uid_t uid) {
|
||||||
SArray *pUids = NULL;
|
SArray * pUids = NULL;
|
||||||
SSmaIdxKey *pSmaIdxKey = NULL;
|
SSmaIdxKey *pSmaIdxKey = NULL;
|
||||||
|
|
||||||
SMSmaCursor *pCur = metaOpenSmaCursor(pMeta, uid);
|
SMSmaCursor *pCur = metaOpenSmaCursor(pMeta, uid);
|
||||||
|
@ -527,7 +527,7 @@ SArray *metaGetSmaIdsByTable(SMeta *pMeta, tb_uid_t uid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SArray *metaGetSmaTbUids(SMeta *pMeta) {
|
SArray *metaGetSmaTbUids(SMeta *pMeta) {
|
||||||
SArray *pUids = NULL;
|
SArray * pUids = NULL;
|
||||||
SSmaIdxKey *pSmaIdxKey = NULL;
|
SSmaIdxKey *pSmaIdxKey = NULL;
|
||||||
tb_uid_t lastUid = 0;
|
tb_uid_t lastUid = 0;
|
||||||
|
|
||||||
|
@ -589,19 +589,21 @@ const void *metaGetTableTagVal(SMetaEntry *pEntry, int16_t type, STagVal *val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
SMeta *pMeta;
|
SMeta * pMeta;
|
||||||
TBC *pCur;
|
TBC * pCur;
|
||||||
tb_uid_t suid;
|
tb_uid_t suid;
|
||||||
int16_t cid;
|
int16_t cid;
|
||||||
int16_t type;
|
int16_t type;
|
||||||
void *pKey;
|
void * pKey;
|
||||||
void *pVal;
|
void * pVal;
|
||||||
int32_t kLen;
|
int32_t kLen;
|
||||||
int32_t vLen;
|
int32_t vLen;
|
||||||
} SIdxCursor;
|
} SIdxCursor;
|
||||||
|
|
||||||
int32_t metaFilteTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) {
|
int32_t metaFilteTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) {
|
||||||
SIdxCursor *pCursor = NULL;
|
SIdxCursor *pCursor = NULL;
|
||||||
|
char * buf = NULL;
|
||||||
|
int32_t maxSize = 0;
|
||||||
|
|
||||||
int32_t ret = 0, valid = 0;
|
int32_t ret = 0, valid = 0;
|
||||||
pCursor = (SIdxCursor *)taosMemoryCalloc(1, sizeof(SIdxCursor));
|
pCursor = (SIdxCursor *)taosMemoryCalloc(1, sizeof(SIdxCursor));
|
||||||
|
@ -619,17 +621,29 @@ int32_t metaFilteTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) {
|
||||||
int32_t nKey = 0;
|
int32_t nKey = 0;
|
||||||
|
|
||||||
int32_t nTagData = 0;
|
int32_t nTagData = 0;
|
||||||
void *tagData = NULL;
|
void * tagData = NULL;
|
||||||
|
|
||||||
if (IS_VAR_DATA_TYPE(param->type)) {
|
if (IS_VAR_DATA_TYPE(param->type)) {
|
||||||
tagData = varDataVal(param->val);
|
tagData = varDataVal(param->val);
|
||||||
nTagData = varDataLen(param->val);
|
nTagData = varDataLen(param->val);
|
||||||
|
|
||||||
|
if (param->type == TSDB_DATA_TYPE_NCHAR) {
|
||||||
|
maxSize = 4 * nTagData + 1;
|
||||||
|
buf = taosMemoryCalloc(1, maxSize);
|
||||||
|
if (false == taosMbsToUcs4(tagData, nTagData, (TdUcs4 *)buf, maxSize, &maxSize)) {
|
||||||
|
goto END;
|
||||||
|
}
|
||||||
|
|
||||||
|
tagData = buf;
|
||||||
|
nTagData = maxSize;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
tagData = param->val;
|
tagData = param->val;
|
||||||
nTagData = tDataTypes[param->type].bytes;
|
nTagData = tDataTypes[param->type].bytes;
|
||||||
}
|
}
|
||||||
ret = metaCreateTagIdxKey(pCursor->suid, pCursor->cid, tagData, nTagData, pCursor->type,
|
ret = metaCreateTagIdxKey(pCursor->suid, pCursor->cid, tagData, nTagData, pCursor->type,
|
||||||
param->reverse ? INT64_MAX : INT64_MIN, &pKey, &nKey);
|
param->reverse ? INT64_MAX : INT64_MIN, &pKey, &nKey);
|
||||||
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
|
@ -638,7 +652,7 @@ int32_t metaFilteTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) {
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *entryKey = NULL, *entryVal = NULL;
|
void * entryKey = NULL, *entryVal = NULL;
|
||||||
int32_t nEntryKey, nEntryVal;
|
int32_t nEntryKey, nEntryVal;
|
||||||
while (1) {
|
while (1) {
|
||||||
valid = tdbTbcGet(pCursor->pCur, (const void **)&entryKey, &nEntryKey, (const void **)&entryVal, &nEntryVal);
|
valid = tdbTbcGet(pCursor->pCur, (const void **)&entryKey, &nEntryKey, (const void **)&entryVal, &nEntryVal);
|
||||||
|
@ -672,6 +686,7 @@ int32_t metaFilteTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) {
|
||||||
END:
|
END:
|
||||||
if (pCursor->pMeta) metaULock(pCursor->pMeta);
|
if (pCursor->pMeta) metaULock(pCursor->pMeta);
|
||||||
if (pCursor->pCur) tdbTbcClose(pCursor->pCur);
|
if (pCursor->pCur) tdbTbcClose(pCursor->pCur);
|
||||||
|
taosMemoryFree(buf);
|
||||||
|
|
||||||
taosMemoryFree(pCursor);
|
taosMemoryFree(pCursor);
|
||||||
|
|
||||||
|
|
|
@ -180,15 +180,17 @@ static int32_t sifInitJsonParam(SNode *node, SIFParam *param, SIFCtx *ctx) {
|
||||||
// memcpy(param->colName, l->colName, sizeof(l->colName));
|
// memcpy(param->colName, l->colName, sizeof(l->colName));
|
||||||
}
|
}
|
||||||
static int32_t sifInitParam(SNode *node, SIFParam *param, SIFCtx *ctx) {
|
static int32_t sifInitParam(SNode *node, SIFParam *param, SIFCtx *ctx) {
|
||||||
|
param->status = SFLT_COARSE_INDEX;
|
||||||
switch (nodeType(node)) {
|
switch (nodeType(node)) {
|
||||||
case QUERY_NODE_VALUE: {
|
case QUERY_NODE_VALUE: {
|
||||||
SValueNode *vn = (SValueNode *)node;
|
SValueNode *vn = (SValueNode *)node;
|
||||||
|
if (vn->typeData == TSDB_DATA_TYPE_NULL) {
|
||||||
|
param->status = SFLT_NOT_INDEX;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
SIF_ERR_RET(sifGetValueFromNode(node, ¶m->condValue));
|
SIF_ERR_RET(sifGetValueFromNode(node, ¶m->condValue));
|
||||||
param->colId = -1;
|
param->colId = -1;
|
||||||
param->colValType = (uint8_t)(vn->node.resType.type);
|
param->colValType = (uint8_t)(vn->node.resType.type);
|
||||||
if (vn->literal == NULL || strlen(vn->literal) == 0) {
|
|
||||||
return TSDB_CODE_QRY_INVALID_INPUT;
|
|
||||||
}
|
|
||||||
memcpy(param->colName, vn->literal, strlen(vn->literal));
|
memcpy(param->colName, vn->literal, strlen(vn->literal));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -517,9 +519,17 @@ static int32_t sifExecOper(SOperatorNode *node, SIFCtx *ctx, SIFParam *output) {
|
||||||
// ugly code, refactor later
|
// ugly code, refactor later
|
||||||
output->arg = ctx->arg;
|
output->arg = ctx->arg;
|
||||||
sif_func_t operFn = sifNullFunc;
|
sif_func_t operFn = sifNullFunc;
|
||||||
code = sifGetOperFn(node->opType, &operFn, &output->status);
|
|
||||||
if (!ctx->noExec) {
|
if (!ctx->noExec) {
|
||||||
code = operFn(¶ms[0], nParam > 1 ? ¶ms[1] : NULL, output);
|
SIF_ERR_RET(sifGetOperFn(node->opType, &operFn, &output->status));
|
||||||
|
SIF_ERR_RET(operFn(¶ms[0], nParam > 1 ? ¶ms[1] : NULL, output));
|
||||||
|
} else {
|
||||||
|
// ugly code, refactor later
|
||||||
|
if (nParam > 1 && params[1].status == SFLT_NOT_INDEX) {
|
||||||
|
output->status = SFLT_NOT_INDEX;
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
SIF_ERR_RET(sifGetOperFn(node->opType, &operFn, &output->status));
|
||||||
}
|
}
|
||||||
|
|
||||||
taosMemoryFree(params);
|
taosMemoryFree(params);
|
||||||
|
@ -595,7 +605,7 @@ static EDealRes sifWalkLogic(SNode *pNode, void *context) {
|
||||||
}
|
}
|
||||||
static EDealRes sifWalkOper(SNode *pNode, void *context) {
|
static EDealRes sifWalkOper(SNode *pNode, void *context) {
|
||||||
SOperatorNode *node = (SOperatorNode *)pNode;
|
SOperatorNode *node = (SOperatorNode *)pNode;
|
||||||
SIFParam output = {.result = taosArrayInit(8, sizeof(uint64_t))};
|
SIFParam output = {.result = taosArrayInit(8, sizeof(uint64_t)), .status = SFLT_COARSE_INDEX};
|
||||||
|
|
||||||
SIFCtx *ctx = context;
|
SIFCtx *ctx = context;
|
||||||
ctx->code = sifExecOper(node, ctx, &output);
|
ctx->code = sifExecOper(node, ctx, &output);
|
||||||
|
|
Loading…
Reference in New Issue