diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index 6d01538d8fef438eb18fe05f5adf6bd313cbd7f3..d4cb66e16fd8abe9709e0e07aebf207a89cb473b 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 5696611387049b890eeaf726d465b67d6dbc3a4d..4e7a8ed6bd38e0973f40d858802901f61ca448c8 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 0c51898a79351d069452dc9e03f9759a185b4625..87ddd704d29e1404e6bf8879edf679116ec5244a 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 5c7d8789eaa54d52e34dcb1d4e4c83eae7d23bbe..ae1f4058fabe9f191ee87998c42fbb7eadba958a 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);