From d11f81bec1139c4b5fb9aa662df21c02cd02bf9c Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Mon, 13 Dec 2021 19:35:48 +0800 Subject: [PATCH] code optimization --- src/client/inc/tsclient.h | 4 ++-- src/client/src/tscParseInsert.c | 10 ++++------ src/common/inc/tdataformat.h | 3 +-- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index 728021543b..e4b2c7b0a1 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -115,9 +115,9 @@ typedef struct SParsedDataColInfo { int16_t numOfCols; int16_t numOfBound; uint16_t flen; // TODO: get from STSchema - uint16_t allNullLen; // TODO: get from STSchema + uint16_t allNullLen; // TODO: get from STSchema(base on SDataRow) uint16_t extendedVarLen; - uint16_t boundNullLen; // bound column len with all NULL value + uint16_t boundNullLen; // bound column len with all NULL value(without VarDataOffsetT/SColIdx part) int32_t * boundedColumns; // bound column idx according to schema SBoundColumn * cols; SBoundIdxInfo *colIdxInfo; diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index 59ad58d03c..e7346b130e 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -50,9 +50,9 @@ int initMemRowBuilder(SMemRowBuilder *pBuilder, uint32_t nRows, SParsedDataColIn } } - uint32_t dataLen = pColInfo->allNullLen + TD_MEM_ROW_DATA_HEAD_SIZE; + uint32_t dataLen = TD_MEM_ROW_DATA_HEAD_SIZE + pColInfo->allNullLen; uint32_t kvLen = TD_MEM_ROW_KV_HEAD_SIZE + pColInfo->numOfBound * sizeof(SColIdx) + pColInfo->boundNullLen; - if (isConvertToKvRow(kvLen, dataLen)) { + if (isConvertToKVRow(kvLen, dataLen)) { pBuilder->memRowType = SMEM_ROW_KV; } else { pBuilder->memRowType = SMEM_ROW_DATA; @@ -1240,8 +1240,6 @@ static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDat pColInfo->cols[t].valStat = VAL_STAT_HAS; pColInfo->boundedColumns[pColInfo->numOfBound] = t; ++pColInfo->numOfBound; - // N.B. make sure sizeof(VarDataOffsetT) == sizeof(SColIdx) - pColInfo->boundNullLen += TYPE_BYTES[pSchema[t].type]; switch (pSchema[t].type) { case TSDB_DATA_TYPE_BINARY: pColInfo->boundNullLen += (VARSTR_HEADER_SIZE + CHAR_BYTES); @@ -1250,6 +1248,7 @@ static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDat pColInfo->boundNullLen += (VARSTR_HEADER_SIZE + TSDB_NCHAR_SIZE); break; default: + pColInfo->boundNullLen += TYPE_BYTES[pSchema[t].type]; break; } findColumnIndex = true; @@ -1275,8 +1274,6 @@ static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDat pColInfo->cols[t].valStat = VAL_STAT_HAS; pColInfo->boundedColumns[pColInfo->numOfBound] = t; ++pColInfo->numOfBound; - // N.B. make sure sizeof(VarDataOffsetT) == sizeof(SColIdx) - pColInfo->boundNullLen += TYPE_BYTES[pSchema[t].type]; switch (pSchema[t].type) { case TSDB_DATA_TYPE_BINARY: pColInfo->boundNullLen += (VARSTR_HEADER_SIZE + CHAR_BYTES); @@ -1285,6 +1282,7 @@ static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDat pColInfo->boundNullLen += (VARSTR_HEADER_SIZE + TSDB_NCHAR_SIZE); break; default: + pColInfo->boundNullLen += TYPE_BYTES[pSchema[t].type]; break; } findColumnIndex = true; diff --git a/src/common/inc/tdataformat.h b/src/common/inc/tdataformat.h index 7c2438c737..664b6f2527 100644 --- a/src/common/inc/tdataformat.h +++ b/src/common/inc/tdataformat.h @@ -619,8 +619,7 @@ typedef void *SMemRow; #define isDataRow(r) (SMEM_ROW_DATA == memRowType(r)) #define isKvRowT(t) (SMEM_ROW_KV == (((uint8_t)(t)) & 0x01)) #define isKvRow(r) (SMEM_ROW_KV == memRowType(r)) -#define isConvertToKvRow(k, d) ((k) < ((d)*KVRatioConvert)) -#define isConvertToDataRow(k, d) ((k) > (d)) +#define isConvertToKVRow(k, d) ((k) < ((d)*KVRatioConvert)) #define memRowDataBody(r) POINTER_SHIFT(r, TD_MEM_ROW_TYPE_SIZE) // section after flag #define memRowKvBody(r) \ -- GitLab