Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: stmt vtable query core#34640

Open
Pengrongkun wants to merge 4 commits intomainfrom
fix/main/6788971938-2
Open

fix: stmt vtable query core#34640
Pengrongkun wants to merge 4 commits intomainfrom
fix/main/6788971938-2

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 March 2, 2026 05:42
@gemini-code-assist
Copy link
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 addresses a core issue in how prepared statements handle virtual table queries by overhauling the metadata fetching process. It introduces a synchronous metadata retrieval step during statement binding, ensuring that the parser has complete information about virtual tables before execution. This change enhances the robustness and correctness of query processing for complex virtual table structures.

Highlights

  • Metadata Handling for Prepared Statements: Refactored the metadata fetching mechanism for prepared statements, especially for virtual tables, to ensure all necessary metadata is available synchronously before query parsing.
  • Function Signature Update: The qStmtParseQuerySql function signature was updated to accept an SMetaData* parameter, allowing metadata to be passed directly during parsing.
  • Synchronous Metadata Fetching: Introduced a new static function stmtFetchMetadataForQuery in clientStmt2.c to perform synchronous metadata fetching using SParseMetaCache and SCatalogReq before a query is parsed in stmtBindBatch2.
  • Catalog API Refactoring: The catalogGetAllMeta function in catalog.c was refactored to use a synchronous wrapper around catalogAsyncGetAllMeta, utilizing a semaphore for blocking until metadata is retrieved.
  • Memory Management Improvement: Improved memory management in planOptimizer.c by explicitly setting pointers to NULL after destroying lists (pScanPseudoCols, node.pTargets) to prevent potential use-after-free issues.
  • Test Case Expansion: Expanded test cases in stmt2Test.cpp to include more comprehensive scenarios for virtual table queries, specifically for last aggregate functions with various data types and tags.

🧠 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/parser/parser.h
    • Modified qStmtParseQuerySql function signature to accept SMetaData*.
    • Added SParseMetaCache struct definition.
    • Declared collectMetaKey, buildCatalogReq, and destoryParseMetaCache functions.
  • source/client/src/clientStmt.c
    • Updated call to qStmtParseQuerySql to pass NULL for the new SMetaData* parameter.
  • source/client/src/clientStmt2.c
    • Added stmtFetchMetadataForQuery function for synchronous metadata retrieval.
    • Modified stmtBindBatch2 to integrate stmtFetchMetadataForQuery and pass metadata to qStmtParseQuerySql.
    • Implemented logic to copy and clear metaData within stmtBindBatch2.
  • source/client/test/stmt2Test.cpp
    • Removed AsyncArgs setup and cleanup for certain TAOS_STMT2_OPTION configurations.
    • Modified create stable statement to include a float_v float column.
    • Added new test cases for query_last_core to validate last aggregate functions on virtual tables.
  • source/libs/catalog/src/catalog.c
    • Refactored catalogGetAllMeta to use a synchronous wrapper around catalogAsyncGetAllMeta with a semaphore for blocking.
    • Introduced SCatalogSyncCbParam struct and catalogSyncGetAllMetaCb callback for synchronous operation.
  • source/libs/parser/inc/parUtil.h
    • Removed SParseMetaCache struct definition, which was moved to parser.h.
    • Removed declarations for collectMetaKey and destoryParseMetaCache.
  • source/libs/parser/src/parTranslater.c
    • Removed conditional logic that previously handled cases where VStbRefDbs data was not available, indicating that metadata is now expected to be present.
  • source/libs/parser/src/parser.c
    • Included parUtil.h.
    • Modified qStmtParseQuerySql to initialize SParseMetaCache, collect metadata keys, build catalog requests, populate the metadata cache, and then call translate.
    • Added cleanup for SParseMetaCache and SCatalogReq.
  • source/libs/planner/src/planOptimizer.c
    • Explicitly set pScanPseudoCols and node.pTargets to NULL after nodesDestroyList in rebuildTableScanTargets.
    • Explicitly set node.pTargets to NULL after nodesDestroyList in rebuildVstbScanTargets.
  • source/libs/planner/test/planTestUtil.cpp
    • Updated call to qStmtParseQuerySql to pass NULL for the new SMetaData* parameter.
