From 4a388c4223abc8b3f5719298e55e7630046cf16e Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Fri, 11 Feb 2022 16:08:28 +0800 Subject: [PATCH] Feature/td 11381 3.0 (#10220) * calculate boundNullLen * add extendedRowSize --- 2.0/src/client/src/tscParseInsert.c | 8 ++++---- include/common/trow.h | 12 ++++++++++-- source/libs/parser/src/dataBlockMgt.c | 1 + source/libs/parser/src/insertParser.c | 16 ++++++++++++++-- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/2.0/src/client/src/tscParseInsert.c b/2.0/src/client/src/tscParseInsert.c index b2e2e950dc..b3f7c076e3 100644 --- a/2.0/src/client/src/tscParseInsert.c +++ b/2.0/src/client/src/tscParseInsert.c @@ -1209,10 +1209,10 @@ static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDat ++pColInfo->numOfBound; switch (pSchema[t].type) { case TSDB_DATA_TYPE_BINARY: - pColInfo->boundNullLen += (VARSTR_HEADER_SIZE + CHAR_BYTES); + pColInfo->boundNullLen += (sizeof(VarDataOffsetT) + VARSTR_HEADER_SIZE + CHAR_BYTES); break; case TSDB_DATA_TYPE_NCHAR: - pColInfo->boundNullLen += (VARSTR_HEADER_SIZE + TSDB_NCHAR_SIZE); + pColInfo->boundNullLen += (sizeof(VarDataOffsetT) + VARSTR_HEADER_SIZE + TSDB_NCHAR_SIZE); break; default: pColInfo->boundNullLen += TYPE_BYTES[pSchema[t].type]; @@ -1243,10 +1243,10 @@ static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDat ++pColInfo->numOfBound; switch (pSchema[t].type) { case TSDB_DATA_TYPE_BINARY: - pColInfo->boundNullLen += (VARSTR_HEADER_SIZE + CHAR_BYTES); + pColInfo->boundNullLen += (sizeof(VarDataOffsetT) + VARSTR_HEADER_SIZE + CHAR_BYTES); break; case TSDB_DATA_TYPE_NCHAR: - pColInfo->boundNullLen += (VARSTR_HEADER_SIZE + TSDB_NCHAR_SIZE); + pColInfo->boundNullLen += (sizeof(VarDataOffsetT) + VARSTR_HEADER_SIZE + TSDB_NCHAR_SIZE); break; default: pColInfo->boundNullLen += TYPE_BYTES[pSchema[t].type]; diff --git a/include/common/trow.h b/include/common/trow.h index f86809b19f..4bb44e31f0 100644 --- a/include/common/trow.h +++ b/include/common/trow.h @@ -423,8 +423,16 @@ static FORCE_INLINE int32_t tdSRowSetInfo(SRowBuilder *pBuilder, int32_t nCols, */ static FORCE_INLINE int32_t tdSRowSetExtendedInfo(SRowBuilder *pBuilder, int32_t nCols, int32_t nBoundCols, int32_t flen, int32_t allNullLen, int32_t boundNullLen) { - if ((boundNullLen > 0) && (allNullLen > 0) && isSelectKVRow(boundNullLen, allNullLen)) { - pBuilder->rowType = TD_ROW_KV; + if ((boundNullLen > 0) && (allNullLen > 0) && (nBoundCols > 0)) { + uint32_t tpLen = allNullLen; + uint32_t kvLen = sizeof(col_id_t) + sizeof(SKvRowIdx) * nBoundCols + boundNullLen; + if (isSelectKVRow(kvLen, tpLen)) { + pBuilder->rowType = TD_ROW_KV; + } else { + pBuilder->rowType = TD_ROW_TP; + } + + } else { pBuilder->rowType = TD_ROW_TP; } diff --git a/source/libs/parser/src/dataBlockMgt.c b/source/libs/parser/src/dataBlockMgt.c index 8412580d71..eefaa2c147 100644 --- a/source/libs/parser/src/dataBlockMgt.c +++ b/source/libs/parser/src/dataBlockMgt.c @@ -77,6 +77,7 @@ void setBoundColumnInfo(SParsedDataColInfo* pColList, SSchema* pSchema, int32_t pColList->boundedColumns[i] = pSchema[i].colId; } pColList->allNullLen += pColList->flen; + pColList->boundNullLen = pColList->allNullLen; // default set allNullLen pColList->extendedVarLen = (uint16_t)(nVar * sizeof(VarDataOffsetT)); } diff --git a/source/libs/parser/src/insertParser.c b/source/libs/parser/src/insertParser.c index e7f3be6049..08fe0852b1 100644 --- a/source/libs/parser/src/insertParser.c +++ b/source/libs/parser/src/insertParser.c @@ -292,6 +292,7 @@ static int32_t parseBoundColumns(SInsertParseContext* pCxt, SParsedDataColInfo* int32_t nCols = pColList->numOfCols; pColList->numOfBound = 0; + pColList->boundNullLen = 0; memset(pColList->boundedColumns, 0, sizeof(int32_t) * nCols); for (int32_t i = 0; i < nCols; ++i) { pColList->cols[i].valStat = VAL_STAT_NONE; @@ -323,6 +324,17 @@ static int32_t parseBoundColumns(SInsertParseContext* pCxt, SParsedDataColInfo* pColList->cols[index].valStat = VAL_STAT_HAS; pColList->boundedColumns[pColList->numOfBound] = index; ++pColList->numOfBound; + switch (pSchema[t].type) { + case TSDB_DATA_TYPE_BINARY: + pColList->boundNullLen += (sizeof(VarDataOffsetT) + VARSTR_HEADER_SIZE + CHAR_BYTES); + break; + case TSDB_DATA_TYPE_NCHAR: + pColList->boundNullLen += (sizeof(VarDataOffsetT) + VARSTR_HEADER_SIZE + TSDB_NCHAR_SIZE); + break; + default: + pColList->boundNullLen += TYPE_BYTES[pSchema[t].type]; + break; + } } pColList->orderStatus = isOrdered ? ORDER_STATUS_ORDERED : ORDER_STATUS_DISORDERED; @@ -450,7 +462,7 @@ static int parseOneRow(SInsertParseContext* pCxt, STableDataBlocks* pDataBlocks, } } - *len = pBuilder->extendedRowSize; + // *len = pBuilder->extendedRowSize; return TSDB_CODE_SUCCESS; } @@ -480,7 +492,7 @@ static int32_t parseValues(SInsertParseContext* pCxt, STableDataBlocks* pDataBlo int32_t len = 0; CHECK_CODE(parseOneRow(pCxt, pDataBlock, tinfo.precision, &len, tmpTokenBuf)); - pDataBlock->size += len; + pDataBlock->size += extendedRowSize; //len; NEXT_TOKEN(pCxt->pSql, sToken); if (TK_RP != sToken.type) {