Skip to content

enh: [6492510964] Virtual super table window optimize for interval/session/event - #34690

Merged
guanshengliang merged 1 commit into
3.0from
enh/3.0/6492510964
Mar 9, 2026
Merged

guanshengliang merged 1 commit into
3.0from
enh/3.0/6492510964

Conversation

@Simon9997

@Simon9997 Simon9997 commented Mar 5, 2026

Copy link
Copy Markdown
Contributor

Description

Issue(s)

Checklist

Please check the items in the checklist if applicable.

  • Is the user manual updated?
  • Are the test cases passed and automated?
  • Is there no significant decrease in test coverage?

Copilot AI review requested due to automatic review settings March 5, 2026 09:33
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 delivers a major enhancement to virtual super table window queries by introducing specialized optimizations for INTERVAL, SESSION, and EVENT window types. The core changes involve expanding the dynamic query type system, refining memory allocation practices, and overhauling the query planning and execution phases to efficiently process these complex windowing functions. The goal is to significantly improve the performance and robustness of window operations on virtual tables.

Highlights

  • New Dynamic Query Types: Introduced DYN_QTYPE_VTB_TS_SCAN and DYN_QTYPE_VTB_INTERVAL to support new virtual table windowing operations.
  • Virtual Table Window Optimization: Implemented significant optimizations for INTERVAL, SESSION, and EVENT window queries on virtual super tables, including new planning and execution strategies.
  • Improved Memory Management: Switched several taosMemoryMalloc calls to taosMemoryCalloc for operator parameters to ensure zero-initialization, and enhanced cleanup logic for various operator parameters and data structures.
  • Refactored Data Block Handling: Introduced getNextBlockFromDownstreamRemainDetach for more controlled data block retrieval and updated several operators to use it, preventing potential issues with shared data blocks.
  • Enhanced EXPLAIN Output: Modified qExplainGetDynQryCtrlType to correctly display the new virtual table types in query explanation plans.
  • Dynamic Operator Parameter Building: Added new functions like buildMergeOperatorParamForTsScan, buildHashIntervalOperatorParam, and buildIntervalOperatorParam to construct parameters for the new dynamic query types.
  • Updated Query Execution Logic: Implemented vtbTsScanNext and vtbIntervalNext functions to handle the execution flow for virtual table TS scan and interval queries, respectively.
  • Comprehensive Plan Optimizer Refactoring: The planOptimizer.c file underwent extensive changes, introducing new helper functions and a dispatch mechanism in vstableWindowOptimize to apply specific optimizations based on the window type (INTERVAL, SESSION, EVENT, STATE).
  • New Test Cases: Added new EXPLAIN and SELECT test cases for event, interval, and session windows, along with a dedicated test file (test_vtable_query_boundary.py) for boundary conditions in event window queries.

🧠 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.