Activity
  • The pull request was created by Pengrongkun to fix an issue related to statement virtual table queries.
  • The changes involve significant refactoring of metadata handling, indicating a complex underlying problem was addressed.
  • New test cases were added and existing ones modified, suggesting thorough validation of the implemented fix.
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 updates stmt/vtable query parsing to support virtual-table metadata resolution by fetching catalog metadata and feeding it into the parser/translator, and adjusts related call sites and tests.

Changes:

  • Extend qStmtParseQuerySql to accept optional SMetaData* and populate a parse meta-cache from it.
  • Add a synchronous catalogGetAllMeta wrapper (built on catalogAsyncGetAllMeta) and use it from stmt2 query bind/parse.
  • Update stmt2 tests to cover vtable/last() query scenarios.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
source/libs/planner/test/planTestUtil.cpp Update call site for new qStmtParseQuerySql signature.
source/libs/planner/src/planOptimizer.c Null out pointers after list destruction to avoid stale pointers/double-destroys.
source/libs/parser/src/parser.c Implement new qStmtParseQuerySql(..., SMetaData*) flow with meta-cache + cleanup.
source/libs/parser/src/parTranslater.c Remove fallback behavior when VStbRefDbs is missing from cache.
source/libs/parser/inc/parUtil.h Move/adjust meta-cache related declarations and add collectMetaKey prototype.
source/libs/catalog/src/catalog.c Implement synchronous catalogGetAllMeta wrapper using semaphore + async API.
source/client/src/clientStmt2.c Fetch metadata synchronously on stmt2 bind, then parse with metadata.
source/client/src/clientStmt.c Update call site for new qStmtParseQuerySql signature (passes NULL).
include/libs/parser/parser.h Update public signature and expose meta-cache-related types/APIs.
source/client/test/stmt2Test.cpp Expand stmt2 tests for vtable/core last() queries and adjust query test options.

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

Comment on lines +2026 to +2030
// Copy metaData to pRequest->parseMeta for potential future use
// Similar to doAsyncQueryFromAnalyse when parseOnly is true
(void)memcpy(&pStmt->exec.pRequest->parseMeta, &metaData, sizeof(SMetaData));
(void)memset(&metaData, 0, sizeof(SMetaData)); // Clear to avoid double free
} else {
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

This copies metaData into pRequest->parseMeta unconditionally, but request teardown (doDestroyRequest) does not free parseMeta via catalogFreeMetaData. This introduces a persistent leak for every stmt2 bind/parse. Either only store parseMeta when parseOnly is enabled (matching doAsyncQueryFromAnalyse), or ensure parseMeta is freed during request destruction/reset before overwriting it.

Copilot uses AI. Check for mistakes.
Comment on lines 1529 to 1545
int32_t catalogGetAllMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SCatalogReq* pReq, SMetaData* pRsp) {
CTG_API_ENTER();

if (NULL == pCtg || NULL == pConn || NULL == pReq || NULL == pRsp) {
CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT);
}

int32_t code = 0;
pRsp->pTableMeta = NULL;

