diff --git a/src/query/inc/qExecutor.h b/src/query/inc/qExecutor.h index af28d7b3bf37d0bdf5e4734cd3229e3ad2d21c07..bdaec7e2faa5ad0ffed0a432c015265f28218555 100644 --- a/src/query/inc/qExecutor.h +++ b/src/query/inc/qExecutor.h @@ -124,6 +124,7 @@ typedef struct SQueryCostInfo { uint64_t firstStageMergeTime; uint64_t winInfoSize; uint64_t tableInfoSize; + uint64_t hashSize; uint64_t numOfTimeWindows; } SQueryCostInfo; diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 88abb2e90c7583c6911af2b5e73ef080c9a6b4e2..3da3d6e28dd5bdcd4cc883c059c272286be86199 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -461,16 +461,16 @@ static SWindowResult *doSetTimeWindowFromKey(SQueryRuntimeEnv *pRuntimeEnv, SWin // more than the capacity, reallocate the resources if (pWindowResInfo->size >= pWindowResInfo->capacity) { - int64_t newCap = 0; + int64_t newCapacity = 0; if (pWindowResInfo->capacity > 10000) { - newCap = (int64_t)(pWindowResInfo->capacity * 1.25); + newCapacity = (int64_t)(pWindowResInfo->capacity * 1.25); } else { - newCap = (int64_t)(pWindowResInfo->capacity * 1.5); + newCapacity = (int64_t)(pWindowResInfo->capacity * 1.5); } - char *t = realloc(pWindowResInfo->pResult, (size_t)(newCap * sizeof(SWindowResult))); - pRuntimeEnv->summary.winInfoSize += (newCap - pWindowResInfo->capacity) * sizeof(SWindowResult); - pRuntimeEnv->summary.numOfTimeWindows += (newCap - pWindowResInfo->capacity); + char *t = realloc(pWindowResInfo->pResult, (size_t)(newCapacity * sizeof(SWindowResult))); + pRuntimeEnv->summary.winInfoSize += (newCapacity - pWindowResInfo->capacity) * sizeof(SWindowResult); + pRuntimeEnv->summary.numOfTimeWindows += (newCapacity - pWindowResInfo->capacity); if (t == NULL) { longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -478,19 +478,19 @@ static SWindowResult *doSetTimeWindowFromKey(SQueryRuntimeEnv *pRuntimeEnv, SWin pWindowResInfo->pResult = (SWindowResult *)t; - int32_t inc = (int32_t)newCap - pWindowResInfo->capacity; + int32_t inc = (int32_t)newCapacity - pWindowResInfo->capacity; memset(&pWindowResInfo->pResult[pWindowResInfo->capacity], 0, sizeof(SWindowResult) * inc); pRuntimeEnv->summary.winInfoSize += (pQuery->numOfOutput * sizeof(SResultInfo) + pRuntimeEnv->interBufSize) * inc; - for (int32_t i = pWindowResInfo->capacity; i < newCap; ++i) { + for (int32_t i = pWindowResInfo->capacity; i < newCapacity; ++i) { int32_t ret = createQueryResultInfo(pQuery, &pWindowResInfo->pResult[i], pRuntimeEnv->stableQuery, pRuntimeEnv->interBufSize); if (ret != TSDB_CODE_SUCCESS) { longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_OUT_OF_MEMORY); } } - pWindowResInfo->capacity = (int32_t)newCap; + pWindowResInfo->capacity = (int32_t)newCapacity; } // add a new result set for a new group diff --git a/src/query/src/qUtil.c b/src/query/src/qUtil.c index c454669474cecb695df4fc4a922c2ce877f20b90..3482c52052b0b0438a3f19056a1cbdb519e2acc0 100644 --- a/src/query/src/qUtil.c +++ b/src/query/src/qUtil.c @@ -49,16 +49,16 @@ int32_t initWindowResInfo(SWindowResInfo *pWindowResInfo, SQueryRuntimeEnv *pRun SQueryCostInfo* pSummary = &pRuntimeEnv->summary; // use the pointer arraylist - pWindowResInfo->pResult = calloc(threshold, sizeof(SWindowResult)); + pWindowResInfo->pResult = calloc(pWindowResInfo->capacity, sizeof(SWindowResult)); if (pWindowResInfo->pResult == NULL) { return TSDB_CODE_QRY_OUT_OF_MEMORY; } pWindowResInfo->interval = pRuntimeEnv->pQuery->interval.interval; - pSummary->winInfoSize += sizeof(SWindowResult) * threshold; + pSummary->winInfoSize += sizeof(SWindowResult) * pWindowResInfo->capacity; pSummary->winInfoSize += (pRuntimeEnv->pQuery->numOfOutput * sizeof(SResultInfo) + pRuntimeEnv->interBufSize) * pWindowResInfo->capacity; - pSummary->numOfTimeWindows = threshold; + pSummary->numOfTimeWindows = pWindowResInfo->capacity; for (int32_t i = 0; i < pWindowResInfo->capacity; ++i) { int32_t code = createQueryResultInfo(pRuntimeEnv->pQuery, &pWindowResInfo->pResult[i], pRuntimeEnv->stableQuery, pRuntimeEnv->interBufSize); diff --git a/src/util/inc/hash.h b/src/util/inc/hash.h index 2a58bec8830faab4cf9909bd417a44e2e8881570..d4e9b1677cb36d528830d43c5e97af0b6ff87276 100644 --- a/src/util/inc/hash.h +++ b/src/util/inc/hash.h @@ -32,7 +32,6 @@ typedef void (*_hash_free_fn_t)(void *param); typedef struct SHashNode { char *key; -// struct SHashNode *prev; struct SHashNode *next; uint32_t hashVal; // the hash value of key, if hashVal == HASH_VALUE_IN_TRASH, this node is moved to trash uint32_t keyLen; // length of the key @@ -175,6 +174,8 @@ void* taosHashDestroyIter(SHashMutableIterator* iter); */ int32_t taosHashGetMaxOverflowLinkLength(const SHashObj *pHashObj); +size_t taosHashGetMemSize(const SHashObj *pHashObj); + #ifdef __cplusplus } #endif diff --git a/src/util/src/hash.c b/src/util/src/hash.c index 625d4af1ac981c5d1f5f079f5b15533a4d63ef24..9aadee0924d769a9a1ef53b8576f9fe062b3a578 100644 --- a/src/util/src/hash.c +++ b/src/util/src/hash.c @@ -798,3 +798,11 @@ SHashNode *getNextHashNode(SHashMutableIterator *pIter) { return NULL; } + +size_t taosHashGetMemSize(const SHashObj *pHashObj) { + if (pHashObj == NULL) { + return 0; + } + + return (pHashObj->capacity * sizeof(SHashEntry) + POINTER_BYTES) + sizeof(SHashNode) * taosHashGetSize(pHashObj); +}