Changelog
  • include/libs/nodes/querynodes.h
    • Added DYN_QTYPE_VTB_TS_SCAN and DYN_QTYPE_VTB_INTERVAL to EDynQueryType enum.
  • source/common/src/msg/tmsg.c
    • Updated tSerializeSOperatorParam and tDeserializeSOperatorParam to include new physical plan types for hash interval, merge, and table merge scan.
  • source/common/src/tdatablock.c
    • Populated dataLoad and scanFlag fields in the destination data block's information.
  • source/libs/command/src/explain.c
    • Modified qExplainGetDynQryCtrlType to accept SDynQueryCtrlPhysiNode* and display new virtual table types (Virtual Stable Interval, Virtual Stable Ts Scan).
  • source/libs/executor/inc/executorInt.h
    • Added EX_SRC_TYPE_VSTB_TS_SCAN, EX_SRC_TYPE_VSTB_INTERVAL_SCAN, and EX_SRC_TYPE_VSTB_PART_INTERVAL_SCAN to EExchangeSourceType enum.
  • source/libs/executor/inc/operator.h
    • Declared getNextBlockFromDownstreamRemainDetach function.
  • source/libs/executor/src/aggregateoperator.c
    • Replaced getNextBlockFromDownstreamRemain with getNextBlockFromDownstreamRemainDetach for data block retrieval.
  • source/libs/executor/src/dynqueryctrloperator.c
    • Updated destroyDynQueryCtrlOperator to correctly destroy vtbScan for DYN_QTYPE_VTB_WINDOW and added DYN_QTYPE_VTB_INTERVAL to destroyVtbScanDynCtrlInfo.
    • Changed multiple taosMemoryMalloc calls to taosMemoryCalloc for operator parameter initialization.
    • Modified buildBatchExchangeOperatorParamForVirtual to accept a source operator type.
    • Enhanced memory cleanup for child operator parameters in buildExternalWindowOperatorParam and buildMergeOperatorParam.
    • Added new functions buildMergeOperatorParamForTsScan, buildHashIntervalOperatorParam, buildSplitIntervalMergeOperatorParam, buildSplitIntervalOperatorParam, and buildIntervalOperatorParam for TS scan and interval operations.
    • Extended buildVirtualSuperTableScanChildTableMap to include DYN_QTYPE_VTB_INTERVAL and DYN_QTYPE_VTB_TS_SCAN in mapping logic.
    • Introduced vtbDefaultOpen and vtbTsScanNext functions for virtual table TS scan processing.
    • Adjusted vtbWindowOpen to correctly handle window batch numbers and boundary keys using TMAX/TMIN.
    • Modified vtbWindowNext to apply TMAX/TMIN for window boundary calculations.
    • Expanded resetDynQueryCtrlOperState to cover DYN_QTYPE_VTB_TS_SCAN and DYN_QTYPE_VTB_INTERVAL.
    • Removed vtbAggOpen and integrated its functionality into vtbDefaultOpen.
    • Added vtbIntervalNext function for virtual table interval processing.
    • Updated createDynQueryCtrlOperatorInfo to utilize vtbTsScanNext and vtbIntervalNext with vtbDefaultOpen.
  • source/libs/executor/src/eventwindowoperator.c
    • Set dataLoad flag to 1 in the result data block for event window aggregation.
  • source/libs/executor/src/exchangeoperator.c
    • Replaced taosMemoryMalloc with taosMemoryCalloc for several operator parameter allocations.
    • Refactored buildAggOperatorParam to use taosMemoryCalloc and simplify its logic.
    • Added buildIntervalOperatorParam for interval operator parameter construction.
    • Introduced clearVtbScanDataInfo to properly deallocate virtual table scan data.
    • Updated doSendFetchDataRequest to use clearVtbScanDataInfo and handle new exchange source types, adding error handling for pWrapper.
    • Removed a redundant clearVtbScanDataInfo definition.
    • Modified addSingleExchangeSource to skip non-matching vgId for specific virtual stable scan types and extended its switch statement.
  • source/libs/executor/src/executorInt.c
    • Expanded freeOperatorParam to include new physical plan types for table merge scan, hash interval, and merge interval.
    • Added debug logging to freeOperatorParam, freeResetOperatorParams, and getNextBlockFromDownstreamImpl.
  • source/libs/executor/src/externalwindowoperator.c
    • Switched to getNextBlockFromDownstreamRemainDetach for fetching data blocks.
  • source/libs/executor/src/mergeoperator.c
    • Enhanced error handling and added debug logging to sortMergeloadNextDataBlock and openSortMergeOperator.
  • source/libs/executor/src/operator.c
    • Modified createOperator to handle dynamic operations for QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN.
    • Implemented getNextBlockFromDownstreamRemainDetachImpl and getNextBlockFromDownstreamRemainDetach for detached data block retrieval.
  • source/libs/executor/src/scanoperator.c
    • Removed unused isDynVtbScan and freeTableCachedValObj functions.
    • Added findMatchSlotIdByColId to locate column match items by ID.
    • Updated createVTableScanInfoFromBatchParam to use pMatchList for column mapping and ensure timestamp mapping.
    • Ensured pMatchList is properly destroyed in createVTableScanInfoFromBatchParam error handling.
    • Initialized found boolean in blockSetVstbSlotId loop.
    • Modified dumpQueryTableCond to correctly handle pSlotList and colList memory management.
    • Introduced setSubTableCondSuidByUid to set sub-table condition SUID by UID.
    • Updated initSubTableInputs to use setSubTableCondSuidByUid for sub-table conditions.
    • Replaced direct taosMemoryFree with cleanupQueryTableDataCond for sub-table condition cleanup.
    • Added stopDurationForGroupTableMergeScan and createVTableMergeScanInfoFromBatchParam for dynamic table merge scan.
    • Modified doTableMergeScanParaSubTablesNext to process dynamic parameters and call createVTableMergeScanInfoFromBatchParam.
    • Removed a redundant stopDurationForGroupTableMergeScan definition.
    • Updated createTableMergeScanOperatorInfo to initialize orgCond and cond for dynamic operations and use doTableMergeScanParaSubTablesNext conditionally.
  • source/libs/executor/src/timewindowoperator.c
    • Replaced getNextBlockFromDownstream with getNextBlockFromDownstreamRemainDetach in doOpenIntervalAgg and doMergeAlignedIntervalAgg.
    • Set dataLoad flag to 1 in the result data block for state window aggregation and session window aggregation.
    • Updated doBuildIntervalResultNext to handle dynamic parameters and reset operator state.
  • source/libs/executor/src/virtualtablescanoperator.c
    • Removed tsSlotId parameter from getTimeWindowOfBlock function.
    • Simplified createSortHandleFromParam by removing a conditional check and casting i to int64_t.
    • Changed colNum type to size_t in doGetVStableMergedBlockData.
    • Corrected the function signature for virtualTableGetNext.
  • source/libs/function/src/builtinsimpl.c
    • Added a check for zero rows in funcInputGetNextRowIndex to prevent out-of-bounds access.
  • source/libs/nodes/src/nodesCodeFuncs.c
    • Included DYN_QTYPE_VTB_TS_SCAN and DYN_QTYPE_VTB_INTERVAL in JSON serialization/deserialization for dynamic query control nodes.
  • source/libs/nodes/src/nodesMsgFuncs.c
    • Included DYN_QTYPE_VTB_TS_SCAN and DYN_QTYPE_VTB_INTERVAL in message serialization for dynamic query control nodes.
  • source/libs/nodes/src/nodesUtilFuncs.c
    • Extended nodesDestroyNode to handle DYN_QTYPE_VTB_INTERVAL and DYN_QTYPE_VTB_TS_SCAN for proper cleanup.
  • source/libs/planner/src/planOptimizer.c
    • Refactored column parameter checking for window functions into functionHasTagOrPkParam and functionHasTagParam.
    • Updated vtableWindowMayBeOptimized to use new tag/PK functions and support EVENT, SESSION, INTERVAL window types.
    • Added eventWindowHasNullCond and eventWindowContainsNullCond for handling NULL conditions in event windows.
    • Introduced helper functions hasTargetInColumnList, removeUselessTargetFromNodeByColumnList, createOrderByExprNode, createMergeScanNodeByScanNode, setSingleVgroupForMergeScan, appendSingleVgroupMergeScan, createMergeSortNodeForTsScan for plan optimization.
    • Modified createSortNodeForWinColScan to use createOrderByExprNode.
    • The main vstableWindowOptimize function now dispatches to vstableWindowOptimizeInterval or vstableWindowOptimizeImpl based on the window type.
    • Added rebuildScanColsAndTargetsByTsEnd, rebuildScanTargetsWithPrimaryTs, vstableIntervalWindowFuncsCanSplit, vstableIntervalScanNeedSplit, vstableWindowOptimizeIntervalOld, vstableWindowOptimizeIntervalSplit functions for interval window specific optimizations.
    • Updated rebuildVstbScanTargets to accept a generic SLogicNode* and handle timestamp primary key for window nodes.
  • source/libs/planner/src/planPhysiCreater.c
    • Included DYN_QTYPE_VTB_TS_SCAN and DYN_QTYPE_VTB_INTERVAL in createDynQueryCtrlPhysiNode and isDynVirtualStableAgg.
    • Set node.dynamicOp for exchange nodes created by createExchangePhysiNodeByMerge.
  • source/libs/planner/src/planSpliter.c
    • Improved error handling in splCreateExchangeNode.
    • Set pMerge->node.dynamicOp in stbSplCreateMergeNode.
    • Added a check for dynamicOp in smaIdxSplFindSplitNode.
    • Introduced SMergeTableScanSplitInfo, mergeTableScanFindSplitNode, and mergeTableScanSplit for splitting merge table scans.
    • Updated dynVirtualScanFindSplitNode to include DYN_QTYPE_VTB_TS_SCAN and DYN_QTYPE_VTB_INTERVAL.
    • Added SVstbIntervalSplitInfo, vstbIntervalFindSplitNode, and vstbIntervalSplit for virtual stable interval splitting.
    • Included MergeTableScanSplit and VStbIntervalSplit in the splitRuleSet.
  • test/cases/05-VirtualTables/ans/test_vtable_meta.ans
    • Updated expected output for information_schema queries to include db_name filtering.
  • test/cases/05-VirtualTables/in/test_vstable_plan_test_window_event.in
    • Added new EXPLAIN queries to test event window plans.
  • test/cases/05-VirtualTables/in/test_vstable_plan_test_window_interval.in
    • Added new EXPLAIN queries to test interval window plans.
  • test/cases/05-VirtualTables/in/test_vstable_plan_test_window_session.in
    • Added new EXPLAIN queries to test session window plans.
  • test/cases/05-VirtualTables/in/test_vstable_select_test_count.in
    • Added new SELECT queries for count window scenarios.
  • test/cases/05-VirtualTables/in/test_vstable_select_test_event.in
    • Added new SELECT queries for event window scenarios.
  • test/cases/05-VirtualTables/in/test_vstable_select_test_session.in
    • Added new SELECT queries for session window scenarios.
  • test/cases/05-VirtualTables/in/test_vtable_meta.in
    • Updated information_schema queries to filter by db_name.
  • test/cases/05-VirtualTables/test_vtable_plan_window_optimize.py
    • Added test runs for session, event, and interval window plans.
  • test/cases/05-VirtualTables/test_vtable_query_boundary.py
    • Added a new Python test file to cover boundary conditions for event window queries.
  • test/cases/05-VirtualTables/test_vtable_query_cross_db_stb_window.py
    • Enabled a previously commented-out test case test_vstable_select_test_state_mode_1.
  • test/cases/05-VirtualTables/test_vtable_query_same_db_stb_window.py
    • Removed teardown_class and enabled test_vstable_select_test_state_mode_1.
  • test/ci/cases.task
    • Included the new test_vtable_query_boundary.py in the continuous integration test suite.
  • test/new_test_framework/utils/common.py
    • Modified the taos command for parsing explain verbose true output to use extended regular expressions and improve filtering of irrelevant information.
