enh: fix index bug

This commit is contained in:
yihaoDeng 2022-06-10 18:24:04 +08:00
parent a4cd6bfb9b
commit 39244e08ea
2 changed files with 58 additions and 33 deletions

View File

@ -602,6 +602,8 @@ typedef struct {
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));
@ -624,12 +626,24 @@ int32_t metaFilteTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) {
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;
} }
@ -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);

View File

@ -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, &param->condValue)); SIF_ERR_RET(sifGetValueFromNode(node, &param->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(&params[0], nParam > 1 ? &params[1] : NULL, output); SIF_ERR_RET(sifGetOperFn(node->opType, &operFn, &output->status));
SIF_ERR_RET(operFn(&params[0], nParam > 1 ? &params[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);