From 93245c12f9327ff2481c974e05adbf54dc22c7ea Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 3 Aug 2021 20:01:39 +0800 Subject: [PATCH] [TD-4199] enhance performance --- src/client/inc/tscUtil.h | 2 +- src/client/src/tscSQLParser.c | 2 +- src/client/src/tscServer.c | 2 +- src/client/src/tscUtil.c | 17 ++++++++++++----- src/util/src/hash.c | 2 +- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h index a7c2862f51..577ce2a0fd 100644 --- a/src/client/inc/tscUtil.h +++ b/src/client/inc/tscUtil.h @@ -340,7 +340,7 @@ STableMeta* createSuperTableMeta(STableMetaMsg* pChild); uint32_t tscGetTableMetaSize(STableMeta* pTableMeta); CChildTableMeta* tscCreateChildMeta(STableMeta* pTableMeta); uint32_t tscGetTableMetaMaxSize(); -int32_t tscCreateTableMetaFromSTableMeta(STableMeta* pChild, const char* name, void* buf); +int32_t tscCreateTableMetaFromSTableMeta(STableMeta** pChild, const char* name, size_t *tableMetaCapacity); STableMeta* tscTableMetaDup(STableMeta* pTableMeta); SVgroupsInfo* tscVgroupsInfoDup(SVgroupsInfo* pVgroupsInfo); diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 6f18ea3753..9022d84de1 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -8150,7 +8150,7 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) { // avoid mem leak, may should update pTableMeta void* pVgroupIdList = NULL; if (pTableMeta->tableType == TSDB_CHILD_TABLE) { - code = tscCreateTableMetaFromSTableMeta(pTableMeta, name, pSql->pBuf); + code = tscCreateTableMetaFromSTableMeta((STableMeta **)(&pTableMeta), name, &tableMetaCapacity); // create the child table meta from super table failed, try load it from mnode if (code != TSDB_CODE_SUCCESS) { diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index d1cc0c1fa8..cd79049281 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -2857,7 +2857,7 @@ int32_t tscGetTableMetaImpl(SSqlObj* pSql, STableMetaInfo *pTableMetaInfo, bool if (pMeta && pMeta->id.uid > 0) { // in case of child table, here only get the if (pMeta->tableType == TSDB_CHILD_TABLE) { - int32_t code = tscCreateTableMetaFromSTableMeta(pTableMetaInfo->pTableMeta, name, pSql->pBuf); + int32_t code = tscCreateTableMetaFromSTableMeta(&pTableMetaInfo->pTableMeta, name, &pTableMetaInfo->tableMetaCapacity); if (code != TSDB_CODE_SUCCESS) { return getTableMetaFromMnode(pSql, pTableMetaInfo, autocreate); } diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index b42199ec91..cf5f0b2d12 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -4448,11 +4448,13 @@ CChildTableMeta* tscCreateChildMeta(STableMeta* pTableMeta) { return cMeta; } -int32_t tscCreateTableMetaFromSTableMeta(STableMeta* pChild, const char* name, void* buf) { - assert(pChild != NULL); +int32_t tscCreateTableMetaFromSTableMeta(STableMeta** ppChild, const char* name, size_t *tableMetaCapacity) { + assert(*ppChild != NULL); STableMeta* p = NULL; size_t sz = 0; + STableMeta* pChild = *ppChild; + taosHashGetCloneExt(tscTableMetaMap, pChild->sTableName, strnlen(pChild->sTableName, TSDB_TABLE_FNAME_LEN), NULL, (void **)&p, &sz); // tableMeta exists, build child table meta according to the super table meta @@ -4462,9 +4464,14 @@ int32_t tscCreateTableMetaFromSTableMeta(STableMeta* pChild, const char* name, v pChild->tversion = p->tversion; memcpy(&pChild->tableInfo, &p->tableInfo, sizeof(STableComInfo)); - int32_t total = pChild->tableInfo.numOfColumns + pChild->tableInfo.numOfTags; - - memcpy(pChild->schema, p->schema, sizeof(SSchema) *total); + int32_t totalBytes = (pChild->tableInfo.numOfColumns + pChild->tableInfo.numOfTags) * sizeof(SSchema); + int32_t tableMetaSize = sizeof(STableMeta) + totalBytes; + if (*tableMetaCapacity < tableMetaSize) { + pChild = realloc(pChild, tableMetaSize); + *tableMetaCapacity = (size_t)tableMetaSize; + } + memcpy(pChild->schema, p->schema, totalBytes); + *ppChild = pChild; tfree(p); return TSDB_CODE_SUCCESS; } else { // super table has been removed, current tableMeta is also expired. remove it here diff --git a/src/util/src/hash.c b/src/util/src/hash.c index d4e23c900f..6118aa7bef 100644 --- a/src/util/src/hash.c +++ b/src/util/src/hash.c @@ -18,7 +18,7 @@ #include "tulog.h" #include "taosdef.h" -#define EXT_SIZE 512 +#define EXT_SIZE 1024 #define HASH_NEED_RESIZE(_h) ((_h)->size >= (_h)->capacity * HASH_DEFAULT_LOAD_FACTOR) -- GitLab