Activity
  • Initial commit by Simon9997.
  • Code review and feedback provided, leading to further refinements and additions.
  • Refinements and additions to support new window types and optimizations.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enhances TDengine virtual super table “dynamic window” execution to support additional window types (interval/session/event) and improves robustness of dynamic operator parameter handling, with expanded regression/plan tests.

Changes:

  • Extend planner/executor dynamic-query-control support for virtual stable interval and virtual stable TS-scan paths (new dyn qTypes, new split rules, updated explain output).
  • Improve executor/operator parameter lifecycle handling for dynamic tasks (detach-style downstream fetching, broader param serialization/freeing, extra metadata carried in datablocks).
  • Expand test coverage for virtual-table window optimizations (new boundary regression test, additional interval/session/event queries and plan asserts).

Reviewed changes

Copilot reviewed 39 out of 46 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/new_test_framework/utils/common.py Updates CLI output normalization pipeline (sed patterns) for more stable golden comparisons.
test/ci/cases.task Adds new virtual table boundary test to CI task list.
test/cases/05-VirtualTables/test_vtable_query_same_db_stb_window.py Enables additional state-mode window query coverage in same-db vtable tests.
test/cases/05-VirtualTables/test_vtable_query_cross_db_stb_window.py Enables additional state-mode window query coverage in cross-db vtable tests.
test/cases/05-VirtualTables/test_vtable_query_boundary.py Adds boundary regression tests for optimized event-window behavior and TRUE_FOR semantics.
test/cases/05-VirtualTables/test_vtable_plan_window_optimize.py Adds plan testcases for session/event/interval window explain validation.
test/cases/05-VirtualTables/in/test_vtable_meta.in Narrows information_schema queries to the test database for deterministic output.
test/cases/05-VirtualTables/in/test_vstable_select_test_session.in Adds additional session-window query variants for vtable/vstable coverage.
test/cases/05-VirtualTables/in/test_vstable_select_test_event.in Adds additional event-window + TRUE_FOR query variants for vstable coverage.
test/cases/05-VirtualTables/in/test_vstable_select_test_count.in Adds additional count-window query variants for vstable coverage.
test/cases/05-VirtualTables/in/test_vstable_plan_test_window_session.in New explain-verbose inputs for session window optimization path(s).
test/cases/05-VirtualTables/in/test_vstable_plan_test_window_interval.in New explain-verbose inputs for interval window optimization path(s).
test/cases/05-VirtualTables/in/test_vstable_plan_test_window_event.in New explain-verbose inputs for event window optimization path(s).
test/cases/05-VirtualTables/ans/test_vtable_meta.ans Updates expected output for DB-filtered information_schema queries.
test/cases/05-VirtualTables/ans/test_vstable_select_test_state_mode_1.ans Updates expected window results after execution/optimization changes.
test/cases/05-VirtualTables/ans/test_vstable_plan_test_window_interval.ans Adds expected explain output for interval window optimization path(s).
source/libs/planner/src/planSpliter.c Adds split rules and dynamicOp propagation to support new vstable interval/ts-scan execution flows.
source/libs/planner/src/planPhysiCreater.c Extends dyn-query-control physical node creation for new vtb/vstable qTypes.
source/libs/planner/src/planOptimizer.c Broadens vstable window optimization eligibility and adds new plan rewrites for session/event/interval.
source/libs/nodes/src/nodesUtilFuncs.c Ensures new dyn qTypes free their scan-related structures on node destruction.
source/libs/nodes/src/nodesMsgFuncs.c Extends dyn-query-control message encoding for new vtb/vstable qTypes.
source/libs/nodes/src/nodesCodeFuncs.c Extends dyn-query-control JSON encode/decode for new vtb/vstable qTypes.
source/libs/function/src/builtinsimpl.c Avoids out-of-range access for empty inputs when primary key metadata is absent.
source/libs/executor/src/virtualtablescanoperator.c Adjusts vtable scan merge handling and parameter-driven loading behavior.
source/libs/executor/src/timewindowoperator.c Updates downstream fetching semantics for interval/session/state window operators and dynamic params.
source/libs/executor/src/scanoperator.c Adds dynamic vtable/table-merge scan support and improves batch param handling/copying of scan conds.
source/libs/executor/src/operator.c Adds “detach” downstream fetching helper and adjusts dynamic table-merge scan operator creation behavior.
source/libs/executor/src/mergeoperator.c Improves sort-merge operator open/load error handling and dynamic downstream param propagation.
source/libs/executor/src/externalwindowoperator.c Switches to detach-style downstream fetching for dynamic external window flows.
source/libs/executor/src/executorInt.c Extends operator-param freeing/logging and supports additional operator types for param management.
source/libs/executor/src/exchangeoperator.c Refactors/extends exchange param construction for new virtual stable scan modes (ts/interval/partition interval).
source/libs/executor/src/eventwindowoperator.c Ensures result datablock carries appropriate dataLoad metadata for event windows.
source/libs/executor/src/dynqueryctrloperator.c Adds new dyn qTypes execution paths (vtb ts scan, vtb interval) and related param generation.
source/libs/executor/src/aggregateoperator.c Switches to detach-style downstream fetching for grouped aggregation under dynamic modes.
source/libs/executor/inc/operator.h Declares new detach-style downstream fetching API.
source/libs/executor/inc/executorInt.h Adds new exchange source types for new vstable scan modes.
source/libs/command/src/explain.c Updates explain text for new dyn qTypes and refactors dyn-qtype formatting helper.
source/common/src/tdatablock.c Propagates scanFlag/dataLoad when composing datablocks from multiple sources.
source/common/src/msg/tmsg.c Extends operator-param serialization/deserialization for new operator types.
include/libs/nodes/querynodes.h Adds new EDynQueryType values for vtb ts-scan and vtb interval.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread source/libs/executor/src/dynqueryctrloperator.c

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 significant optimizations for virtual super table window queries, specifically for INTERVAL, SESSION, and EVENT windows. It refactors the query plan to handle these window types more efficiently by adding new dynamic query types, exchange source types, and operator logic. The changes also include a number of important bug fixes, such as memory leak corrections, logic fixes in window boundary calculations, and ensuring proper propagation of flags like dynamicOp. The code is also improved by consistently using taosMemoryCalloc for zero-initialized memory allocation and refactoring cleanup logic. Additionally, new tests have been added to cover the new functionality.

