fix(planner): verify %%tbname to use single-table external window#35054
fix(planner): verify %%tbname to use single-table external window#35054guanshengliang merged 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request enhances stream query processing by correctly identifying single-table windows when the asSingleTable flag is set or when partitioning by table name. Key changes include the addition of helper functions and a new test case in parStreamTest.cpp, as well as logic updates in planLogicCreater.c. A review comment points out an inconsistency in createWindowLogicNodeByStreamExternal, suggesting the addition of a partition-by-tbname check to match the logic in createWindowLogicNodeByExternal.
| if (pTable->pMeta->tableType == TSDB_NORMAL_TABLE || pTable->pMeta->tableType == TSDB_CHILD_TABLE || | ||
| pTable->asSingleTable) { |
There was a problem hiding this comment.
The logic for determining isSingleTable in createWindowLogicNodeByStreamExternal is inconsistent with createWindowLogicNodeByExternal. While createWindowLogicNodeByExternal (line 2434) checks for both isPartTb (partition by tbname) and asSingleTable, this function only checks for asSingleTable. For consistency and to ensure that stream windows partitioned by table name are correctly identified as single-table windows even when the %%tbname placeholder is not explicitly used in the FROM clause, the partition check should be added here as well.
if (pTable->pMeta->tableType == TSDB_NORMAL_TABLE || pTable->pMeta->tableType == TSDB_CHILD_TABLE ||
pTable->asSingleTable || (pSelect->pPartitionByList && keysHasTbname(pSelect->pPartitionByList))) {There was a problem hiding this comment.
Pull request overview
Fixes planner single-table detection for external windows when the query uses the %%tbname placeholder (single-table external window should be selected in this case), addressing the linked defect.
Changes:
- Treat
SRealTableNode::asSingleTableas a sufficient condition to mark external window logic nodes asisSingleTable(both regular and stream external-window paths). - Add a parser test that builds a stream query using
%%tbname, deserializes the generated calc plan, and asserts the external window physical node is markedisSingleTable.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| source/libs/planner/src/planLogicCreater.c | Extends external-window single-table detection to honor asSingleTable for real tables. |
| source/libs/parser/test/parStreamTest.cpp | Adds regression test validating %%tbname produces a single-table external window in the calc plan. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
代码审查报告审查状态: completed 整体评估修复逻辑正确。在 已验证问题[LOW] 测试回调中 GTest 的
修复方向: 将 观察(历史遗留,非本 PR 引入,已过滤)
|
|
|
||
| SNode* pPlanNode = nullptr; | ||
| ASSERT_EQ(TSDB_CODE_SUCCESS, nodesStringToNode((char*)req.calcPlan, &pPlanNode)); | ||
| ASSERT_NE(pPlanNode, nullptr); |
There was a problem hiding this comment.
req(第 1706 行)分配后,ASSERT_* 在 GTest lambda 中失败时执行 return 直接退出 lambda,导致下方的 nodesDestroyNode(pPlanNode) 和 tFreeSCMCreateStreamReq(&req) 不会被执行。
同样的问题也存在于第 1707、1708、1711、1712 行的 ASSERT_* 调用。
建议: 将这几处 ASSERT_NE / ASSERT_EQ 改为 EXPECT_NE / EXPECT_EQ,使测试在断言失败后仍能执行到清理代码:
// 改为 EXPECT 系列,确保 cleanup 一定被执行
EXPECT_EQ(TSDB_CODE_SUCCESS, tDeserializeSCMCreateStreamReq(..., &req));
EXPECT_NE(req.calcPlan, nullptr);
if (!req.calcPlan) { tFreeSCMCreateStreamReq(&req); return; }
// ...或者把清理逻辑提前到一个 RAII guard 中(如 std::unique_ptr + 自定义 deleter)。
Description
fix(planner): verify %%tbname to use single-table external window
Issue(s)
Checklist
Please check the items in the checklist if applicable.