diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index 313d1963fd..537f559e90 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -131,6 +131,7 @@ int32_t tValueCompare(const SValue *tv1, const SValue *tv2); int32_t tRowBuild(SArray *aColVal, const STSchema *pTSchema, SRow **ppRow); int32_t tRowGet(SRow *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal); void tRowDestroy(SRow *pRow); +void tRowDataClear(SRow *pColData); int32_t tRowSort(SArray *aRowP); int32_t tRowMerge(SArray *aRowP, STSchema *pTSchema, int8_t flag); int32_t tRowUpsertColData(SRow *pRow, STSchema *pTSchema, SColData *aColData, int32_t nColData, int32_t flag); diff --git a/source/client/src/clientStmt2.c b/source/client/src/clientStmt2.c index c558935281..d9b2b4b2c5 100644 --- a/source/client/src/clientStmt2.c +++ b/source/client/src/clientStmt2.c @@ -1411,10 +1411,13 @@ int stmtBindBatch2(TAOS_STMT2* stmt, TAOS_STMT2_BIND* bind, int32_t colIdx) { if (pStmt->sql.stbInterlaceMode) { (*pDataBlock)->pData->flags = 0; code = qBindStmtStbColsValue2(*pDataBlock, pCols, bind, pStmt->exec.pRequest->msgBuf, - pStmt->exec.pRequest->msgBufLen, &pStmt->sql.siInfo.pTSchema, pStmt->sql.pBindInfo, pStmt->taos->optionInfo.charsetCxt); + pStmt->exec.pRequest->msgBufLen, &pStmt->sql.siInfo.pTSchema, pStmt->sql.pBindInfo, + pStmt->taos->optionInfo.charsetCxt); } else { + taosArrayDestroy(pCols); + (*pDataBlock)->pData->aCol = taosArrayInit(bind->num, POINTER_BYTES); code = - qBindStmtColsValue2(*pDataBlock, pCols, bind, pStmt->exec.pRequest->msgBuf, pStmt->exec.pRequest->msgBufLen, + qBindStmtColsValue2(*pDataBlock, (*pDataBlock)->pData->aRowP, bind, pStmt->exec.pRequest->msgBuf, pStmt->exec.pRequest->msgBufLen, &pStmt->sql.siInfo.pTSchema, pStmt->sql.pBindInfo, pStmt->taos->optionInfo.charsetCxt); } diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index f8f3c0f770..1d60218825 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -669,6 +669,15 @@ void tRowDestroy(SRow *pRow) { if (pRow) taosMemoryFree(pRow); } +void tRowDataClear(SRow *pColData) { + pColData->ts = 0; + pColData->len = 0; + pColData->sver = 0; + pColData->flag = 0; + pColData->numOfPKs = 0; +} + + static int32_t tRowPCmprFn(const void *p1, const void *p2) { SRowKey key1, key2; tRowGetKey(*(SRow **)p1, &key1); diff --git a/source/libs/parser/src/parInsertStmt.c b/source/libs/parser/src/parInsertStmt.c index 9766776ee8..a4af0e0dd9 100644 --- a/source/libs/parser/src/parInsertStmt.c +++ b/source/libs/parser/src/parInsertStmt.c @@ -54,8 +54,13 @@ int32_t qCloneCurrentTbData(STableDataCxt* pDataBlock, SSubmitTbData** pData) { int32_t colNum = taosArrayGetSize(pNew->aCol); for (int32_t i = 0; i < colNum; ++i) { - SColData* pCol = (SColData*)taosArrayGet(pNew->aCol, i); - tColDataDeepClear(pCol); + if (pDataBlock->pData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) { + SColData* pCol = (SColData*)taosArrayGet(pNew->aCol, i); + tColDataDeepClear(pCol); + } else { + SRow* pRowp = (SRow*)taosArrayGet(pNew->aCol, i); + tRowDataClear(pRowp); + } } return TSDB_CODE_SUCCESS; @@ -841,12 +846,6 @@ int32_t qBindStmtColsValue2(void* pBlock, SArray* pCols, TAOS_STMT2_BIND* bind, lastColId = pColSchema->colId; } - SColData* pCol = taosArrayGet(pCols, c); - if (pCol == NULL || pColSchema == NULL) { - code = buildInvalidOperationMsg(&pBuf, "get column schema or column data failed"); - goto _return; - } - if (bind[c].num != rowNum) { code = buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same"); goto _return; @@ -863,7 +862,7 @@ int32_t qBindStmtColsValue2(void* pBlock, SArray* pCols, TAOS_STMT2_BIND* bind, if (code) { goto _return; } - pBind = &ncharBind; + pBindInfos[c].bind = &ncharBind; } else { pBindInfos[c].bind = bind + c; } @@ -872,14 +871,14 @@ int32_t qBindStmtColsValue2(void* pBlock, SArray* pCols, TAOS_STMT2_BIND* bind, pBindInfos[c].type = pColSchema->type; pBindInfos[c].bytes = pColSchema->bytes; - // code = tColDataAddValueByBind2(pCol, pBind, - // IS_VAR_DATA_TYPE(pColSchema->type) ? pColSchema->bytes - VARSTR_HEADER_SIZE : -1, - // initCtxAsText, checkWKB); - if (code) { - goto _return; + if (code) { + goto _return; + } } -} - code = tRowBuildFromBind2(pBindInfos, boundInfo->numOfBound, colInOrder, *pTSchema, pCols, &pDataBlock->ordered, &pDataBlock->duplicateTs); + + pDataBlock->pData->flags &= ~SUBMIT_REQ_COLUMN_DATA_FORMAT; + code = tRowBuildFromBind2(pBindInfos, boundInfo->numOfBound, colInOrder, *pTSchema, pCols, &pDataBlock->ordered, + &pDataBlock->duplicateTs); qDebug("stmt all %d columns bind %d rows data", boundInfo->numOfBound, rowNum); _return: @@ -1127,15 +1126,24 @@ int32_t qResetStmtDataBlock(STableDataCxt* block, bool deepClear) { int32_t colNum = taosArrayGetSize(pBlock->pData->aCol); for (int32_t i = 0; i < colNum; ++i) { - SColData* pCol = (SColData*)taosArrayGet(pBlock->pData->aCol, i); - if (pCol == NULL) { - qError("qResetStmtDataBlock column is NULL"); - return terrno; - } - if (deepClear) { - tColDataDeepClear(pCol); + if (pBlock->pData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) { + SColData* pCol = (SColData*)taosArrayGet(pBlock->pData->aCol, i); + if (pCol == NULL) { + qError("qResetStmtDataBlock column is NULL"); + return terrno; + } + if (deepClear) { + tColDataDeepClear(pCol); + } else { + tColDataClear(pCol); + } } else { - tColDataClear(pCol); + SRow* aRowP = (SRow*)taosArrayGet(pBlock->pData->aRowP, i); + if (aRowP == NULL) { + qError("qResetStmtDataBlock row pointer is NULL"); + return terrno; + } + tRowDataClear(aRowP); } }