提交 576e3d11 编写于 作者: K kailixu

chore: erase duplicated func node for window logic node

上级 bcac24b6
......@@ -4940,7 +4940,7 @@ static int32_t buildTableForSampleAst(SSampleAstInfo* pInfo, SNode** pOutput) {
}
snprintf(pTable->table.dbName, sizeof(pTable->table.dbName), "%s", pInfo->pDbName);
snprintf(pTable->table.tableName, sizeof(pTable->table.tableName), "%s", pInfo->pTableName);
snprintf(pTable->table.tableAlias, sizeof(pTable->table.tableName), "%s", pInfo->pTableName);
snprintf(pTable->table.tableAlias, sizeof(pTable->table.tableAlias), "%s", pInfo->pTableName);
TSWAP(pTable->pMeta, pInfo->pRollupTableMeta);
*pOutput = (SNode*)pTable;
return TSDB_CODE_SUCCESS;
......
......@@ -749,6 +749,25 @@ static int32_t createWindowLogicNodeFinalize(SLogicPlanContext* pCxt, SSelectStm
code = rewriteExprsForSelect(pWindow->pFuncs, pSelect, SQL_CLAUSE_WINDOW, NULL);
}
// erase duplicated funcNode by filtering colNode in pSelect->pProjectionList
int32_t funcIndex = 0;
SNode * pFunc = NULL, *pProject = NULL;
FOREACH(pFunc, pWindow->pFuncs) {
bool exist = false;
FOREACH(pProject, pSelect->pProjectionList) {
if (0 != ((SFunctionNode*)pFunc)->node.aliasName[0] &&
0 == strncmp(((SFunctionNode*)pFunc)->node.aliasName, ((SColumnNode*)pProject)->colName, TSDB_COL_NAME_LEN)) {
exist = true;
break;
}
}
if (!exist) {
nodesListErase(pWindow->pFuncs, nodesListGetCell(pWindow->pFuncs, funcIndex));
} else {
++funcIndex;
}
}
if (TSDB_CODE_SUCCESS == code) {
code = createColumnByRewriteExprs(pWindow->pFuncs, &pWindow->node.pTargets);
}
......
......@@ -1385,18 +1385,7 @@ static SNode* smaIndexOptFindWStartFunc(SNodeList* pSmaFuncs) {
return NULL;
}
static SNode* smaIndexOptFuncInProject(SNodeList* pProjects, SFunctionNode* pFunc) {
SNode* pProject = NULL;
FOREACH(pProject, pProjects) {
if (0 != pFunc->node.aliasName[0] &&
0 == strncmp(pFunc->node.aliasName, ((SColumnNode*)pProject)->colName, TSDB_COL_NAME_LEN)) {
return pProject;
}
}
return NULL;
}
static int32_t smaIndexOptCreateSmaCols(SWindowLogicNode* pWindow, uint64_t tableId, SNodeList* pSmaFuncs,
static int32_t smaIndexOptCreateSmaCols(SNodeList* pFuncs, uint64_t tableId, SNodeList* pSmaFuncs,
SNodeList** pOutput) {
SNodeList* pCols = NULL;
SNode* pFunc = NULL;
......@@ -1404,16 +1393,11 @@ static int32_t smaIndexOptCreateSmaCols(SWindowLogicNode* pWindow, uint64_t tabl
int32_t index = 0;
int32_t smaFuncIndex = -1;
bool hasWStart = false;
SProjectLogicNode* pProject = (SProjectLogicNode*)pWindow->node.pParent;
FOREACH(pFunc, pWindow->pFuncs) {
FOREACH(pFunc, pFuncs) {
smaFuncIndex = smaIndexOptFindSmaFunc(pFunc, pSmaFuncs);
if (smaFuncIndex < 0) {
break;
} else {
if (pProject && !smaIndexOptFuncInProject(pProject->pProjections, (SFunctionNode*)pFunc)) {
continue;
}
code = nodesListMakeStrictAppend(&pCols, smaIndexOptCreateSmaCol(pFunc, tableId, smaFuncIndex + 1));
if (TSDB_CODE_SUCCESS != code) {
break;
......@@ -1460,11 +1444,10 @@ static int32_t smaIndexOptCouldApplyIndex(SScanLogicNode* pScan, STableIndexInfo
if (!smaIndexOptEqualInterval(pScan, pWindow, pIndex)) {
return TSDB_CODE_SUCCESS;
}
SNodeList* pSmaFuncs = NULL;
int32_t code = nodesStringToList(pIndex->expr, &pSmaFuncs);
if (TSDB_CODE_SUCCESS == code) {
code = smaIndexOptCreateSmaCols(pWindow, pIndex->dstTbUid, pSmaFuncs, pCols);
code = smaIndexOptCreateSmaCols(pWindow->pFuncs, pIndex->dstTbUid, pSmaFuncs, pCols);
}
nodesDestroyList(pSmaFuncs);
return code;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册