From a2a2dbd68a34e36ecf5ed5679e30395197220495 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 1 Aug 2022 13:11:32 +0800 Subject: [PATCH] refactor: optimize the build block perf. --- include/common/tdatablock.h | 1 + source/common/src/tdatablock.c | 22 ++++++++++++++++++++++ source/libs/executor/src/scanoperator.c | 7 +++++++ source/libs/scalar/src/sclfunc.c | 1 + 4 files changed, 31 insertions(+) diff --git a/include/common/tdatablock.h b/include/common/tdatablock.h index 22aac46560..93ce7ea984 100644 --- a/include/common/tdatablock.h +++ b/include/common/tdatablock.h @@ -184,6 +184,7 @@ static FORCE_INLINE void colDataAppendDouble(SColumnInfoData* pColumnInfoData, u int32_t getJsonValueLen(const char* data); int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, const char* pData, bool isNull); +int32_t colDataReserve(SColumnInfoData* pColumnInfoData, size_t newSize); int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, int32_t numOfRow1, int32_t* capacity, const SColumnInfoData* pSource, int32_t numOfRow2); int32_t colDataAssign(SColumnInfoData* pColumnInfoData, const SColumnInfoData* pSource, int32_t numOfRows, diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index cc4b6a2890..5da7cfcbba 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -118,6 +118,28 @@ int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, con return 0; } +int32_t colDataReserve(SColumnInfoData* pColumnInfoData, size_t newSize) { + if (!IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) { + return TSDB_CODE_SUCCESS; + } + + if (pColumnInfoData->varmeta.allocLen >= newSize) { + return TSDB_CODE_SUCCESS; + } + + if (pColumnInfoData->varmeta.allocLen < newSize) { + char* buf = taosMemoryRealloc(pColumnInfoData->pData, newSize); + if (buf == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + pColumnInfoData->pData = buf; + pColumnInfoData->varmeta.allocLen = newSize; + } + + return TSDB_CODE_SUCCESS; +} + static void doBitmapMerge(SColumnInfoData* pColumnInfoData, int32_t numOfRow1, const SColumnInfoData* pSource, int32_t numOfRow2) { if (numOfRow2 <= 0) return; diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index fc67f3da6c..3439259224 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -399,8 +399,15 @@ int32_t addTagPseudoColumnData(SReadHandle* pHandle, SExprInfo* pPseudoExpr, int const char* p = metaGetTableTagVal(&mr.me, pColInfoData->info.type, &tagVal); char* data = NULL; + int32_t len = 0; if (pColInfoData->info.type != TSDB_DATA_TYPE_JSON && p != NULL) { data = tTagValToData((const STagVal*)p, false); + len = varDataTLen(data); + code = colDataReserve(pColInfoData, len * pBlock->info.rows); + if (code != TSDB_CODE_SUCCESS) { + terrno = code; + return code; + } } else { data = (char*)p; } diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index a70afe25d6..c162b13799 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -1728,6 +1728,7 @@ int32_t qTbnameFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pO char str[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; metaGetTableNameByUid(pInput->param, uid, str); + colDataReserve(pOutput->columnData, varDataTLen(str) * (pInput->numOfRows + pOutput->numOfRows)); for(int32_t i = 0; i < pInput->numOfRows; ++i) { colDataAppend(pOutput->columnData, pOutput->numOfRows + i, str, false); } -- GitLab