From 2c703b558e471396c5ba776c2af5f7e6fc0a738e Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Wed, 21 Jul 2021 13:46:21 +0800 Subject: [PATCH] [TD-5431]:fix hashDistinct bug that var_data_type value use the the maxmium length as the key length --- src/query/src/qExecutor.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 288a206491..51a4e01c53 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -6594,10 +6594,19 @@ static SSDataBlock* hashDistinct(void* param, bool* newgroup) { if (isNull(val, type)) { continue; } - int dummy; - void* res = taosHashGet(pInfo->pSet, val, bytes); + + size_t keyLen = 0; + if (IS_VAR_DATA_TYPE(pOperator->pExpr->base.colType)) { + tstr* var = (tstr*)(val); + keyLen = varDataLen(var); + } else { + keyLen = bytes; + } + + int dummy; + void* res = taosHashGet(pInfo->pSet, val, keyLen); if (res == NULL) { - taosHashPut(pInfo->pSet, val, bytes, &dummy, sizeof(dummy)); + taosHashPut(pInfo->pSet, val, keyLen, &dummy, sizeof(dummy)); char* start = pResultColInfoData->pData + bytes * pInfo->pRes->info.rows; memcpy(start, val, bytes); pRes->info.rows += 1; @@ -6624,6 +6633,7 @@ SOperatorInfo* createDistinctOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperat pOperator->blockingOptr = false; pOperator->status = OP_IN_EXECUTING; pOperator->operatorType = OP_Distinct; + pOperator->pExpr = pExpr; pOperator->numOfOutput = numOfOutput; pOperator->info = pInfo; pOperator->pRuntimeEnv = pRuntimeEnv; -- GitLab