From 2f271fa684fa0eaf2de6294cb3c40efbb55af706 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Thu, 15 Jul 2021 21:09:30 +0800 Subject: [PATCH] code optimization and give the same hint when exceed max columns --- src/client/inc/tsclient.h | 4 +--- src/client/src/tscParseInsert.c | 9 ++------- src/client/src/tscPrepare.c | 10 ++-------- src/client/src/tscSQLParser.c | 6 +++++- src/inc/taosdef.h | 2 +- 5 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index c23ca2bc98..d60c6756d6 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -41,8 +41,6 @@ extern "C" { // forward declaration struct SSqlInfo; -#define KvRowNColsThresh 128 // default 128 - typedef void (*__async_cb_func_t)(void *param, TAOS_RES *tres, int32_t numOfRows); typedef struct SNewVgroupInfo { @@ -111,7 +109,7 @@ typedef struct SParsedDataColInfo { int8_t orderStatus; // bounded columns: } SParsedDataColInfo; -#define IS_DATA_COL_ORDERED(s) (((s)->orderStatus) == (int8_t)ORDER_STATUS_ORDERED) +#define IS_DATA_COL_ORDERED(s) ((s) == (int8_t)ORDER_STATUS_ORDERED) typedef struct { SSchema * pSchema; diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index bfebed6676..b6062b5ad2 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -406,7 +406,6 @@ static FORCE_INLINE TDRowLenT tsSetPayloadColValue(char *payloadStart, char *pay payloadColSetId(payload, columnId); payloadColSetType(payload, columnType); memcpy(POINTER_SHIFT(payloadStart,tOffset), value, valueLen); - // payloadSetTLen(payloadStart, payloadTLen(payloadStart) + valueLen); return valueLen; } @@ -867,7 +866,7 @@ int tsParseOneRow(char **str, STableDataBlocks *pDataBlocks, int16_t timePrec, i TDRowLenT kvRowColLen = 0; TDRowLenT colValAppended = 0; - if (!IS_DATA_COL_ORDERED(spd)) { + if (!IS_DATA_COL_ORDERED(spd->orderStatus)) { ASSERT(spd->colIdxInfo != NULL); if(!isPrimaryKey) { kvStart = POINTER_SHIFT(kvPrimaryKeyStart, spd->colIdxInfo[i].finalIdx * PAYLOAD_COL_HEAD_LEN); @@ -891,7 +890,7 @@ int tsParseOneRow(char **str, STableDataBlocks *pDataBlocks, int16_t timePrec, i payloadColSetOffset(kvPrimaryKeyStart, colValOffset); } else { payloadColSetOffset(kvStart, colValOffset); - if (spd->orderStatus == ORDER_STATUS_ORDERED) { + if (IS_DATA_COL_ORDERED(spd->orderStatus)) { kvStart += PAYLOAD_COL_HEAD_LEN; // move to next column } } @@ -910,10 +909,6 @@ int tsParseOneRow(char **str, STableDataBlocks *pDataBlocks, int16_t timePrec, i *len = (int32_t)(payloadValOffset + colValOffset); payloadSetTLen(payload, *len); - // TSKEY tsKey = payloadKey(payload); - // ASSERT((tsKey < 1627747200000000 && tsKey > 1498838400000000) || (tsKey < 1627747200000 && tsKey > 1498838400000) || - // (tsKey < 1627747200 && tsKey > 1498838400)); - return TSDB_CODE_SUCCESS; } diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 0eb1eaa12f..36c10f6cd5 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -370,7 +370,7 @@ static int refactorPayload(STableDataBlocks* pBlock, int32_t rowNum) { bool isPrimaryKey = (colIndex == PRIMARYKEY_TIMESTAMP_COL_INDEX); // the primary key locates in 1st column - if (!IS_DATA_COL_ORDERED(spd)) { + if (!IS_DATA_COL_ORDERED(spd->orderStatus)) { ASSERT(spd->colIdxInfo != NULL); if (!isPrimaryKey) { kvStart = POINTER_SHIFT(kvPrimaryKeyStart, spd->colIdxInfo[i].finalIdx * PAYLOAD_COL_HEAD_LEN); @@ -406,7 +406,7 @@ static int refactorPayload(STableDataBlocks* pBlock, int32_t rowNum) { kvRowLen += TYPE_BYTES[pSchema->type]; } - if (IS_DATA_COL_ORDERED(spd)) { + if (IS_DATA_COL_ORDERED(spd->orderStatus)) { kvStart += PAYLOAD_COL_HEAD_LEN; // move to next column } } @@ -425,12 +425,6 @@ static int refactorPayload(STableDataBlocks* pBlock, int32_t rowNum) { TDRowTLenT len = payloadValOffset + colValOffset; payloadSetTLen(destPayload, len); -#if 0 - TSKEY tsKey = payloadKey(destPayload); - ASSERT((tsKey < 1627747200000000 && tsKey > 1498838400000000) || (tsKey < 1627747200000 && tsKey > 1498838400000) || - (tsKey < 1627747200 && tsKey > 1498838400)); -#endif - // next loop srcPayload += pBlock->rowSize; destPayload += len; diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index d9ad830214..13fd9a8092 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -1245,12 +1245,16 @@ static bool validateTableColumnInfo(SArray* pFieldList, SSqlCmd* pCmd) { const char* msg4 = "invalid data type"; const char* msg5 = "invalid binary/nchar column length"; const char* msg6 = "invalid column name"; + const char* msg7 = "too many columns"; // number of fields no less than 2 size_t numOfCols = taosArrayGetSize(pFieldList); - if (numOfCols <= 1 || numOfCols > TSDB_MAX_COLUMNS) { + if (numOfCols <= 1 ) { invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg); return false; + } else if (numOfCols > TSDB_MAX_COLUMNS) { + invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg7); + return false; } // first column must be timestamp diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index 7c6b3bbed9..f5be879878 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -198,7 +198,7 @@ do { \ /** * In some scenarios uint16_t (0~65535) is used to store the row len. * - Firstly, we use 65531(65535 - 4), as the SDataRow and SKVRow including 4 bits header. - * - Secondly, if all cols are VarType except primary key, we need 4 bits to store the offset, thus + * - Secondly, if all cols are VarDataT type except primary key, we need 4 bits to store the offset, thus * the final value is 65531-(4096-1)*4 = 49151. */ #define TSDB_MAX_BYTES_PER_ROW 49151 -- GitLab