Skip to content

enh: stmt2 support vtable query#33825

Merged
guanshengliang merged 4 commits intomainfrom
enh/main/TS-7348
Dec 5, 2025
Merged

enh: stmt2 support vtable query#33825
guanshengliang merged 4 commits intomainfrom
enh/main/TS-7348

Conversation

@Pengrongkun
Copy link
Contributor

Description

Please briefly describe the code changes in this pull request.

<Close/close/Fix/fix/Resolve/resolve>:

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?

@gemini-code-assist
Copy link
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enables vtable (virtual table) query support for stmt2 (prepared statement v2). Previously, vtable queries were blocked when using stmt2 with an error TSDB_CODE_VTABLE_NOT_SUPPORT_STMT. This enhancement allows stmt2 to query both virtual super tables and virtual child tables with parameterized queries.

Key changes:

  • Removed the stmt version check that blocked vtable queries in stmt2
  • Added graceful handling for missing VStbRefDbs metadata in stmt scenario (returns empty vgroup list for runtime resolution)
  • Added comprehensive test coverage for vtable queries via stmt2 (replaces negative test with positive test)

Reviewed changes

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

Show a summary per file
File Description
source/libs/parser/src/parTranslater.c Removed stmt version check blocking vtable queries; added error handling for missing VStbRefDbs cache data in stmt scenarios
source/libs/parser/src/parUtil.c Added null checks and special handling for stmt scenario where VStbRefDbs slot is reserved but not filled
source/libs/planner/src/planLogicCreater.c Set pTargets to NULL after destroy to prevent potential dangling pointer issues
source/libs/catalog/src/ctgCache.c Properly set numOfColRefs and rversion fields when copying metadata for virtual child tables
source/libs/parser/src/parInsertSql.c Changed log level from warning to trace for table name specified in SQL (reduces log noise)
source/client/test/stmt2Test.cpp Replaced negative test case with comprehensive positive test coverage for vtable queries via stmt2; improved test cleanup

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

// TODO(smj) : create a fake logic node, no need to collect column
PLAN_ERR_JRET(createScanLogicNode(pCxt, pSelect, (SRealTableNode*)nodesListGetNode(pVirtualTable->refTables, 1), &pInsColumnsScan));
nodesDestroyList(((SScanLogicNode*)pInsColumnsScan)->node.pTargets);
((SScanLogicNode*)pInsColumnsScan)->node.pTargets = NULL; // Set to NULL after destroy to avoid use-after-free
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

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

[nitpick] The comment on line 1134 mentions "avoid use-after-free", but this is not accurate. Setting a pointer to NULL after destroying it prevents double-free issues and dangling pointer access, not use-after-free specifically. Consider updating the comment to: "Set to NULL after destroy to prevent double-free or dangling pointer issues".

Suggested change
((SScanLogicNode*)pInsColumnsScan)->node.pTargets = NULL; // Set to NULL after destroy to avoid use-after-free
((SScanLogicNode*)pInsColumnsScan)->node.pTargets = NULL; // Set to NULL after destroy to prevent double-free or dangling pointer issues

Copilot uses AI. Check for mistakes.
// query virtual child table
code = taos_stmt2_prepare(stmt, "select c1 from vtb_0 where ts = ? order by c1", 0);
checkError(stmt, code, __FILE__, __LINE__);
int t2_len = 5;
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

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

Unused variable t2_len is declared but never used. It should be removed.

Suggested change
int t2_len = 5;

Copilot uses AI. Check for mistakes.
@guanshengliang guanshengliang merged commit bffc07a into main Dec 5, 2025
23 of 25 checks passed
@minhuinie minhuinie deleted the enh/main/TS-7348 branch February 4, 2026 02:36
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.

4 participants