From 68bd8d28f09845ab64193409c736f138e7e906a5 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Wed, 21 Aug 2024 15:30:21 +0800 Subject: [PATCH] stmt2/binding: no hole for cols binding --- include/client/taos.h | 11 +++--- source/common/src/tdataformat.c | 15 ++++---- source/libs/parser/src/parInsertStmt.c | 30 +++++++++------- tests/script/api/stmt2-nohole.c | 48 +++++++++++++++----------- 4 files changed, 60 insertions(+), 44 deletions(-) diff --git a/include/client/taos.h b/include/client/taos.h index 9bd1517d38..90d6712d6e 100644 --- a/include/client/taos.h +++ b/include/client/taos.h @@ -210,12 +210,11 @@ typedef struct { } TAOS_STMT2_OPTION; typedef struct { - int buffer_type; - void *buffer; - uintptr_t buffer_length; - int32_t *length; - char *is_null; - int num; + int buffer_type; + void *buffer; + int32_t *length; + char *is_null; + int num; } TAOS_STMT2_BIND; typedef struct { diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index d12b44a093..6e5e614481 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -3127,6 +3127,7 @@ int32_t tColDataAddValueByBind2(SColData *pColData, TAOS_STMT2_BIND *pBind, int3 } if (IS_VAR_DATA_TYPE(pColData->type)) { // var-length data type + uint8_t *buf = pBind->buffer; for (int32_t i = 0; i < pBind->num; ++i) { if (pBind->is_null && pBind->is_null[i]) { if (pColData->cflag & COL_IS_KEY) { @@ -3139,8 +3140,8 @@ int32_t tColDataAddValueByBind2(SColData *pColData, TAOS_STMT2_BIND *pBind, int3 uError("var data length too big, len:%d, max:%d", pBind->length[i], buffMaxLen); return TSDB_CODE_INVALID_PARA; } else { - code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_VALUE]( - pColData, (uint8_t *)pBind->buffer + pBind->buffer_length * i, pBind->length[i]); + code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_VALUE](pColData, buf, pBind->length[i]); + buf += pBind->length[i]; } } } else { // fixed-length data type @@ -3164,7 +3165,7 @@ int32_t tColDataAddValueByBind2(SColData *pColData, TAOS_STMT2_BIND *pBind, int3 // optimize (todo) for (int32_t i = 0; i < pBind->num; ++i) { code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_VALUE]( - pColData, (uint8_t *)pBind->buffer + TYPE_BYTES[pColData->type] * i, pBind->buffer_length); + pColData, (uint8_t *)pBind->buffer + TYPE_BYTES[pColData->type] * i, TYPE_BYTES[pColData->type]); } } else if (allNull) { // optimize (todo) @@ -3179,7 +3180,7 @@ int32_t tColDataAddValueByBind2(SColData *pColData, TAOS_STMT2_BIND *pBind, int3 if (code) goto _exit; } else { code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_VALUE]( - pColData, (uint8_t *)pBind->buffer + TYPE_BYTES[pColData->type] * i, pBind->buffer_length); + pColData, (uint8_t *)pBind->buffer + TYPE_BYTES[pColData->type] * i, TYPE_BYTES[pColData->type]); } } } @@ -3244,8 +3245,10 @@ int32_t tRowBuildFromBind2(SBindInfo2 *infos, int32_t numOfInfos, bool infoSorte *data += length; // value.pData = (uint8_t *)infos[iInfo].bind->buffer + infos[iInfo].bind->buffer_length * iRow; } else { - (void)memcpy(&value.val, (uint8_t *)infos[iInfo].bind->buffer + infos[iInfo].bind->buffer_length * iRow, - infos[iInfo].bytes /*bind->buffer_length*/); + (void)memcpy( + &value.val, + (uint8_t *)infos[iInfo].bind->buffer + infos[iInfo].bytes /*infos[iInfo].bind->buffer_length*/ * iRow, + infos[iInfo].bytes /*bind->buffer_length*/); } colVal = COL_VAL_VALUE(infos[iInfo].columnId, value); } diff --git a/source/libs/parser/src/parInsertStmt.c b/source/libs/parser/src/parInsertStmt.c index 51373f0828..5b459243a4 100644 --- a/source/libs/parser/src/parInsertStmt.c +++ b/source/libs/parser/src/parInsertStmt.c @@ -588,8 +588,8 @@ end: } static int32_t convertStmtStbNcharCol2(SMsgBuf* pMsgBuf, SSchema* pSchema, TAOS_STMT2_BIND* src, TAOS_STMT2_BIND* dst) { - int32_t output = 0; - int32_t max_buf_len = pSchema->bytes - VARSTR_HEADER_SIZE; + int32_t output = 0; + const int32_t max_buf_len = pSchema->bytes - VARSTR_HEADER_SIZE; dst->buffer = taosMemoryCalloc(src->num, max_buf_len); if (NULL == dst->buffer) { @@ -710,14 +710,16 @@ _return: } static int32_t convertStmtNcharCol2(SMsgBuf* pMsgBuf, SSchema* pSchema, TAOS_STMT2_BIND* src, TAOS_STMT2_BIND* dst) { - int32_t output = 0; + int32_t output = 0; + const int32_t max_buf_len = pSchema->bytes - VARSTR_HEADER_SIZE; + int32_t newBuflen = (pSchema->bytes - VARSTR_HEADER_SIZE) * src->num; - if (dst->buffer_length < newBuflen) { - dst->buffer = taosMemoryRealloc(dst->buffer, newBuflen); - if (NULL == dst->buffer) { - return TSDB_CODE_OUT_OF_MEMORY; - } + // if (dst->buffer_length < newBuflen) { + dst->buffer = taosMemoryRealloc(dst->buffer, newBuflen); + if (NULL == dst->buffer) { + return TSDB_CODE_OUT_OF_MEMORY; } + //} if (NULL == dst->length) { dst->length = taosMemoryRealloc(dst->length, sizeof(int32_t) * src->num); @@ -727,15 +729,17 @@ static int32_t convertStmtNcharCol2(SMsgBuf* pMsgBuf, SSchema* pSchema, TAOS_STM } } - dst->buffer_length = pSchema->bytes - VARSTR_HEADER_SIZE; - + // dst->buffer_length = pSchema->bytes - VARSTR_HEADER_SIZE; + char* src_buf = src->buffer; + char* dst_buf = dst->buffer; for (int32_t i = 0; i < src->num; ++i) { if (src->is_null && src->is_null[i]) { continue; } - if (!taosMbsToUcs4(((char*)src->buffer) + src->buffer_length * i, src->length[i], - (TdUcs4*)(((char*)dst->buffer) + dst->buffer_length * i), dst->buffer_length, &output)) { + /*if (!taosMbsToUcs4(((char*)src->buffer) + src->buffer_length * i, src->length[i], + (TdUcs4*)(((char*)dst->buffer) + dst->buffer_length * i), dst->buffer_length, &output)) {*/ + if (!taosMbsToUcs4(src_buf, src->length[i], (TdUcs4*)dst_buf, max_buf_len, &output)) { if (errno == E2BIG) { return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name); } @@ -745,6 +749,8 @@ static int32_t convertStmtNcharCol2(SMsgBuf* pMsgBuf, SSchema* pSchema, TAOS_STM } dst->length[i] = output; + src_buf += src->length[i]; + dst_buf += output; } dst->buffer_type = src->buffer_type; diff --git a/tests/script/api/stmt2-nohole.c b/tests/script/api/stmt2-nohole.c index 8ec5136631..9e6b94778c 100644 --- a/tests/script/api/stmt2-nohole.c +++ b/tests/script/api/stmt2-nohole.c @@ -99,7 +99,7 @@ void veriry_stmt(TAOS* taos) { #include "time.h" clock_t start, end; - TAOS_STMT2_OPTION option = {0, true, true, stmtAsyncQueryCb, NULL}; + TAOS_STMT2_OPTION option = {0, true, false, stmtAsyncQueryCb, NULL}; start = clock(); TAOS_STMT2* stmt = taos_stmt2_init(taos, &option); @@ -110,63 +110,63 @@ void veriry_stmt(TAOS* taos) { char is_null[10] = {0}; params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; - params[0].buffer_length = sizeof(v.ts[0]); + // params[0].buffer_length = sizeof(v.ts[0]); params[0].buffer = v.ts; params[0].length = t64_len; params[0].is_null = is_null; params[0].num = 10; params[1].buffer_type = TSDB_DATA_TYPE_BOOL; - params[1].buffer_length = sizeof(v.b[0]); + // params[1].buffer_length = sizeof(v.b[0]); params[1].buffer = v.b; params[1].length = t8_len; params[1].is_null = is_null; params[1].num = 10; params[2].buffer_type = TSDB_DATA_TYPE_TINYINT; - params[2].buffer_length = sizeof(v.v1[0]); + // params[2].buffer_length = sizeof(v.v1[0]); params[2].buffer = v.v1; params[2].length = t8_len; params[2].is_null = is_null; params[2].num = 10; params[3].buffer_type = TSDB_DATA_TYPE_SMALLINT; - params[3].buffer_length = sizeof(v.v2[0]); + // params[3].buffer_length = sizeof(v.v2[0]); params[3].buffer = v.v2; params[3].length = t16_len; params[3].is_null = is_null; params[3].num = 10; params[4].buffer_type = TSDB_DATA_TYPE_INT; - params[4].buffer_length = sizeof(v.v4[0]); + // params[4].buffer_length = sizeof(v.v4[0]); params[4].buffer = v.v4; params[4].length = t32_len; params[4].is_null = is_null; params[4].num = 10; params[5].buffer_type = TSDB_DATA_TYPE_BIGINT; - params[5].buffer_length = sizeof(v.v8[0]); + // params[5].buffer_length = sizeof(v.v8[0]); params[5].buffer = v.v8; params[5].length = t64_len; params[5].is_null = is_null; params[5].num = 10; params[6].buffer_type = TSDB_DATA_TYPE_FLOAT; - params[6].buffer_length = sizeof(v.f4[0]); + // params[6].buffer_length = sizeof(v.f4[0]); params[6].buffer = v.f4; params[6].length = float_len; params[6].is_null = is_null; params[6].num = 10; params[7].buffer_type = TSDB_DATA_TYPE_DOUBLE; - params[7].buffer_length = sizeof(v.f8[0]); + // params[7].buffer_length = sizeof(v.f8[0]); params[7].buffer = v.f8; params[7].length = double_len; params[7].is_null = is_null; params[7].num = 10; /* params[8].buffer_type = TSDB_DATA_TYPE_BINARY; - params[8].buffer_length = sizeof(v.bin[0]); + //params[8].buffer_length = sizeof(v.bin[0]); params[8].buffer = v.bin; params[8].length = bin_len; params[8].is_null = is_null; @@ -180,7 +180,7 @@ void veriry_stmt(TAOS* taos) { params[8].num = 10; params[9].buffer_type = TSDB_DATA_TYPE_NCHAR; - params[9].buffer_length = sizeof(v.blob[0]); + // params[9].buffer_length = sizeof(v.blob[0]); params[9].buffer = v.blob; params[9].length = blob_len; params[9].is_null = is_null; @@ -205,9 +205,17 @@ void veriry_stmt(TAOS* taos) { } */ - int64_t ts = 1591060628000; - char* blob2_buffer = v.blob2; - char* blob_buffer = v.blob; + int64_t ts = 1591060628000; + char* blob2_buffer = v.blob2; + char* blob_buffer = v.blob; + const char* blob2_str[] = { + "一二三四五六七十九八", "一二三四五六七十九", "一二三四五六七十", "一二三四五六七", "一二三四五六", + "一二三四五", "一二三四", "一二三", "一二", "一", + }; + const char* blob_str[] = { + "一", "一二", "一二三", "一二三四", "一二三四五", + "一二三四五六", "一二三四五六七", "一二三四五六七八", "一二三四五六七八九", "一二三四五六七八九十", + }; for (int i = 0; i < 10; ++i) { is_null[i] = 0; @@ -224,10 +232,10 @@ void veriry_stmt(TAOS* taos) { } // strcpy(v.blob2[i], "一二三四五六七十九八"); // strcpy(v.blob[i], "一二三四五六七八九十"); - const char* blob2_str = "一二三四五六七十九八"; - const char* blob_str = "一二三四五六七八九十"; - strcpy(blob2_buffer, blob2_str); - strcpy(blob_buffer, blob_str); + // const char* blob2_str = "一二三四五六七十九八"; + // const char* blob_str = "一二三四五六七八九十"; + strcpy(blob2_buffer, blob2_str[i]); + strcpy(blob_buffer, blob_str[i]); t8_len[i] = sizeof(int8_t); t16_len[i] = sizeof(int16_t); @@ -238,8 +246,8 @@ void veriry_stmt(TAOS* taos) { bin_len[i] = sizeof(v.bin[0]); // blob_len[i] = (int32_t)strlen(v.blob[i]); // blob_len2[i] = (int32_t)strlen(v.blob2[i]); - blob_len[i] = (int32_t)strlen(blob_str); - blob_len2[i] = (int32_t)strlen(blob2_str); + blob_len[i] = (int32_t)strlen(blob_str[i]); + blob_len2[i] = (int32_t)strlen(blob2_str[i]); blob_buffer += blob_len[i]; blob2_buffer += blob_len2[i]; }