Comment thread source/libs/executor/src/operator.c
Comment thread source/libs/executor/src/scanoperator.c
Comment thread source/libs/executor/src/virtualtablescanoperator.c
@Simon9997

Copy link
Copy Markdown
Contributor Author

@copilot code review[agent]
你是 TDengine 数据库内核 maintainer。请对本次 C 代码 diff 做严格 review:

  • 按 P0/P1/P2/P3 分级列问题,必须给 file:line、触发条件、影响、修复建议(可含伪 diff)、验证方式
  • 强制覆盖:并发/锁顺序、内存与资源释放(错误路径)、UB/类型截断、错误码契约、磁盘/协议兼容、性能热路径
  • 给:回归风险场景 Top10 + 必补测试用例最小集合(含 sanitizer/压测/故障注入)

Copilot AI commented Mar 5, 2026

Copy link
Copy Markdown
Contributor

@Simon9997 I've opened a new pull request, #34691, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 39 out of 46 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread source/libs/executor/src/virtualtablescanoperator.c
@Simon9997
Simon9997 force-pushed the enh/3.0/6492510964 branch from 057f444 to 54bc0d8 Compare March 6, 2026 02:48
@Simon9997

Copy link
Copy Markdown
Contributor Author

@copilot
你是 TDengine(数据库内核)资深 maintainer,擅长 C、并发与性能调优。请对本次提交(diff)做极其严格的代码审查,目标是“最大化发现问题与回归风险”,宁可多提也不要漏。

