enh: optimize tbname condition
This commit is contained in:
parent
ad7c3218f7
commit
70761fd959
|
@ -1082,7 +1082,7 @@ int32_t ctgUpdateUserEnqueue(SCatalog *pCtg, SGetUserAuthRsp *pAuth, bool syncOp
|
|||
if (NULL == msg) {
|
||||
ctgError("malloc %d failed", (int32_t)sizeof(SCtgUpdateUserMsg));
|
||||
taosMemoryFree(op);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
msg->pCtg = pCtg;
|
||||
|
|
|
@ -30,6 +30,11 @@
|
|||
|
||||
#define SYSTABLE_SHOW_TYPE_OFFSET QUERY_NODE_SHOW_DNODES_STMT
|
||||
|
||||
typedef struct SRewriteTbNameContext {
|
||||
int32_t errCode;
|
||||
char* pTbName;
|
||||
} SRewriteTbNameContext;
|
||||
|
||||
typedef struct STranslateContext {
|
||||
SParseContext* pParseCxt;
|
||||
int32_t errCode;
|
||||
|
@ -2541,6 +2546,64 @@ static int32_t setTableCacheLastMode(STranslateContext* pCxt, SSelectStmt* pSele
|
|||
return code;
|
||||
}
|
||||
|
||||
static EDealRes doTranslateTbName(SNode** pNode, void* pContext) {
|
||||
switch (nodeType(*pNode)) {
|
||||
case QUERY_NODE_FUNCTION: {
|
||||
SFunctionNode *pFunc = (SFunctionNode *)*pNode;
|
||||
if (FUNCTION_TYPE_TBNAME == pFunc->funcType) {
|
||||
SRewriteTbNameContext *pCxt = (SRewriteTbNameContext*)pContext;
|
||||
SValueNode* pVal = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE);
|
||||
if (NULL == pVal) {
|
||||
pCxt->errCode = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
|
||||
int32_t tbLen = strlen(pCxt->pTbName);
|
||||
pVal->literal = taosStrdup(pCxt->pTbName);
|
||||
if (NULL == pVal->literal) {
|
||||
pCxt->errCode = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
pVal->isDuration = false;
|
||||
pVal->translate = true;
|
||||
pVal->node.resType.type = TSDB_DATA_TYPE_BINARY;
|
||||
pVal->node.resType.bytes = tbLen + VARSTR_HEADER_SIZE;
|
||||
pVal->datum.p = taosMemoryCalloc(1, tbLen + VARSTR_HEADER_SIZE + 1);
|
||||
varDataSetLen(pVal->datum.p, tbLen);
|
||||
strncpy(varDataVal(pVal->datum.p), pVal->literal, tbLen);
|
||||
strcpy(pVal->node.userAlias, pFunc->node.userAlias);
|
||||
strcpy(pVal->node.aliasName, pFunc->node.aliasName);
|
||||
|
||||
nodesDestroyNode(*pNode);
|
||||
*pNode = (SNode*)pVal;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
static int32_t replaceTbName(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
||||
if (QUERY_NODE_REAL_TABLE != nodeType(pSelect->pFromTable)) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SRealTableNode* pTable = (SRealTableNode*)pSelect->pFromTable;
|
||||
if (TSDB_CHILD_TABLE != pTable->pMeta->tableType && TSDB_NORMAL_TABLE != pTable->pMeta->tableType && TSDB_SYSTEM_TABLE != pTable->pMeta->tableType) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SNode** pNode = NULL;
|
||||
SRewriteTbNameContext pRewriteCxt = {0};
|
||||
pRewriteCxt.pTbName = pTable->table.tableName;
|
||||
|
||||
nodesRewriteExprPostOrder(&pSelect->pWhere, doTranslateTbName, &pRewriteCxt);
|
||||
|
||||
return pRewriteCxt.errCode;
|
||||
}
|
||||
|
||||
static int32_t checkJoinTable(STranslateContext* pCxt, SJoinTableNode* pJoinTable) {
|
||||
if ((QUERY_NODE_TEMP_TABLE == nodeType(pJoinTable->pLeft) &&
|
||||
!isTimeLineQuery(((STempTableNode*)pJoinTable->pLeft)->pSubquery)) ||
|
||||
|
@ -3649,6 +3712,10 @@ static int32_t translateSelectFrom(STranslateContext* pCxt, SSelectStmt* pSelect
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setTableCacheLastMode(pCxt, pSelect);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = replaceTbName(pCxt, pSelect);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue