-
Notifications
You must be signed in to change notification settings - Fork 5k
calc subq to runner #34457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 3.0
Are you sure you want to change the base?
calc subq to runner #34457
Conversation
Summary of ChangesHello @stephenkgu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly extends the system's capabilities by introducing comprehensive support for subqueries within stream calculation plans. It involves fundamental changes to how query plans are structured and processed, from their definition in header files to their execution by runners. The changes ensure that subqueries can be correctly parsed, translated, serialized, and integrated into the overall stream processing workflow, enabling more advanced and flexible stream analytics. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces support for subqueries in stream calculations. The changes span across the parser, planner, and execution layers. A new field pSubQ is added to SSubplan to hold subquery information, and logic is added to build and manage runner tasks for these subqueries.
The overall approach is sound, but there are several areas for improvement:
- There are critical risks of NULL pointer dereferences due to missing checks on plan structures.
- The code contains some inefficiencies, such as repeated parsing of plan strings.
- There are also minor issues like commented-out code and an incorrect type cast that should be addressed.
Please review the detailed comments for specific suggestions.
| SNodeList* pSubEP = NULL; | ||
|
|
||
| TAOS_CHECK_EXIT(nodesStringToNode(pStream->pCreate->calcPlan, (SNode**)&pPlan)); | ||
| pSubQPlan = (SQueryPlan*)pPlan->pChildren->pHead->pNode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line accesses pPlan->pChildren->pHead->pNode without checking if pPlan->pChildren or pPlan->pChildren->pHead are NULL. This could lead to a NULL pointer dereference and a crash. Please add checks to handle this case gracefully.
if (pPlan->pChildren == NULL || pPlan->pChildren->pHead == NULL || pPlan->pChildren->pHead->pNode == NULL) {
mstsError("stream:%s invalid calc plan, no subquery plan found", pStream->pCreate->name);
code = TSDB_CODE_INVALID_SQL;
goto _exit;
}
pSubQPlan = (SQueryPlan*)pPlan->pChildren->pHead->pNode;| } | ||
|
|
||
| // TODO: for each subquery plan do the following plan xform | ||
| SQueryPlan* calcSubQPlan = ((SQueryPlan*)calcPlan ->pChildren ->pHead ->pNode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line accesses calcPlan->pChildren->pHead->pNode without any checks for NULL pointers. This is unsafe and can lead to a crash if pChildren or pHead is NULL. Please add validation to ensure these pointers are valid before dereferencing them.
if (calcPlan->pChildren == NULL || calcPlan->pChildren->pHead == NULL || calcPlan->pChildren->pHead->pNode == NULL) {
PAR_ERR_JRET(TSDB_CODE_INVALID_SQL);
}
SQueryPlan* calcSubQPlan = ((SQueryPlan*)calcPlan ->pChildren ->pHead ->pNode);| code = msmBuildRunnerTasksImpl(pCtx, pSubQPlan, pInfo, pStream, pPlan, &pSubEP); | ||
| pPlan = NULL; | ||
| TAOS_CHECK_EXIT(code); | ||
| TAOS_CHECK_EXIT(nodesStringToNode(pStream->pCreate->calcPlan, (SNode**)&pPlan)); | ||
| code = msmBuildRunnerTasksImpl(pCtx, pPlan, pInfo, pStream, pPlan, &pSubEP); | ||
| pPlan = NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The calculation plan is parsed from a string (nodesStringToNode) multiple times within this function and also within the called function msmBuildRunnerTasksImpl. This is inefficient. Consider parsing it once at the beginning, and if the plan needs to be modified by a function, pass a clone of the plan instead of destroying and re-parsing it. This would improve performance and make the data flow clearer.
| SDownstreamSourceNode* pSource = NULL; | ||
|
|
||
| for (int32_t i = 0; i < subTaskNum; ++i) { | ||
| SValueNode* pVal = (SValueNode*)nodesListGetNode(pSubplan->pSubQ, i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The node from pSubplan->pSubQ is cast to SValueNode*, but based on how it's created in mndStreamMgmt.c, it should be a SDownstreamSourceNode*. This cast is misleading and potentially incorrect. Please use the correct type, SDownstreamSourceNode*, or a generic SNode* to avoid confusion and potential bugs.
SNode* pVal = (SNode*)nodesListGetNode(pSubplan->pSubQ, i);| // SQueryPlan* calcSubQPlan = ((SQueryPlan*)pDag->pChildren->pHead->pNode); | ||
| // SNodeList* subQSubplans = calcSubQPlan->pSubplans; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (subQ) { | ||
| SStmTaskSrcAddr addr = {0}; | ||
| SDownstreamSourceNode* pSource = NULL; | ||
|
|
||
| TAOS_CHECK_EXIT(nodesMakeNode(QUERY_NODE_DOWNSTREAM_SOURCE, (SNode**)&pSource)); | ||
|
|
||
| addr.taskId = pDeploy->task.taskId; | ||
| addr.vgId = pDeploy->task.nodeId; | ||
| addr.groupId = plan->id.groupId; | ||
| addr.epset = mndGetDnodeEpsetById(pCtx->pMnode, pDeploy->task.nodeId); | ||
|
|
||
| pSource->addr.epSet = addr.epset; | ||
| pSource->addr.nodeId = addr.vgId; | ||
|
|
||
| pSource->clientId = streamId; | ||
| pSource->taskId = pDeploy->task.taskId; | ||
| pSource->sId = 0; | ||
| pSource->execId = 0; | ||
| pSource->fetchMsgType = TDMT_STREAM_FETCH_FROM_RUNNER; | ||
| pSource->localExec = false; | ||
|
|
||
| code = nodesListMakeStrictAppend(subEP, (SNode *)pSource); | ||
| if (code) { | ||
| TAOS_CHECK_EXIT(code); | ||
| } | ||
| } else { | ||
| TAOS_CHECK_EXIT(nodesCloneList(*subEP, &plan->pSubQ)); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| static int32_t msmUpdateCalcReaderTasks(SStreamObj* pStream, SNodeList* pSubEP) { | ||
| int32_t code = TSDB_CODE_SUCCESS; | ||
| int32_t lino = 0; | ||
| int64_t streamId = pStream->pCreate->streamId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // string to node | ||
| // for each subplan, adjoin subEP | ||
| // node to the string of calcScanPlan |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description
Issue(s)
Checklist
Please check the items in the checklist if applicable.