【提交背景】

  • PR/commit 目的:<粘贴描述>
  • 影响模块:<例如:query/tsdb/vnode/wal/raft/rpc/udf/stream/optimizer/...>
  • 运行场景:<高并发写入/复杂查询/订阅/stream/集群/高基数 tag/冷热数据等>
  • 兼容性要求:<老版本协议/磁盘格式/元数据/配置/接口 ABI 等>
  • 性能预算:<延迟/吞吐/CPU/内存>
  • 我最担心的点:<例如:窗口计算、聚合、WAL、一致性、OOM、死锁>

【审查范围与原则】

  • 只基于本次 diff + 直接受影响的调用链做判断;不确定处必须标注“需要上下文”,并列出应查看的文件/函数。
  • 对所有新增/修改的函数:检查错误路径、资源释放、并发安全、边界条件、日志与指标。

【输出格式(强制)】

  1. “结论摘要”(<=5行):总体风险等级(高/中/低)+ 3 个最重要的问题
  2. “问题清单”按严重度排序:P0 必须改 / P1 强烈建议 / P2 建议 / P3 可选
    每条必须包含:
    • 位置:file:line 或 function
    • 触发条件:给出具体场景/输入/并发时序(尽量可复现)
    • 影响:正确性/一致性/崩溃/安全/性能/可维护性
    • 修复建议:给出可执行改法(必要时写出 C 代码片段或伪 diff)
    • 验证:建议的单测/集成测试/压测/故障注入点
  3. “回归风险矩阵”:列出最可能出问题的 5~10 个场景(读/写/compaction/重启/回放/扩缩容/网络抖动等)
  4. “必补测试清单”:最少测试用例集合(按优先级)+ 建议的 sanitizer/工具
  5. “性能与可观测性建议”:是否需要新增 metrics、trace、日志(避免泄露敏感信息)

