From 58f2621fc84e1c5985981ac3b9faf02798c03285 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Fri, 16 Jul 2021 19:17:35 +0800 Subject: [PATCH] code optimization --- src/client/inc/tsclient.h | 2 +- src/client/src/tscSQLParser.c | 6 +++--- src/client/src/tscServer.c | 6 +++--- src/client/src/tscUtil.c | 4 ++-- src/common/src/ttypes.c | 2 +- src/cq/src/cqMain.c | 2 +- src/inc/taosdef.h | 5 +++-- src/inc/ttype.h | 2 +- src/tsdb/src/tsdbMeta.c | 2 +- 9 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index d60c6756d6..6b6b8a23c6 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -184,6 +184,7 @@ typedef struct { uint32_t allocSize; char * payload; int32_t payloadLen; + void * pBuf; // table meta buffer SHashObj *pTableMetaMap; // local buffer to keep the queried table meta, before validating the AST SQueryInfo *pQueryInfo; @@ -273,7 +274,6 @@ typedef struct SSqlObj { void * pStream; void * pSubscription; char * sqlstr; - void * pBuf; // tableMeta buffer char parseRetry; char retry; char maxRetry; diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 13fd9a8092..18d17e9016 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -7697,8 +7697,8 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) { char name[TSDB_TABLE_FNAME_LEN] = {0}; assert(maxSize < 80 * TSDB_MAX_COLUMNS); - if (!pSql->pBuf) { - if (NULL == (pSql->pBuf = tcalloc(1, 80 * TSDB_MAX_COLUMNS))) { + if (!pSql->cmd.pBuf) { + if (NULL == (pSql->cmd.pBuf = tcalloc(1, 80 * TSDB_MAX_COLUMNS))) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } } @@ -7718,7 +7718,7 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) { if (pTableMeta->id.uid > 0) { if (pTableMeta->tableType == TSDB_CHILD_TABLE) { - code = tscCreateTableMetaFromSTableMeta(pTableMeta, name, pSql->pBuf); + code = tscCreateTableMetaFromSTableMeta(pTableMeta, name, pSql->cmd.pBuf); // 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 223c03b108..2f469a3828 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -2596,8 +2596,8 @@ int32_t tscGetTableMetaImpl(SSqlObj* pSql, STableMetaInfo *pTableMetaInfo, bool // TODO resize the tableMeta assert(size < 80 * TSDB_MAX_COLUMNS); - if (!pSql->pBuf) { - if (NULL == (pSql->pBuf = tcalloc(1, 80 * TSDB_MAX_COLUMNS))) { + if (!pSql->cmd.pBuf) { + if (NULL == (pSql->cmd.pBuf = tcalloc(1, 80 * TSDB_MAX_COLUMNS))) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } } @@ -2606,7 +2606,7 @@ int32_t tscGetTableMetaImpl(SSqlObj* pSql, STableMetaInfo *pTableMetaInfo, bool if (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, pSql->cmd.pBuf); 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 2e0d5c7d8a..bf997f3cbb 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -1450,7 +1450,6 @@ void tscFreeSqlObj(SSqlObj* pSql) { pSql->signature = NULL; pSql->fp = NULL; tfree(pSql->sqlstr); - tfree(pSql->pBuf); tfree(pSql->pSubs); pSql->subState.numOfSub = 0; @@ -1461,8 +1460,9 @@ void tscFreeSqlObj(SSqlObj* pSql) { memset(pCmd->payload, 0, (size_t)pCmd->allocSize); tfree(pCmd->payload); + tfree(pCmd->pBuf); pCmd->allocSize = 0; - + tsem_destroy(&pSql->rspSem); memset(pSql, 0, sizeof(*pSql)); free(pSql); diff --git a/src/common/src/ttypes.c b/src/common/src/ttypes.c index 34dda32401..24789d01ad 100644 --- a/src/common/src/ttypes.c +++ b/src/common/src/ttypes.c @@ -515,7 +515,7 @@ static void *nullValues[] = { &nullTinyIntu, &nullSmallIntu, &nullIntu, &nullBigIntu, }; -void *getNullValue(int32_t type) { +const void *getNullValue(int32_t type) { assert(type >= TSDB_DATA_TYPE_BOOL && type <= TSDB_DATA_TYPE_UBIGINT); return nullValues[type - 1]; } diff --git a/src/cq/src/cqMain.c b/src/cq/src/cqMain.c index cd762f3110..b45234901b 100644 --- a/src/cq/src/cqMain.c +++ b/src/cq/src/cqMain.c @@ -492,7 +492,7 @@ static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) { STColumn *c = pSchema->columns + i; void* val = row[i]; if (val == NULL) { - val = getNullValue(c->type); + val = (void *)getNullValue(c->type); } else if (c->type == TSDB_DATA_TYPE_BINARY) { val = ((char*)val) - sizeof(VarDataLenT); } else if (c->type == TSDB_DATA_TYPE_NCHAR) { diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index f5be879878..0caf204baf 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -329,8 +329,9 @@ do { \ #define TSDB_MAX_JOIN_TABLE_NUM 10 #define TSDB_MAX_UNION_CLAUSE 5 -#define TSDB_MAX_BINARY_LEN (16384-TSDB_KEYSIZE) // keep 16384 -#define TSDB_MAX_NCHAR_LEN (16384-TSDB_KEYSIZE) // keep 16384 +#define TSDB_MAX_FIELD_LEN 16384 +#define TSDB_MAX_BINARY_LEN (TSDB_MAX_FIELD_LEN-TSDB_KEYSIZE) // keep 16384 +#define TSDB_MAX_NCHAR_LEN (TSDB_MAX_FIELD_LEN-TSDB_KEYSIZE) // keep 16384 #define PRIMARYKEY_TIMESTAMP_COL_INDEX 0 #define TSDB_MAX_RPC_THREADS 5 diff --git a/src/inc/ttype.h b/src/inc/ttype.h index 2581589563..d0266d6a5c 100644 --- a/src/inc/ttype.h +++ b/src/inc/ttype.h @@ -178,7 +178,7 @@ bool isValidDataType(int32_t type); void setVardataNull(char* val, int32_t type); void setNull(char *val, int32_t type, int32_t bytes); void setNullN(char *val, int32_t type, int32_t bytes, int32_t numOfElems); -void *getNullValue(int32_t type); +const void *getNullValue(int32_t type); void assignVal(char *val, const char *src, int32_t len, int32_t type); void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size, void* buf); diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 621be04e21..b599e38e3a 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -787,7 +787,7 @@ static char *getTagIndexKey(const void *pData) { void * res = tdGetKVRowValOfCol(pTable->tagVal, pCol->colId); if (res == NULL) { // treat the column as NULL if we cannot find it - res = getNullValue(pCol->type); + res = (void *)getNullValue(pCol->type); } return res; } -- GitLab