if (pReq->pTableMeta) {
int32_t tbNum = (int32_t)taosArrayGetSize(pReq->pTableMeta);
if (tbNum <= 0) {
ctgError("empty table name list, tbNum:%d", tbNum);
CTG_ERR_JRET(TSDB_CODE_CTG_INVALID_INPUT);
}

pRsp->pTableMeta = taosArrayInit(tbNum, POINTER_BYTES);
if (NULL == pRsp->pTableMeta) {
ctgError("taosArrayInit %d failed", tbNum);
CTG_ERR_JRET(terrno);
}

for (int32_t i = 0; i < tbNum; ++i) {
SName* name = taosArrayGet(pReq->pTableMeta, i);
STableMeta* pTableMeta = NULL;
SCtgTbMetaCtx ctx = {0};
ctx.pName = name;
ctx.flag = CTG_FLAG_UNKNOWN_STB;

CTG_ERR_JRET(ctgGetTbMeta(pCtg, pConn, &ctx, &pTableMeta));

if (NULL == taosArrayPush(pRsp->pTableMeta, &pTableMeta)) {
ctgError("taosArrayPush failed, idx:%d", i);
taosMemoryFreeClear(pTableMeta);
CTG_ERR_JRET(terrno);
}
}
SCatalogSyncCbParam cbParam = {.pRsp = pRsp, .code = TSDB_CODE_SUCCESS};
if (tsem_init(&cbParam.sem, 0, 0) != 0) {
CTG_API_LEAVE(TSDB_CODE_CTG_INTERNAL_ERROR);
}

if (pReq->qNodeRequired) {
pRsp->pQnodeList = taosArrayInit(10, sizeof(SQueryNodeLoad));
CTG_ERR_JRET(ctgGetQnodeListFromMnode(pCtg, pConn, pRsp->pQnodeList, NULL));
}

CTG_API_LEAVE(TSDB_CODE_SUCCESS);

_return:

if (pRsp->pTableMeta) {
int32_t aSize = taosArrayGetSize(pRsp->pTableMeta);
for (int32_t i = 0; i < aSize; ++i) {
STableMeta* pMeta = taosArrayGetP(pRsp->pTableMeta, i);
taosMemoryFreeClear(pMeta);
}

taosArrayDestroy(pRsp->pTableMeta);
pRsp->pTableMeta = NULL;
int32_t code = catalogAsyncGetAllMeta(pCtg, pConn, pReq, catalogSyncGetAllMetaCb, &cbParam, NULL);
if (TSDB_CODE_SUCCESS == code) {
tsem_wait(&cbParam.sem);
code = cbParam.code;
}
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

catalogGetAllMeta no longer initializes/clears *pRsp. If catalogAsyncGetAllMeta returns an error (or tsem_init fails), the function returns without touching pRsp, leaving any existing pointers/values in caller memory intact and risking later misuse/free. Consider zeroing *pRsp at entry (or documenting/guaranteeing that callers must pass a zeroed SMetaData).

Copilot uses AI. Check for mistakes.
ASSERT_NE(row2, nullptr);
ASSERT_EQ(*(int64_t*)row2[0], 1591060630000);
row2 = taos_fetch_row(res2);
ASSERT_EQ(row2, nullptr);
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

This loop allocates/initializes a TAOS_STMT2 but never closes it. In the rest of this test file, statements are consistently released via taos_stmt2_close; skipping it here will leak resources and can destabilize later tests. Ensure each stmt created in the loop is closed (and that any associated result state is released) before the next iteration/end of test.

Suggested change
ASSERT_EQ(row2, nullptr);
ASSERT_EQ(row2, nullptr);
taos_free_result(res2);
taos_stmt2_close(stmt);

Copilot uses AI. Check for mistakes.
Comment on lines +5062 to 5093
AsyncArgs args = {0, 0};
ASSERT_EQ(tsem_init(&args.sem, 0, 0), TSDB_CODE_SUCCESS);
TAOS_STMT2_OPTION option[2] = {{0, true, true, stmtAsyncQueryCb, &args}, {0, true, true, NULL, NULL}};

int32_t dataname_len = 3;
char* dataname = "abc";
char* dataname2 = "def";

for (int i = 1; i < 2; i++) {
TAOS_STMT2* stmt = taos_stmt2_init(taos, &option[i]);
ASSERT_NE(stmt, nullptr);

int code =
taos_stmt2_prepare(stmt, "select last(bool_v) from ts_kv_data tbv1 where dataname in (?) partition by tbname", 0);
checkError(stmt, code, __FILE__, __LINE__);
int32_t dataname_len = 3;
char* dataname = "abc";
TAOS_STMT2_BIND params[1] = {
{TSDB_DATA_TYPE_BINARY, dataname, &dataname_len, NULL, 1},
};
TAOS_STMT2_BIND* paramv = &params[0];
TAOS_STMT2_BINDV bindv = {1, NULL, NULL, &paramv};
code = taos_stmt2_bind_param(stmt, &bindv, -1);
checkError(stmt, code, __FILE__, __LINE__);
code = taos_stmt2_exec(stmt, NULL);
checkError(stmt, code, __FILE__, __LINE__);
int code = taos_stmt2_prepare(
stmt,
"select last(ts,bool_v,float_v) from stmt2_testdb_32.ts_kv_data where dataname in (?,?) partition by tbname",
0);
checkError(stmt, code, __FILE__, __LINE__);
TAOS_STMT2_BIND params[2] = {
{TSDB_DATA_TYPE_BINARY, dataname, &dataname_len, NULL, 1},
{TSDB_DATA_TYPE_BINARY, dataname2, &dataname_len, NULL, 1},
};
TAOS_STMT2_BIND* paramv = &params[0];
TAOS_STMT2_BINDV bindv = {1, NULL, NULL, &paramv};
code = taos_stmt2_bind_param(stmt, &bindv, -1);
checkError(stmt, code, __FILE__, __LINE__);
code = taos_stmt2_exec(stmt, NULL);
checkError(stmt, code, __FILE__, __LINE__);

TAOS_RES* res = taos_stmt2_result(stmt);
ASSERT_NE(res, nullptr);
TAOS_ROW row = taos_fetch_row(res);
ASSERT_NE(row, nullptr);
ASSERT_EQ(*(bool*)row[0], false);
if (i == 0) {
tsem_wait(&args.sem);
}

Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

The async test path is currently unreachable: the loop starts at i=1, but the wait is guarded by if (i == 0). As written, the semaphore/AsyncArgs setup is unused and the async option isn’t exercised. Either iterate over both options (0 and 1) and wait in the async case, or remove the async scaffolding if only the sync path is intended.

Copilot uses AI. Check for mistakes.
Comment on lines +5152 to +5175
for (int i = 1; i < 2; i++) {
TAOS_STMT2* stmt = taos_stmt2_init(taos, &option[i]);
ASSERT_NE(stmt, nullptr);

int code = taos_stmt2_prepare(
stmt,
"select last(ts,bool_v,float_v) from stmt2_testdb_32.ts_kv_data where dataname in (?,?) partition by tbname",
0);
checkError(stmt, code, __FILE__, __LINE__);
TAOS_STMT2_BIND params[2] = {
{TSDB_DATA_TYPE_BINARY, dataname, &dataname_len, NULL, 1},
{TSDB_DATA_TYPE_BINARY, dataname2, &dataname_len, NULL, 1},
};
TAOS_STMT2_BIND* paramv = &params[0];
TAOS_STMT2_BINDV bindv = {1, NULL, NULL, &paramv};
code = taos_stmt2_bind_param(stmt, &bindv, -1);
checkError(stmt, code, __FILE__, __LINE__);
code = taos_stmt2_exec(stmt, NULL);
checkError(stmt, code, __FILE__, __LINE__);

if (i == 0) {
tsem_wait(&args.sem);
}

Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

Same issue as above: the loop starts at i=1 so the async option (i==0) is never executed, and the semaphore wait block is dead code. This reduces test coverage of the async stmt2 execution path and leaves unnecessary synchronization setup in the test.

Copilot uses AI. Check for mistakes.
Comment on lines 5093 to 5096
SArray* pVStbRefs = NULL;
code = getVStbRefDbsFromCache(pCxt->pMetaCache, pName, &pVStbRefs);

// Handle the case where VStbRefDbs data is not available (e.g., stmt scenario)
if (TSDB_CODE_PAR_TABLE_NOT_EXIST == code || TSDB_CODE_PAR_INTERNAL_ERROR == code) {
// VStbRefDbs not available in cache (stmt scenario without async metadata fetch)
// Use empty vgroup list - the executor will resolve vgroups at runtime
taosMemoryFreeClear(pRefScanTable->pVgroupList);
PAR_ERR_JRET(toVgroupsInfo(vgroupList, &pRefScanTable->pVgroupList));
code = TSDB_CODE_SUCCESS;
goto _return;
}
PAR_ERR_JRET(code);

Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

Removing the fallback handling here means translate will now hard-fail when VStbRefDbs is missing from the meta cache (getVStbRefDbsFromCache returns TSDB_CODE_PAR_TABLE_NOT_EXIST when pMetaCache/pVStbRefDbs is NULL). This breaks sync parse flows that do not populate meta cache (e.g., qParseSql/parseSqlIntoAst passes NULL meta cache) and stmt1 query parsing (qStmtParseQuerySql called with NULL metadata). Either restore the previous fallback to allow an empty vgroup list, or add a synchronous catalog fetch path for VStbRefDbs when it’s not present in cache.

Copilot uses AI. Check for mistakes.
Comment on lines +1949 to +1955
// Clean up metaData on failure - free all arrays
if (pMetaData->pVStbRefDbs) {
taosArrayDestroy(pMetaData->pVStbRefDbs);
pMetaData->pVStbRefDbs = NULL;
}
// Note: Other fields in metaData are managed by catalog module if ctgFree is true
// For now, we only need to clean up pVStbRefDbs which we explicitly need
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

On failure, this cleanup only destroys pMetaData->pVStbRefDbs, but catalogGetAllMeta can populate many other fields in SMetaData (pDbVgroup, pTableMeta, pUser, etc.). This will leak memory (and possibly leave partially-initialized pointers) on error. Prefer calling catalogFreeMetaData(pMetaData) (or the appropriate catalog cleanup API) for complete cleanup.

Suggested change
// Clean up metaData on failure - free all arrays
if (pMetaData->pVStbRefDbs) {
taosArrayDestroy(pMetaData->pVStbRefDbs);
pMetaData->pVStbRefDbs = NULL;
}
// Note: Other fields in metaData are managed by catalog module if ctgFree is true
// For now, we only need to clean up pVStbRefDbs which we explicitly need
// Clean up metaData on failure using catalog API to avoid leaks/partial init
catalogFreeMetaData(pMetaData);

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 mechanism to fetch metadata for prepared statements, which is crucial for handling virtual tables where metadata depends on query parameters. The overall approach is sound, involving passing metadata to qStmtParseQuerySql and refactoring catalogGetAllMeta for synchronous metadata retrieval. The code is well-structured, but I've identified a few areas for improvement, primarily in the test suite where parameter binding is incorrect for queries with multiple parameters. I've also noted a redundant function declaration and an opportunity to refactor duplicated code.

Comment on lines +5083 to +5085
TAOS_STMT2_BIND* paramv = &params[0];
TAOS_STMT2_BINDV bindv = {1, NULL, NULL, &paramv};
code = taos_stmt2_bind_param(stmt, &bindv, -1);
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 parameter binding for the prepared statement is incorrect. The query ... where dataname in (?,?) ... has two parameter markers, but the TAOS_STMT2_BINDV is configured to bind only one parameter (num_params is 1). This means the test doesn't correctly cover the scenario with multiple parameters in an IN clause.

    TAOS_STMT2_BIND* param_ptrs[] = {&params[0], &params[1]};
    TAOS_STMT2_BINDV bindv = {2, NULL, NULL, param_ptrs};
    code = taos_stmt2_bind_param(stmt, &bindv, -1);

Comment on lines +5165 to +5167
TAOS_STMT2_BIND* paramv = &params[0];
TAOS_STMT2_BINDV bindv = {1, NULL, NULL, &paramv};
code = taos_stmt2_bind_param(stmt, &bindv, -1);
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Similar to the previous test case, the parameter binding here is incorrect. The query uses two parameter markers (?,?), but the binding is set up for only a single parameter. This should be corrected to bind both parameters.

      TAOS_STMT2_BIND* param_ptrs[] = {&params[0], &params[1]};
      TAOS_STMT2_BINDV bindv = {2, NULL, NULL, param_ptrs};
      code = taos_stmt2_bind_param(stmt, &bindv, -1);

Comment on lines +5213 to +5215
TAOS_STMT2_BIND* paramv = &params[0];
TAOS_STMT2_BINDV bindv = {1, NULL, NULL, &paramv};
code = taos_stmt2_bind_param(stmt, &bindv, -1);
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 parameter binding is incorrect for this test case as well. The query has two parameter markers, but the binding is configured for only one. Please adjust the TAOS_STMT2_BINDV to bind both parameters.

      TAOS_STMT2_BIND* param_ptrs[] = {&params[0], &params[1]};
      TAOS_STMT2_BINDV bindv = {2, NULL, NULL, param_ptrs};
      code = taos_stmt2_bind_param(stmt, &bindv, -1);

Comment on lines +1948 to +1956
if (TSDB_CODE_SUCCESS != code) {
// Clean up metaData on failure - free all arrays
if (pMetaData->pVStbRefDbs) {
taosArrayDestroy(pMetaData->pVStbRefDbs);
pMetaData->pVStbRefDbs = NULL;
}
// Note: Other fields in metaData are managed by catalog module if ctgFree is true
// For now, we only need to clean up pVStbRefDbs which we explicitly need
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This cleanup logic is duplicated in stmtBindBatch2 at lines 2031-2035. To improve maintainability and reduce code duplication, consider extracting this logic into a static helper function.

int32_t getVStbRefDbsFromCache(SParseMetaCache* pMetaCache, const SName* pName, SArray** pOutput);
int32_t getDnodeListFromCache(SParseMetaCache* pMetaCache, SArray** pDnodes);
void destoryParseMetaCache(SParseMetaCache* pMetaCache, bool request);
int32_t collectMetaKey(SParseContext* pParseCxt, SQuery* pQuery, SParseMetaCache* pMetaCache);
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The function collectMetaKey is also declared in the public header include/libs/parser/parser.h. This declaration in an internal header is redundant and should be removed to avoid potential inconsistencies and improve maintainability.

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