From c2f32ad9c1cc67f5da01ed86689a13e645b43ac8 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 8 Jul 2021 23:33:12 +0800 Subject: [PATCH 1/8] [TD-5134] fix runtime error --- src/client/src/tscSQLParser.c | 6 +++--- src/client/src/tscSubquery.c | 7 ++++--- src/client/src/tscUtil.c | 6 ++++-- src/query/src/qExecutor.c | 13 +++++++++---- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index c2542fb8c6..9e8cb325a8 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -2766,8 +2766,7 @@ static bool isTablenameToken(SStrToken* token) { SStrToken tableToken = {0}; extractTableNameFromToken(&tmpToken, &tableToken); - - return (strncasecmp(TSQL_TBNAME_L, tmpToken.z, tmpToken.n) == 0 && tmpToken.n == strlen(TSQL_TBNAME_L)); + return (tmpToken.n == strlen(TSQL_TBNAME_L) && strncasecmp(TSQL_TBNAME_L, tmpToken.z, tmpToken.n) == 0); } static int16_t doGetColumnIndex(SQueryInfo* pQueryInfo, int32_t index, SStrToken* pToken) { @@ -2798,7 +2797,8 @@ int32_t doGetColumnIndexByName(SStrToken* pToken, SQueryInfo* pQueryInfo, SColum if (isTablenameToken(pToken)) { pIndex->columnIndex = TSDB_TBNAME_COLUMN_INDEX; - } else if (strncasecmp(pToken->z, DEFAULT_PRIMARY_TIMESTAMP_COL_NAME, pToken->n) == 0) { + } else if (strlen(DEFAULT_PRIMARY_TIMESTAMP_COL_NAME) == pToken->n && + strncasecmp(pToken->z, DEFAULT_PRIMARY_TIMESTAMP_COL_NAME, pToken->n) == 0) { pIndex->columnIndex = PRIMARYKEY_TIMESTAMP_COL_INDEX; } else { // not specify the table name, try to locate the table index by column name diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 8ab3512cba..804878fa45 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -3047,9 +3047,10 @@ static void multiVnodeInsertFinalize(void* param, TAOS_RES* tres, int numOfRows) pParentObj->cmd.insertParam.schemaAttached = 1; } } - - if (!subAndCheckDone(tres, pParentObj, pSupporter->index)) { - tscDebug("0x%"PRIx64" insert:%p,%d completed, total:%d", pParentObj->self, tres, pSupporter->index, pParentObj->subState.numOfSub); + + int32_t suppIdx = pSupporter->index; + if (!subAndCheckDone(tres, pParentObj, suppIdx)) { + tscDebug("0x%"PRIx64" insert:%p,%d completed, total:%d", pParentObj->self, tres, suppIdx, pParentObj->subState.numOfSub); return; } diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index b42724a2ec..3195e74f02 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -297,7 +297,7 @@ bool tscHasColumnFilter(SQueryInfo* pQueryInfo) { size_t size = taosArrayGetSize(pQueryInfo->colList); for (int32_t i = 0; i < size; ++i) { - SColumn* pCol = taosArrayGet(pQueryInfo->colList, i); + SColumn* pCol = taosArrayGetP(pQueryInfo->colList, i); if (pCol->info.flist.numOfFilters > 0) { return true; } @@ -4382,7 +4382,9 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt if (pQueryAttr->fillType != TSDB_FILL_NONE) { pQueryAttr->fillVal = calloc(pQueryAttr->numOfOutput, sizeof(int64_t)); - memcpy(pQueryAttr->fillVal, pQueryInfo->fillVal, pQueryAttr->numOfOutput * sizeof(int64_t)); + int32_t fields = tscNumOfFields(pQueryInfo); + int32_t cpySize = fields < pQueryAttr->numOfOutput ? fields : pQueryAttr->numOfOutput; + memcpy(pQueryAttr->fillVal, pQueryInfo->fillVal, cpySize * sizeof(int64_t)); } pQueryAttr->srcRowSize = 0; diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index ef88f8bc06..ecdbc3be4f 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -5956,8 +5956,13 @@ SColumnInfo* extractColumnFilterInfo(SExprInfo* pExpr, int32_t numOfOutput, int3 pCols[i].colId = pExpr[i].base.resColId; pCols[i].flist.numOfFilters = pExpr[i].base.flist.numOfFilters; - pCols[i].flist.filterInfo = calloc(pCols[i].flist.numOfFilters, sizeof(SColumnFilterInfo)); - memcpy(pCols[i].flist.filterInfo, pExpr[i].base.flist.filterInfo, pCols[i].flist.numOfFilters * sizeof(SColumnFilterInfo)); + if (pCols[i].flist.numOfFilters != 0) { + pCols[i].flist.filterInfo = calloc(pCols[i].flist.numOfFilters, sizeof(SColumnFilterInfo)); + memcpy(pCols[i].flist.filterInfo, pExpr[i].base.flist.filterInfo, pCols[i].flist.numOfFilters * sizeof(SColumnFilterInfo)); + } else { + // avoid runtime error + pCols[i].flist.filterInfo = NULL; + } } assert(numOfFilter > 0); @@ -6416,10 +6421,10 @@ static SSDataBlock* hashDistinct(void* param, bool* newgroup) { if (isNull(val, type)) { continue; } - + int dummy; void* res = taosHashGet(pInfo->pSet, val, bytes); if (res == NULL) { - taosHashPut(pInfo->pSet, val, bytes, NULL, 0); + taosHashPut(pInfo->pSet, val, bytes, &dummy, sizeof(dummy)); char* start = pResultColInfoData->pData + bytes * pInfo->pRes->info.rows; memcpy(start, val, bytes); pRes->info.rows += 1; From 2b963dc3869acf962db01b28ff560e62d7cb2e7e Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 9 Jul 2021 08:49:40 +0800 Subject: [PATCH 2/8] [TD-5134] fix runtime error --- src/client/src/tscSQLParser.c | 4 +- src/client/src/tscSubquery.c | 13 ++-- src/client/src/tscUtil.c | 14 ++-- src/common/src/tarithoperator.c | 71 ++++++++++++++++++- src/query/inc/qTableMeta.h | 5 +- src/query/src/qExecutor.c | 1 + .../general/parser/col_arithmetic_query.sim | 4 +- 7 files changed, 97 insertions(+), 15 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 9e8cb325a8..db97af616b 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -5014,7 +5014,8 @@ int32_t validateFillNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNo size_t numOfFields = tscNumOfFields(pQueryInfo); if (pQueryInfo->fillVal == NULL) { - pQueryInfo->fillVal = calloc(numOfFields, sizeof(int64_t)); + pQueryInfo->fillVal = calloc(numOfFields, sizeof(int64_t)); + pQueryInfo->numOfFillVal = numOfFields; if (pQueryInfo->fillVal == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -8191,6 +8192,7 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf } taosArrayAddBatch(pQueryInfo->exprList1, (void*) p, numOfExpr); + tfree(p); } #if 0 diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 804878fa45..55f4251660 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -107,6 +107,9 @@ bool subAndCheckDone(SSqlObj *pSql, SSqlObj *pParentSql, int idx) { subState->states[idx] = 1; bool done = allSubqueryDone(pParentSql); + if (!done) { + tscDebug("0x%"PRIx64" sub:%p,%d completed, total:%d", pParentSql->self, pSql, idx, pParentSql->subState.numOfSub); + } pthread_mutex_unlock(&subState->mutex); return done; } @@ -1173,7 +1176,7 @@ static void tidTagRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow // no data exists in next vnode, mark the query completed // only when there is no subquery exits any more, proceeds to get the intersect of the tuple sets. if (!subAndCheckDone(pSql, pParentSql, pSupporter->subqueryIndex)) { - tscDebug("0x%"PRIx64" tagRetrieve:%p,%d completed, total:%d", pParentSql->self, tres, pSupporter->subqueryIndex, pParentSql->subState.numOfSub); + //tscDebug("0x%"PRIx64" tagRetrieve:%p,%d completed, total:%d", pParentSql->self, tres, pSupporter->subqueryIndex, pParentSql->subState.numOfSub); return; } @@ -1441,7 +1444,7 @@ static void joinRetrieveFinalResCallback(void* param, TAOS_RES* tres, int numOfR } if (!subAndCheckDone(pSql, pParentSql, pSupporter->subqueryIndex)) { - tscDebug("0x%"PRIx64" sub:0x%"PRIx64",%d completed, total:%d", pParentSql->self, pSql->self, pSupporter->subqueryIndex, pState->numOfSub); + //tscDebug("0x%"PRIx64" sub:0x%"PRIx64",%d completed, total:%d", pParentSql->self, pSql->self, pSupporter->subqueryIndex, pState->numOfSub); return; } @@ -3048,9 +3051,9 @@ static void multiVnodeInsertFinalize(void* param, TAOS_RES* tres, int numOfRows) } } - int32_t suppIdx = pSupporter->index; - if (!subAndCheckDone(tres, pParentObj, suppIdx)) { - tscDebug("0x%"PRIx64" insert:%p,%d completed, total:%d", pParentObj->self, tres, suppIdx, pParentObj->subState.numOfSub); + if (!subAndCheckDone(tres, pParentObj, pSupporter->index)) { + // concurrency problem, other thread already release pParentObj + //tscDebug("0x%"PRIx64" insert:%p,%d completed, total:%d", pParentObj->self, tres, suppIdx, pParentObj->subState.numOfSub); return; } diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 3195e74f02..62b57b484d 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -2949,6 +2949,7 @@ int32_t tscQueryInfoCopy(SQueryInfo* pQueryInfo, const SQueryInfo* pSrc) { pQueryInfo->tsBuf = NULL; pQueryInfo->fillType = pSrc->fillType; pQueryInfo->fillVal = NULL; + pQueryInfo->numOfFillVal = 0;; pQueryInfo->clauseLimit = pSrc->clauseLimit; pQueryInfo->prjOffset = pSrc->prjOffset; pQueryInfo->numOfTables = 0; @@ -2984,11 +2985,12 @@ int32_t tscQueryInfoCopy(SQueryInfo* pQueryInfo, const SQueryInfo* pSrc) { } if (pSrc->fillType != TSDB_FILL_NONE) { - pQueryInfo->fillVal = malloc(pSrc->fieldsInfo.numOfOutput * sizeof(int64_t)); + pQueryInfo->fillVal = calloc(1, pSrc->fieldsInfo.numOfOutput * sizeof(int64_t)); if (pQueryInfo->fillVal == NULL) { code = TSDB_CODE_TSC_OUT_OF_MEMORY; goto _error; } + pQueryInfo->numOfFillVal = pSrc->fieldsInfo.numOfOutput; memcpy(pQueryInfo->fillVal, pSrc->fillVal, pSrc->fieldsInfo.numOfOutput * sizeof(int64_t)); } @@ -3329,6 +3331,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, __async_cb_func_t pNewQueryInfo->tsBuf = NULL; pNewQueryInfo->fillType = pQueryInfo->fillType; pNewQueryInfo->fillVal = NULL; + pNewQueryInfo->numOfFillVal = 0; pNewQueryInfo->clauseLimit = pQueryInfo->clauseLimit; pNewQueryInfo->prjOffset = pQueryInfo->prjOffset; pNewQueryInfo->numOfTables = 0; @@ -3359,11 +3362,14 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, __async_cb_func_t } if (pQueryInfo->fillType != TSDB_FILL_NONE) { - pNewQueryInfo->fillVal = malloc(pQueryInfo->fieldsInfo.numOfOutput * sizeof(int64_t)); + //just make memory memory sanitizer happy + //refator later + pNewQueryInfo->fillVal = calloc(1, pQueryInfo->fieldsInfo.numOfOutput * sizeof(int64_t)); if (pNewQueryInfo->fillVal == NULL) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; goto _error; } + pNewQueryInfo->numOfFillVal = pQueryInfo->fieldsInfo.numOfOutput; memcpy(pNewQueryInfo->fillVal, pQueryInfo->fillVal, pQueryInfo->fieldsInfo.numOfOutput * sizeof(int64_t)); } @@ -4382,9 +4388,7 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt if (pQueryAttr->fillType != TSDB_FILL_NONE) { pQueryAttr->fillVal = calloc(pQueryAttr->numOfOutput, sizeof(int64_t)); - int32_t fields = tscNumOfFields(pQueryInfo); - int32_t cpySize = fields < pQueryAttr->numOfOutput ? fields : pQueryAttr->numOfOutput; - memcpy(pQueryAttr->fillVal, pQueryInfo->fillVal, cpySize * sizeof(int64_t)); + memcpy(pQueryAttr->fillVal, pQueryInfo->fillVal, pQueryInfo->numOfFillVal * sizeof(int64_t)); } pQueryAttr->srcRowSize = 0; diff --git a/src/common/src/tarithoperator.c b/src/common/src/tarithoperator.c index b37e358b9c..3779303e1a 100644 --- a/src/common/src/tarithoperator.c +++ b/src/common/src/tarithoperator.c @@ -18,7 +18,58 @@ #include "ttype.h" #include "tutil.h" #include "tarithoperator.h" +#include "tcompare.h" +//GET_TYPED_DATA(v, double, _right_type, (char *)&((right)[i])); +#define ARRAY_LIST_OP_DIV(left, right, _left_type, _right_type, len1, len2, out, op, _res_type, _ord) \ + { \ + int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : MAX(len1, len2) - 1; \ + int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; \ + \ + if ((len1) == (len2)) { \ + for (; i < (len2) && i >= 0; i += step, (out) += 1) { \ + if (isNull((char *)&((left)[i]), _left_type) || isNull((char *)&((right)[i]), _right_type)) { \ + SET_DOUBLE_NULL(out); \ + continue; \ + } \ + double v, z = 0.0; \ + GET_TYPED_DATA(v, double, _right_type, (char *)&((right)[i])); \ + if (getComparFunc(TSDB_DATA_TYPE_DOUBLE, 0)(&v, &z) == 0) { \ + SET_DOUBLE_NULL(out); \ + continue; \ + } \ + *(out) = (double)(left)[i] op(right)[i]; \ + } \ + } else if ((len1) == 1) { \ + for (; i >= 0 && i < (len2); i += step, (out) += 1) { \ + if (isNull((char *)(left), _left_type) || isNull((char *)&(right)[i], _right_type)) { \ + SET_DOUBLE_NULL(out); \ + continue; \ + } \ + double v, z = 0.0; \ + GET_TYPED_DATA(v, double, _right_type, (char *)&((right)[i])); \ + if (getComparFunc(TSDB_DATA_TYPE_DOUBLE, 0)(&v, &z) == 0) { \ + SET_DOUBLE_NULL(out); \ + continue; \ + } \ + *(out) = (double)(left)[0] op(right)[i]; \ + } \ + } else if ((len2) == 1) { \ + for (; i >= 0 && i < (len1); i += step, (out) += 1) { \ + if (isNull((char *)&(left)[i], _left_type) || isNull((char *)(right), _right_type)) { \ + SET_DOUBLE_NULL(out); \ + continue; \ + } \ + double v, z = 0.0; \ + GET_TYPED_DATA(v, double, _right_type, (char *)&((right)[0])); \ + if (getComparFunc(TSDB_DATA_TYPE_DOUBLE, 0)(&v, &z) == 0) { \ + SET_DOUBLE_NULL(out); \ + continue; \ + } \ + *(out) = (double)(left)[i] op(right)[0]; \ + } \ + } \ + } #define ARRAY_LIST_OP(left, right, _left_type, _right_type, len1, len2, out, op, _res_type, _ord) \ { \ int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : MAX(len1, len2) - 1; \ @@ -62,6 +113,12 @@ SET_DOUBLE_NULL(out); \ continue; \ } \ + double v, z = 0.0; \ + GET_TYPED_DATA(v, double, _right_type, (char *)&((right)[i])); \ + if (getComparFunc(TSDB_DATA_TYPE_DOUBLE, 0)(&v, &z) == 0) { \ + SET_DOUBLE_NULL(out); \ + continue; \ + } \ *(out) = (double)(left)[i] - ((int64_t)(((double)(left)[i]) / (right)[i])) * (right)[i]; \ } \ } else if (len1 == 1) { \ @@ -70,6 +127,12 @@ SET_DOUBLE_NULL(out); \ continue; \ } \ + double v, z = 0.0; \ + GET_TYPED_DATA(v, double, _right_type, (char *)&((right)[i])); \ + if (getComparFunc(TSDB_DATA_TYPE_DOUBLE, 0)(&v, &z) == 0) { \ + SET_DOUBLE_NULL(out); \ + continue; \ + } \ *(out) = (double)(left)[0] - ((int64_t)(((double)(left)[0]) / (right)[i])) * (right)[i]; \ } \ } else if ((len2) == 1) { \ @@ -78,6 +141,12 @@ SET_DOUBLE_NULL(out); \ continue; \ } \ + double v, z = 0.0; \ + GET_TYPED_DATA(v, double, _right_type, (char *)&((right)[0])); \ + if (getComparFunc(TSDB_DATA_TYPE_DOUBLE, 0)(&v, &z) == 0) { \ + SET_DOUBLE_NULL(out); \ + continue; \ + } \ *(out) = (double)(left)[i] - ((int64_t)(((double)(left)[i]) / (right)[0])) * (right)[0]; \ } \ } \ @@ -90,7 +159,7 @@ #define ARRAY_LIST_MULTI(left, right, _left_type, _right_type, len1, len2, out, _ord) \ ARRAY_LIST_OP(left, right, _left_type, _right_type, len1, len2, out, *, TSDB_DATA_TYPE_DOUBLE, _ord) #define ARRAY_LIST_DIV(left, right, _left_type, _right_type, len1, len2, out, _ord) \ - ARRAY_LIST_OP(left, right, _left_type, _right_type, len1, len2, out, /, TSDB_DATA_TYPE_DOUBLE, _ord) + ARRAY_LIST_OP_DIV(left, right, _left_type, _right_type, len1, len2, out, /, TSDB_DATA_TYPE_DOUBLE, _ord) #define ARRAY_LIST_REM(left, right, _left_type, _right_type, len1, len2, out, _ord) \ ARRAY_LIST_OP_REM(left, right, _left_type, _right_type, len1, len2, out, %, TSDB_DATA_TYPE_DOUBLE, _ord) diff --git a/src/query/inc/qTableMeta.h b/src/query/inc/qTableMeta.h index 7ec6dfbcf9..3f17e62f1e 100644 --- a/src/query/inc/qTableMeta.h +++ b/src/query/inc/qTableMeta.h @@ -106,11 +106,14 @@ typedef struct SQueryInfo { STagCond tagCond; SOrderVal order; - int16_t fillType; // final result fill type int16_t numOfTables; STableMetaInfo **pTableMetaInfo; struct STSBuf *tsBuf; + + int16_t fillType; // final result fill type int64_t * fillVal; // default value for fill + int32_t numOfFillVal; // fill value size + char * msg; // pointer to the pCmd->payload to keep error message temporarily int64_t clauseLimit; // limit for current sub clause diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index ecdbc3be4f..0c7fbf4dc8 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -992,6 +992,7 @@ static void doSetInputDataBlock(SOperatorInfo* pOperator, SQLFunctionCtx* pCtx, setBlockStatisInfo(&pCtx[i], pBlock, &pOperator->pExpr[i].base.colInfo); if (pCtx[i].functionId == TSDB_FUNC_ARITHM) { + pCtx[i].param[1].pz = (char*) &Operator->pRuntimeEnv->sasArray[i]; setArithParams((SArithmeticSupport*)pCtx[i].param[1].pz, &pOperator->pExpr[i], pBlock); } else { SColIndex* pCol = &pOperator->pExpr[i].base.colInfo; diff --git a/tests/script/general/parser/col_arithmetic_query.sim b/tests/script/general/parser/col_arithmetic_query.sim index 191f56fcfb..17ae6cfd6b 100644 --- a/tests/script/general/parser/col_arithmetic_query.sim +++ b/tests/script/general/parser/col_arithmetic_query.sim @@ -193,7 +193,7 @@ if $data02 != 0.000000000 then return -1 endi -if $data03 != 0.000000000 then +if $data03 != NULL then return -1 endi @@ -444,7 +444,7 @@ if $data02 != 8.077777778 then return -1 endi -if $data03 != inf then +if $data03 != NULL then return -1 endi From f8df9d40ce90038dd31b4609b7a9e22fdacc519d Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 9 Jul 2021 09:25:32 +0800 Subject: [PATCH 3/8] [TD-5134] fix runtime error --- src/query/src/qExecutor.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 0c7fbf4dc8..4ed7e19fb3 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -939,7 +939,9 @@ static TSKEY getStartTsKey(SQueryAttr* pQueryAttr, STimeWindow* win, const TSKEY static void setArithParams(SArithmeticSupport* sas, SExprInfo *pExprInfo, SSDataBlock* pSDataBlock) { sas->numOfCols = (int32_t) pSDataBlock->info.numOfCols; sas->pExprInfo = pExprInfo; - + if (sas->colList != NULL) { + return; + } sas->colList = calloc(1, pSDataBlock->info.numOfCols*sizeof(SColumnInfo)); for(int32_t i = 0; i < sas->numOfCols; ++i) { SColumnInfoData* pColData = taosArrayGet(pSDataBlock->pDataBlock, i); @@ -992,7 +994,6 @@ static void doSetInputDataBlock(SOperatorInfo* pOperator, SQLFunctionCtx* pCtx, setBlockStatisInfo(&pCtx[i], pBlock, &pOperator->pExpr[i].base.colInfo); if (pCtx[i].functionId == TSDB_FUNC_ARITHM) { - pCtx[i].param[1].pz = (char*) &Operator->pRuntimeEnv->sasArray[i]; setArithParams((SArithmeticSupport*)pCtx[i].param[1].pz, &pOperator->pExpr[i], pBlock); } else { SColIndex* pCol = &pOperator->pExpr[i].base.colInfo; From b36050cb95199bf9cec235f66fcf1e0050d727a5 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 9 Jul 2021 11:03:09 +0800 Subject: [PATCH 4/8] [TD-5134] fix runtime error --- src/client/src/tscSQLParser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index db97af616b..fdecb6eda5 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -5015,7 +5015,7 @@ int32_t validateFillNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNo if (pQueryInfo->fillVal == NULL) { pQueryInfo->fillVal = calloc(numOfFields, sizeof(int64_t)); - pQueryInfo->numOfFillVal = numOfFields; + pQueryInfo->numOfFillVal = (int32_t)numOfFields; if (pQueryInfo->fillVal == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } From 5a7917e69b861aed9ee4d75960c4c92e2a0c0850 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 10 Jul 2021 11:04:42 +0800 Subject: [PATCH 5/8] [TD-5134] fix runtime error --- src/client/src/tscSQLParser.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 9af6e0b8e6..5ecddb7910 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -3364,7 +3364,14 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, if (IS_NUMERIC_TYPE(pRight->value.nType)) { bufLen = 60; } else { - bufLen = pRight->value.nLen + 1; + /* + * make memory sanitizer happy; + */ + if (pRight->value.nLen == 0) { + bufLen = pRight->value.nLen + 2; + } else { + bufLen = pRight->value.nLen + 1; + } } if (pExpr->tokenId == TK_LE || pExpr->tokenId == TK_LT) { From 3050211e5ce73042a84eb2d4409c65269f0028e2 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 10 Jul 2021 13:58:11 +0800 Subject: [PATCH 6/8] merge develop --- src/client/src/tscSQLParser.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 5ecddb7910..ed76f8fd84 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -2799,7 +2799,9 @@ int32_t doGetColumnIndexByName(SStrToken* pToken, SQueryInfo* pQueryInfo, SColum pIndex->columnIndex = TSDB_TBNAME_COLUMN_INDEX; } else if (strlen(DEFAULT_PRIMARY_TIMESTAMP_COL_NAME) == pToken->n && strncasecmp(pToken->z, DEFAULT_PRIMARY_TIMESTAMP_COL_NAME, pToken->n) == 0) { - pIndex->columnIndex = PRIMARYKEY_TIMESTAMP_COL_INDEX; + pIndex->columnIndex = PRIMARYKEY_TIMESTAMP_COL_INDEX; // just make runtime happy, need fix java test case InsertSpecialCharacterJniTest + } else if (pToken->n == 0) { + pIndex->columnIndex = PRIMARYKEY_TIMESTAMP_COL_INDEX; // just make runtime happy, need fix java test case InsertSpecialCharacterJniTest } else { // not specify the table name, try to locate the table index by column name if (pIndex->tableIndex == COLUMN_INDEX_INITIAL_VAL) { From 2a107511f784b01c224e6b51c3175da719c9340c Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 14 Jul 2021 10:20:46 +0800 Subject: [PATCH 7/8] [TD-5134] fix runtime error --- src/client/src/tscSQLParser.c | 23 +++++++++++++++-------- src/client/src/tscServer.c | 5 +++++ src/client/src/tscSubquery.c | 11 ++++++++--- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index ed76f8fd84..dcd2d1e509 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -4812,7 +4812,7 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq int32_t type = 0; if ((ret = getQueryCondExpr(&pSql->cmd, pQueryInfo, pExpr, &condExpr, &type, (*pExpr)->tokenId)) != TSDB_CODE_SUCCESS) { - return ret; + goto PARSE_WHERE_EXIT; } tSqlExprCompact(pExpr); @@ -4822,17 +4822,17 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq // 1. check if it is a join query if ((ret = validateJoinExpr(&pSql->cmd, pQueryInfo, &condExpr)) != TSDB_CODE_SUCCESS) { - return ret; + goto PARSE_WHERE_EXIT; } // 2. get the query time range if ((ret = getTimeRangeFromExpr(&pSql->cmd, pQueryInfo, condExpr.pTimewindow)) != TSDB_CODE_SUCCESS) { - return ret; + goto PARSE_WHERE_EXIT; } // 3. get the tag query condition if ((ret = getTagQueryCondExpr(&pSql->cmd, pQueryInfo, &condExpr, pExpr)) != TSDB_CODE_SUCCESS) { - return ret; + goto PARSE_WHERE_EXIT; } // 4. get the table name query condition @@ -7707,11 +7707,18 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) { taosArrayPush(pVgroupList, &t); } - STableMeta* pMeta = tscTableMetaDup(pTableMeta); - STableMetaVgroupInfo p = { .pTableMeta = pMeta }; + //STableMeta* pMeta = tscTableMetaDup(pTableMeta); + //STableMetaVgroupInfo p = { .pTableMeta = pMeta }; + //const char* px = tNameGetTableName(pname); + //taosHashPut(pCmd->pTableMetaMap, px, strlen(px), &p, sizeof(STableMetaVgroupInfo)); + // avoid mem leak, may should update pTableMeta const char* px = tNameGetTableName(pname); - taosHashPut(pCmd->pTableMetaMap, px, strlen(px), &p, sizeof(STableMetaVgroupInfo)); + if (taosHashGet(pCmd->pTableMetaMap, px, strlen(px)) == NULL) { + STableMeta* pMeta = tscTableMetaDup(pTableMeta); + STableMetaVgroupInfo p = { .pTableMeta = pMeta, .pVgroupInfo = NULL}; + taosHashPut(pCmd->pTableMetaMap, px, strlen(px), &p, sizeof(STableMetaVgroupInfo)); + } } else { // add to the retrieve table meta array list. char* t = strdup(name); taosArrayPush(plist, &t); @@ -8161,7 +8168,7 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf // in case of join query, time range is required. if (QUERY_IS_JOIN_QUERY(pQueryInfo->type)) { - int64_t timeRange = ABS(pQueryInfo->window.skey - pQueryInfo->window.ekey); + uint64_t timeRange = (uint64_t)pQueryInfo->window.ekey - pQueryInfo->window.skey; if (timeRange == 0 && pQueryInfo->window.skey == 0) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); } diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index d30ee32d67..953dfb186a 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -2064,6 +2064,7 @@ int tscProcessMultiTableMetaRsp(SSqlObj *pSql) { STableMeta* pTableMeta = tscCreateTableMetaFromMsg(pMetaMsg); if (!tIsValidSchema(pTableMeta->schema, pTableMeta->tableInfo.numOfColumns, pTableMeta->tableInfo.numOfTags)) { tscError("0x%"PRIx64" invalid table meta from mnode, name:%s", pSql->self, pMetaMsg->tableFname); + tfree(pTableMeta); taosHashCleanup(pSet); taosReleaseRef(tscObjRef, pParentSql->self); return TSDB_CODE_TSC_INVALID_VALUE; @@ -2105,6 +2106,10 @@ int tscProcessMultiTableMetaRsp(SSqlObj *pSql) { assert(p != NULL); int32_t size = 0; + if (p->pVgroupInfo!= NULL) { + tscVgroupInfoClear(p->pVgroupInfo); + //tfree(p->pTableMeta); + } p->pVgroupInfo = createVgroupInfoFromMsg(pMsg, &size, pSql->self); pMsg += size; } diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 55f4251660..2fa8767eec 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -419,7 +419,9 @@ static void tscDestroyJoinSupporter(SJoinSupporter* pSupporter) { } // tscFieldInfoClear(&pSupporter->fieldsInfo); - + if (pSupporter->fieldsInfo.internalField != NULL) { + taosArrayDestroy(pSupporter->fieldsInfo.internalField); + } if (pSupporter->pTSBuf != NULL) { tsBufDestroy(pSupporter->pTSBuf); pSupporter->pTSBuf = NULL; @@ -433,7 +435,8 @@ static void tscDestroyJoinSupporter(SJoinSupporter* pSupporter) { } if (pSupporter->pVgroupTables != NULL) { - taosArrayDestroy(pSupporter->pVgroupTables); + //taosArrayDestroy(pSupporter->pVgroupTables); + tscFreeVgroupTableInfo(pSupporter->pVgroupTables); pSupporter->pVgroupTables = NULL; } @@ -892,7 +895,9 @@ static int32_t getIntersectionOfTableTuple(SQueryInfo* pQueryInfo, SSqlObj* pPar tscDebug("Join %d - num:%d", i, p->num); // sort according to the tag valu - qsort(p->pIdTagList, p->num, p->tagSize, tagValCompar); + if (p->pIdTagList != NULL) { + qsort(p->pIdTagList, p->num, p->tagSize, tagValCompar); + } if (!checkForDuplicateTagVal(pColSchema, p, pParentSql)) { for (int32_t j = 0; j <= i; j++) { From 361f81e403a39d57ea45cce5644a764a4f7dd4a7 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 14 Jul 2021 18:00:00 +0800 Subject: [PATCH 8/8] fix runtime bug --- src/client/src/tscSQLParser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index dcd2d1e509..c3449a5bfb 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -4827,12 +4827,12 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq // 2. get the query time range if ((ret = getTimeRangeFromExpr(&pSql->cmd, pQueryInfo, condExpr.pTimewindow)) != TSDB_CODE_SUCCESS) { - goto PARSE_WHERE_EXIT; + return ret; } // 3. get the tag query condition if ((ret = getTagQueryCondExpr(&pSql->cmd, pQueryInfo, &condExpr, pExpr)) != TSDB_CODE_SUCCESS) { - goto PARSE_WHERE_EXIT; + return ret; } // 4. get the table name query condition