【TDengine/C 内核专项检查清单(逐项覆盖,不要省略)】
A. 内存/资源

  • malloc/calloc/realloc 返回值检查;size 溢出;对齐;栈/堆生命周期
  • 所有错误路径是否释放:file fd、socket、mutex/cond、refcount、buf、result set、iterator
  • 是否有 double free / use-after-free / 野指针 / 未初始化读
  • 引用计数/对象池:增减是否成对;并发下是否安全

B. 并发/一致性

  • 锁顺序是否一致(死锁风险);锁粒度是否过大(性能)
  • 原子性/可见性:跨线程共享状态是否需要 atomic/barrier
  • 幂等:重试、重复消息、重放(WAL/raft/rpc)是否安全
  • 数据一致性:写入路径/查询路径/compaction/merge 对同一数据的视图是否一致

C. 错误处理/接口契约

  • 错误码是否符合项目约定;是否吞错;是否覆盖原始 errno
  • 返回值与 out 参数一致性;边界输入(0、-1、NULL、超大)
  • 日志级别与信息量:是否泄露 token/密码/用户数据;是否刷屏

D. 数据结构/序列化/磁盘格式

  • 编解码长度、字节序、对齐、版本字段;向后兼容与回滚
  • 变更是否影响磁盘格式/网络协议/元数据:必须显式标注并给迁移策略

