From c454def8b72e78baa3f0819b31b76d1afa560f3e Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 1 Jun 2020 11:44:23 +0800 Subject: [PATCH] [td-225] update the intermediate result size --- src/client/inc/tsclient.h | 2 +- src/client/src/tscFunctionImpl.c | 2 +- src/client/src/tscSQLParser.c | 48 ++++++++++++++---------------- src/client/src/tscSecondaryMerge.c | 2 +- src/client/src/tscSubquery.c | 2 +- src/inc/taosmsg.h | 2 +- src/query/inc/tsqlfunction.h | 2 +- 7 files changed, 28 insertions(+), 32 deletions(-) diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index 35d3184ccb..f1b620176d 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -84,7 +84,7 @@ typedef struct SSqlExpr { int16_t functionId; // function id in aAgg array int16_t resType; // return value type int16_t resBytes; // length of return value - int16_t interBytes; // inter result buffer size + int32_t interBytes; // inter result buffer size int16_t numOfParams; // argument value of each function tVariant param[3]; // parameters are not more than 3 int32_t offset; // sub result column value of arithmetic expression. diff --git a/src/client/src/tscFunctionImpl.c b/src/client/src/tscFunctionImpl.c index 683da0822c..baefdbe102 100644 --- a/src/client/src/tscFunctionImpl.c +++ b/src/client/src/tscFunctionImpl.c @@ -153,7 +153,7 @@ typedef struct SRateInfo { int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionId, int32_t param, int16_t *type, - int16_t *bytes, int16_t *interBytes, int16_t extLength, bool isSuperTable) { + int16_t *bytes, int32_t *interBytes, int16_t extLength, bool isSuperTable) { if (!isValidDataType(dataType, dataBytes)) { tscError("Illegal data type %d or data type length %d", dataType, dataBytes); return TSDB_CODE_INVALID_SQL; diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index c24c97e286..965e85efbd 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -1594,7 +1594,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr int16_t resultType = 0; int16_t resultSize = 0; - int16_t intermediateResSize = 0; + int32_t intermediateResSize = 0; int16_t functionID = 0; if (changeFunctionID(optr, &functionID) != TSDB_CODE_SUCCESS) { @@ -1901,7 +1901,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr int16_t bytes = 0; int16_t type = 0; - int16_t inter = 0; + int32_t inter = 0; int32_t ret = getResultDataInfo(s.type, s.bytes, TSDB_FUNC_TID_TAG, 0, &type, &bytes, &inter, 0, 0); assert(ret == TSDB_CODE_SUCCESS); @@ -2287,7 +2287,7 @@ int32_t tscTansformSQLFuncForSTableQuery(SQueryInfo* pQueryInfo) { int16_t bytes = 0; int16_t type = 0; - int16_t intermediateBytes = 0; + int32_t interBytes = 0; size_t size = tscSqlExprNumOfExprs(pQueryInfo); for (int32_t k = 0; k < size; ++k) { @@ -2301,13 +2301,13 @@ int32_t tscTansformSQLFuncForSTableQuery(SQueryInfo* pQueryInfo) { (functionId >= TSDB_FUNC_FIRST_DST && functionId <= TSDB_FUNC_LAST_DST) || (functionId >= TSDB_FUNC_RATE && functionId <= TSDB_FUNC_AVG_IRATE)) { if (getResultDataInfo(pSrcSchema->type, pSrcSchema->bytes, functionId, pExpr->param[0].i64Key, &type, &bytes, - &intermediateBytes, 0, true) != TSDB_CODE_SUCCESS) { + &interBytes, 0, true) != TSDB_CODE_SUCCESS) { return TSDB_CODE_INVALID_SQL; } tscSqlExprUpdate(pQueryInfo, k, functionId, pExpr->colInfo.colIndex, TSDB_DATA_TYPE_BINARY, bytes); // todo refactor - pExpr->interBytes = intermediateBytes; + pExpr->interBytes = interBytes; } } @@ -2327,27 +2327,23 @@ void tscRestoreSQLFuncForSTableQuery(SQueryInfo* pQueryInfo) { SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i); SSchema* pSchema = tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, pExpr->colInfo.colIndex); -// if (/*(pExpr->functionId >= TSDB_FUNC_FIRST_DST && pExpr->functionId <= TSDB_FUNC_LAST_DST) || -// (pExpr->functionId >= TSDB_FUNC_SUM && pExpr->functionId <= TSDB_FUNC_MAX) || -// pExpr->functionId == TSDB_FUNC_LAST_ROW*/) { - // the final result size and type in the same as query on single table. - // so here, set the flag to be false; - int16_t inter = 0; - - int32_t functionId = pExpr->functionId; - if (functionId >= TSDB_FUNC_TS && functionId <= TSDB_FUNC_DIFF) { - continue; - } - - if (functionId == TSDB_FUNC_FIRST_DST) { - functionId = TSDB_FUNC_FIRST; - } else if (functionId == TSDB_FUNC_LAST_DST) { - functionId = TSDB_FUNC_LAST; - } - - getResultDataInfo(pSchema->type, pSchema->bytes, functionId, 0, &pExpr->resType, &pExpr->resBytes, - &inter, 0, false); -// } + // the final result size and type in the same as query on single table. + // so here, set the flag to be false; + int32_t inter = 0; + + int32_t functionId = pExpr->functionId; + if (functionId >= TSDB_FUNC_TS && functionId <= TSDB_FUNC_DIFF) { + continue; + } + + if (functionId == TSDB_FUNC_FIRST_DST) { + functionId = TSDB_FUNC_FIRST; + } else if (functionId == TSDB_FUNC_LAST_DST) { + functionId = TSDB_FUNC_LAST; + } + + getResultDataInfo(pSchema->type, pSchema->bytes, functionId, 0, &pExpr->resType, &pExpr->resBytes, + &inter, 0, false); } } diff --git a/src/client/src/tscSecondaryMerge.c b/src/client/src/tscSecondaryMerge.c index 219819a2b0..5737564877 100644 --- a/src/client/src/tscSecondaryMerge.c +++ b/src/client/src/tscSecondaryMerge.c @@ -689,7 +689,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr SSchema *p1 = tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, pExpr->colInfo.colIndex); - int16_t inter = 0; + int32_t inter = 0; int16_t type = -1; int16_t bytes = 0; diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 4e34c1028b..99163ba327 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -1084,7 +1084,7 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSupporter int16_t bytes = 0; int16_t type = 0; - int16_t inter = 0; + int32_t inter = 0; getResultDataInfo(s.type, s.bytes, TSDB_FUNC_TID_TAG, 0, &type, &bytes, &inter, 0, 0); diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index b6d45c2091..da6d0847ec 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -370,7 +370,7 @@ typedef struct SExprInfo { struct tExprNode* pExpr; int16_t bytes; int16_t type; - int16_t interBytes; + int32_t interBytes; } SExprInfo; typedef struct SColumnFilterInfo { diff --git a/src/query/inc/tsqlfunction.h b/src/query/inc/tsqlfunction.h index e348ceb177..22d126f7a2 100644 --- a/src/query/inc/tsqlfunction.h +++ b/src/query/inc/tsqlfunction.h @@ -217,7 +217,7 @@ typedef struct SQLAggFuncElem { #define GET_RES_INFO(ctx) ((ctx)->resultInfo) int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionId, int32_t param, int16_t *type, - int16_t *len, int16_t *interBytes, int16_t extLength, bool isSuperTable); + int16_t *len, int32_t *interBytes, int16_t extLength, bool isSuperTable); #define IS_STREAM_QUERY_VALID(x) (((x)&TSDB_FUNCSTATE_STREAM) != 0) #define IS_MULTIOUTPUT(x) (((x)&TSDB_FUNCSTATE_MO) != 0) -- GitLab