From 6dade8a092aaae4fb48f0d646b34e8913e125a7e Mon Sep 17 00:00:00 2001 From: hjxilinx Date: Sat, 4 Apr 2020 16:20:25 +0800 Subject: [PATCH] [TD-98] cleanup the status code in SqlCmd object in SQL parse stage. --- src/client/src/tscParseInsert.c | 12 +++++++++--- src/client/src/tscSQLParser.c | 1 + src/client/src/tscServer.c | 1 - src/client/src/tscUtil.c | 9 +++++---- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index 6d01538d8f..d4cb66e16f 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -1291,7 +1291,7 @@ int tsParseInsertSql(SSqlObj *pSql) { return doParseInsertSql(pSql, pSql->sqlstr + index); } -int tsParseSql(SSqlObj *pSql, bool multiVnodeInsertion) { +int tsParseSql(SSqlObj *pSql, bool initalParse) { int32_t ret = TSDB_CODE_SUCCESS; tscTrace("continue parse sql: %s", pSql->asyncTblPos); @@ -1301,7 +1301,7 @@ int tsParseSql(SSqlObj *pSql, bool multiVnodeInsertion) { * Set the fp before parse the sql string, in case of getmetermeta failed, in which * the error handle callback function can rightfully restore the user defined function (fp) */ - if (pSql->fp != NULL && multiVnodeInsertion) { + if (pSql->fp != NULL && initalParse) { pSql->fetchFp = pSql->fp; // replace user defined callback function with multi-insert proxy function @@ -1311,7 +1311,13 @@ int tsParseSql(SSqlObj *pSql, bool multiVnodeInsertion) { ret = tsParseInsertSql(pSql); } else { ret = tscAllocPayload(&pSql->cmd, TSDB_DEFAULT_PAYLOAD_SIZE); - if (TSDB_CODE_SUCCESS != ret) return ret; + if (TSDB_CODE_SUCCESS != ret) { + return ret; + } + + if (initalParse) { + tscFreeSqlCmdData(&pSql->cmd); + } SSqlInfo SQLInfo = {0}; tSQLParse(&SQLInfo, pSql->sqlstr); diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 5696611387..4e7a8ed6bd 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -497,6 +497,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { } } else if (pCreateTable->type == TSQL_CREATE_TABLE_FROM_STABLE) { + assert(pCmd->numOfCols == 0); if ((code = doCheckForCreateFromStable(pSql, pInfo)) != TSDB_CODE_SUCCESS) { return code; } diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 0c51898a79..87ddd704d2 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -1225,7 +1225,6 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SCreateTableSQL *pCreateTable = pInfo->pCreateTableInfo; pCreateTableMsg->igExists = pCreateTable->existCheck ? 1 : 0; - pCreateTableMsg->numOfColumns = htons(pCmd->numOfCols); pCreateTableMsg->numOfTags = htons(pCmd->count); diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 5c7d8789ea..ae1f4058fa 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -394,6 +394,10 @@ void tscDestroyResPointerInfo(SSqlRes* pRes) { } void tscFreeSqlCmdData(SSqlCmd* pCmd) { + pCmd->command = 0; + pCmd->numOfCols = 0; + pCmd->count = 0; + pCmd->pDataBlocks = tscDestroyBlockArrayList(pCmd->pDataBlocks); tscFreeSubqueryInfo(pCmd); } @@ -454,9 +458,7 @@ void tscFreeSqlObjPartial(SSqlObj* pSql) { cmd == TSDB_SQL_METRIC_JOIN_RETRIEVE) { tscRemoveFromSqlList(pSql); } - - pCmd->command = 0; - + // pSql->sqlstr will be used by tscBuildQueryStreamDesc pthread_mutex_lock(&pObj->mutex); tfree(pSql->sqlstr); @@ -1899,7 +1901,6 @@ void tscFreeSubqueryInfo(SSqlCmd* pCmd) { for (int32_t i = 0; i < pCmd->numOfClause; ++i) { char* addr = (char*)pCmd - offsetof(SSqlObj, cmd); - SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, i); doClearSubqueryInfo(pQueryInfo);