-
Notifications
You must be signed in to change notification settings - Fork 5k
fix:stmt2 query tbname bind problem #34174
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: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @Pengrongkun, 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 addresses a critical bug in the 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.
Pull request overview
This PR attempts to fix an issue with stmt2 query table name binding by handling placeholder values differently when querying with prepared statements. The fix adds logic to extract table names from bound parameters when using placeholders versus literal values.
Key Changes
- Added conditional logic to handle placeholder values (vs literal values) for table name binding in queries
- Uncommented and expanded test cases to verify both placeholder-based and literal-based table name queries
- Tests now verify queries with both bound parameters and hardcoded literal table names
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| source/libs/parser/src/parTranslater.c | Added logic to handle placeholder vs literal table name values in query conditions |
| source/client/test/stmt2Test.cpp | Uncommented and expanded test cases to validate placeholder binding and literal table name queries |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| tbname = varDataVal(pValueNode->datum.p); | ||
| } else { | ||
| tbname = pValueNode->literal; | ||
| } |
Copilot
AI
Jan 5, 2026
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.
When placeholderNo is 0, the tbname variable remains NULL. This breaks queries with literal table names like "tbname = 'tb2'". The else branch should handle the case when placeholderNo is 0 by setting tbname to pValueNode->literal.
| } | |
| } | |
| } else { | |
| tbname = pValueNode->literal; |
|
|
||
| char* tbname = NULL; | ||
| if (pValueNode->placeholderNo != 0) { | ||
| if (NULL == pValueNode->datum.p) { |
Copilot
AI
Jan 5, 2026
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.
Memory leak: pTabNames array is allocated at line 8527 but not freed before the early return when pValueNode->datum.p is NULL. This should call taosArrayDestroy(pTabNames) before returning.
| if (NULL == pValueNode->datum.p) { | |
| if (NULL == pValueNode->datum.p) { | |
| taosArrayDestroy(pTabNames); |
| ASSERT_NE(row, nullptr); | ||
| ASSERT_EQ(strncmp((char*)row[0], "tb2", 3), 0); | ||
| ASSERT_EQ(strncmp((char*)row[1], "xyz", 3), 0); | ||
| ASSERT_EQ(strncmp((char*)row[2], "abc", 3), 0); |
Copilot
AI
Jan 5, 2026
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.
Missing resource cleanup: The taos_stmt2_close function should be called at the end of this test block to properly close the statement handle and free associated resources.
| ASSERT_EQ(strncmp((char*)row[2], "abc", 3), 0); | |
| ASSERT_EQ(strncmp((char*)row[2], "abc", 3), 0); | |
| taos_stmt2_close(stmt); |
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 a fix for binding tbname in stmt2 queries and adds a test case to cover it. While the intent is correct, the implementation in parTranslater.c introduces a regression that breaks filtering by literal table names. Additionally, the new test case in stmt2Test.cpp has a resource leak. I've provided suggestions to address both issues.
| char* tbname = NULL; | ||
| if (pValueNode->placeholderNo != 0) { | ||
| if (NULL == pValueNode->datum.p) { | ||
| return TSDB_CODE_SUCCESS; | ||
| } | ||
| if (IS_VAR_DATA_TYPE(pValueNode->node.resType.type)) { | ||
| tbname = varDataVal(pValueNode->datum.p); | ||
| } else { | ||
| tbname = pValueNode->literal; | ||
| } | ||
| } |
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 logic for extracting the table name from a tbname = ? condition has been updated to handle placeholders, but it introduced a regression for literal values. When pValueNode->placeholderNo is 0 (i.e., not a placeholder), the tbname variable remains NULL, which is then pushed to the pTabNames array. This breaks queries that filter on tbname with a literal string.
char* tbname = NULL;
if (pValueNode->placeholderNo != 0) {
if (NULL == pValueNode->datum.p) {
return TSDB_CODE_SUCCESS;
}
if (IS_VAR_DATA_TYPE(pValueNode->node.resType.type)) {
tbname = varDataVal(pValueNode->datum.p);
} else {
tbname = pValueNode->literal;
}
} else {
tbname = pValueNode->literal;
}| ASSERT_EQ(strncmp((char*)row[0], "tb2", 3), 0); | ||
| ASSERT_EQ(strncmp((char*)row[1], "xyz", 3), 0); | ||
| ASSERT_EQ(strncmp((char*)row[2], "abc", 3), 0); | ||
| } |
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.
91f48c9 to
0233e1e
Compare
Description
Issue(s)
Checklist
Please check the items in the checklist if applicable.