Skip to content

Conversation

@Pengrongkun
Copy link
Contributor

Description

Issue(s)

  • Close/close/Fix/fix/Resolve/resolve: Issue Link

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 January 5, 2026 11:35
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 stmt2 query mechanism where table names, when supplied as bound parameters, were not being correctly processed by the parser. The fix ensures that the system can now properly identify and utilize these bound table names, thereby preventing query failures and improving the robustness of prepared statements. The changes are validated with new test cases covering various binding scenarios.

Highlights

  • Fix for tbname binding in stmt2 queries: Resolved an issue where table names (tbname) were not correctly bound when provided as parameters in stmt2 prepared statements, ensuring proper query execution.
  • Enhanced stmt2 query testing: Added new comprehensive test cases in stmt2Test.cpp to validate the correct binding of table names in stmt2 queries, including scenarios with both bound and literal table names.

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

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 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;
}
Copy link

Copilot AI Jan 5, 2026

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.

Suggested change
}
}
} else {
tbname = pValueNode->literal;

Copilot uses AI. Check for mistakes.

char* tbname = NULL;
if (pValueNode->placeholderNo != 0) {
if (NULL == pValueNode->datum.p) {
Copy link

Copilot AI Jan 5, 2026

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.

Suggested change
if (NULL == pValueNode->datum.p) {
if (NULL == pValueNode->datum.p) {
taosArrayDestroy(pTabNames);

Copilot uses AI. Check for mistakes.
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);
Copy link

Copilot AI Jan 5, 2026

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.

Suggested change
ASSERT_EQ(strncmp((char*)row[2], "abc", 3), 0);
ASSERT_EQ(strncmp((char*)row[2], "abc", 3), 0);
taos_stmt2_close(stmt);

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

Comment on lines 8532 to 8542
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;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

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);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The newly added test block initializes a TAOS_STMT2 resource but does not close it, leading to a resource leak. Please add taos_stmt2_close(stmt); at the end of the block to ensure proper resource cleanup.

    taos_stmt2_close(stmt);
  }

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.

2 participants