E. 性能热点(数据库特有)

  • 热路径是否引入额外 memcpy/分配/锁/系统调用
  • 算法复杂度变化(O(n)→O(n²)等);tag/filter/聚合/窗口/排序路径
  • 批量化与缓存:是否破坏 cache locality;是否增加分支/虚函数式开销
  • 可能的内存膨胀:高基数 tag、超大结果集、长窗口

F. 可移植性/编译

  • gcc/clang、不同平台宏、UB(移位、类型截断、未对齐访问)
  • -Wall/-Wextra 潜在告警;格式化字符串与类型匹配(PRIu64等)

Copilot AI commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

@Simon9997 I've opened a new pull request, #34694, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 41 out of 50 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Simon9997
Simon9997 force-pushed the enh/3.0/6492510964 branch from cda01bd to eb4c5ad Compare March 9, 2026 00:28
Copilot AI review requested due to automatic review settings March 9, 2026 00:45
@Simon9997
Simon9997 force-pushed the enh/3.0/6492510964 branch from eb4c5ad to c45d0a7 Compare March 9, 2026 00:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 41 out of 50 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread source/libs/executor/src/exchangeoperator.c
Comment thread source/libs/executor/src/exchangeoperator.c
break;
}
case WINDOW_TYPE_STATE: {
if (nodeType(pWindow->pStateExpr) != QUERY_NODE_COLUMN) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以扩大到支持标量运算

SFunctionNode *pFunction = (SFunctionNode *)pFunc;
if (windowFuncHasTagPKParam(pFunction)) {
SFunctionNode* pFunction = (SFunctionNode*)pFunc;
if (functionHasTagParam(pFunction)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个理论上也可以支持

@guanshengliang
guanshengliang merged commit 0606cf7 into 3.0 Mar 9, 2026
16 of 18 checks passed
@guanshengliang
guanshengliang deleted the enh/3.0/6492510964 branch March 9, 2026 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants