From f1098e1cc397b20d648db1b0560712794cc34c25 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 6 May 2021 13:18:45 +0800 Subject: [PATCH] [TD-3747] --- src/client/inc/tsclient.h | 1 + src/client/src/tscServer.c | 5 +++++ src/client/src/tscUtil.c | 5 ++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index c91943e232..6d94d270a7 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -83,6 +83,7 @@ typedef struct STableMeta { typedef struct STableMetaInfo { STableMeta *pTableMeta; // table meta, cached in client side and acquired by name + uint32_t tableMetaSize; SVgroupsInfo *vgroupList; SArray *pVgroupTables; // SArray diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 5a7bd92994..706055668d 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -2533,6 +2533,11 @@ int32_t tscGetTableMeta(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo) { uint32_t size = tscGetTableMetaMaxSize(); if (pTableMetaInfo->pTableMeta == NULL) { pTableMetaInfo->pTableMeta = calloc(1, size); + } else if (pTableMetaInfo->tableMetaSize < size) { + char *tmp = realloc(pTableMetaInfo->pTableMeta, size); + if (tmp == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY;} + pTableMetaInfo->pTableMeta = (STableMeta *)tmp; + pTableMetaInfo->tableMetaSize = size; } else { uint32_t s = tscGetTableMetaSize(pTableMetaInfo->pTableMeta); memset(pTableMetaInfo->pTableMeta, 0, s); diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index a1416284c7..df48486e66 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -693,7 +693,8 @@ int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock) { tfree(pTableMetaInfo->pTableMeta); } - pTableMetaInfo->pTableMeta = tscTableMetaDup(pDataBlock->pTableMeta); + pTableMetaInfo->pTableMeta = tscTableMetaDup(pDataBlock->pTableMeta); + pTableMetaInfo->tableMetaSize = tscGetTableMetaSize(pDataBlock->pTableMeta); } /* @@ -2078,6 +2079,7 @@ STableMetaInfo* tscAddTableMetaInfo(SQueryInfo* pQueryInfo, SName* name, STableM } pTableMetaInfo->pTableMeta = pTableMeta; + pTableMetaInfo->tableMetaSize = tscGetTableMetaSize(pTableMeta); if (vgroupList != NULL) { pTableMetaInfo->vgroupList = tscVgroupInfoClone(vgroupList); @@ -2352,6 +2354,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, __async_cb_func_t pFinalInfo = tscAddTableMetaInfo(pNewQueryInfo, &pTableMetaInfo->name, pTableMeta, pTableMetaInfo->vgroupList, pTableMetaInfo->tagColList, pTableMetaInfo->pVgroupTables); + } else { // transfer the ownership of pTableMeta to the newly create sql object. STableMetaInfo* pPrevInfo = tscGetTableMetaInfoFromCmd(&pPrevSql->cmd, pPrevSql->cmd.clauseIndex, 0); if (pPrevInfo->pTableMeta && pPrevInfo->pTableMeta->tableType < 0) { -- GitLab