diff --git a/src/client/src/tscFunctionImpl.c b/src/client/src/tscFunctionImpl.c index b05e82b39a91195e26c3fd926e70ff75a5eb6713..a0deaa519a4ec0c6829cbfa70261b3efa28535d9 100644 --- a/src/client/src/tscFunctionImpl.c +++ b/src/client/src/tscFunctionImpl.c @@ -151,7 +151,6 @@ typedef struct SRateInfo { double sum; // for sum/avg } SRateInfo; - int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionId, int32_t param, int16_t *type, int16_t *bytes, int32_t *interBytes, int16_t extLength, bool isSuperTable) { if (!isValidDataType(dataType, dataBytes)) { diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 372e81d7371debe904ac7ad1e6a9caecb54ccb28..47f679a922e5f389e040a61a9e462979574886b5 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -348,7 +348,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1); } - if (pToken->n >= TSDB_TABLE_NAME_LEN) { + if (tscValidateTableNameLength(pToken->n)) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); } @@ -1056,7 +1056,7 @@ int32_t setObjFullName(char* fullName, const char* account, SSQLToken* pDB, SSQL totalLen += 1; /* here we only check the table name length limitation */ - if (tableName->n > TSDB_TABLE_NAME_LEN) { + if (!tscValidateTableNameLength(tableName->n)) { return TSDB_CODE_TSC_INVALID_SQL; } } else { // pDB == NULL, the db prefix name is specified in tableName @@ -1402,9 +1402,7 @@ int32_t addProjectionExprAndResultField(SQueryInfo* pQueryInfo, tSQLExprItem* pI } if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) { - SSchema colSchema = {.type = TSDB_DATA_TYPE_BINARY, .bytes = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE}; - strcpy(colSchema.name, TSQL_TBNAME_L); - + SSchema colSchema = tGetTableNameColumnSchema(); tscAddSpecialColumnForSelect(pQueryInfo, startPos, TSDB_FUNC_TAGPRJ, &index, &colSchema, true); } else { STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex); @@ -1914,9 +1912,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr SSchema s = {0}; if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) { - s.bytes = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; - s.type = TSDB_DATA_TYPE_BINARY; - s.colId = TSDB_TBNAME_COLUMN_INDEX; + s = tGetTableNameColumnSchema(); } else { s = pTagSchema[index.columnIndex]; } @@ -2230,7 +2226,7 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg6); } - if (pCmd->payloadLen >= TSDB_TABLE_NAME_LEN) { + if (!tscValidateTableNameLength(pCmd->payloadLen)) { return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); } } @@ -2861,7 +2857,7 @@ static int32_t tablenameListToString(tSQLExpr* pExpr, SStringBuilder* sb) { taosStringBuilderAppendString(sb, TBNAME_LIST_SEP); } - if (pSub->val.nLen <= 0 || pSub->val.nLen > TSDB_TABLE_NAME_LEN) { + if (pSub->val.nLen <= 0 || !tscValidateTableNameLength(pSub->val.nLen)) { return TSDB_CODE_TSC_INVALID_SQL; } } @@ -5232,9 +5228,10 @@ static int32_t doAddGroupbyColumnsOnDemand(SQueryInfo* pQueryInfo) { int16_t colIndex = pColIndex->colIndex; if (colIndex == TSDB_TBNAME_COLUMN_INDEX) { - type = TSDB_DATA_TYPE_BINARY; - bytes = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE; // todo extract method - name = TSQL_TBNAME_L; + SSchema s = tGetTableNameColumnSchema(); + type = s.type; + bytes = s.bytes; + name = s.name; } else { if (TSDB_COL_IS_TAG(pColIndex->flag)) { SSchema* tagSchema = tscGetTableTagSchema(pTableMetaInfo->pTableMeta); diff --git a/src/client/src/tscSchemaUtil.c b/src/client/src/tscSchemaUtil.c index 88417addf635fd3cf0824cf6774112c1bfd5a05f..439aa7c1dedc1f9b301d3aeb08ccb7d68ac9ab00 100644 --- a/src/client/src/tscSchemaUtil.c +++ b/src/client/src/tscSchemaUtil.c @@ -50,14 +50,6 @@ int32_t tscGetNumOfColumns(const STableMeta* pTableMeta) { SSchema *tscGetTableSchema(const STableMeta *pTableMeta) { assert(pTableMeta != NULL); - -// if (pTableMeta->tableType == TSDB_CHILD_TABLE) { -// STableMeta* pSTableMeta = pTableMeta->pSTable; -// assert (pSTableMeta != NULL); -// -// return pSTableMeta->schema; -// } - return (SSchema*) pTableMeta->schema; } diff --git a/src/common/inc/tname.h b/src/common/inc/tname.h index 810d7f492c8fcd96aa7a4b2032f05142e8494e86..d2008c9ff8181b54db83fdd92f777ba74489ce73 100644 --- a/src/common/inc/tname.h +++ b/src/common/inc/tname.h @@ -23,5 +23,8 @@ void extractTableName(const char *tableId, char *name); char* extractDBName(const char *tableId, char *name); +SSchema tGetTableNameColumnSchema(); + +bool tscValidateTableNameLength(size_t len); #endif // TDENGINE_NAME_H diff --git a/src/common/src/tname.c b/src/common/src/tname.c index d2f5dfc4f75a96e725dc719a4d348472e36d3564..2514ed26e55e54eddf54d83933beecdfbf4e06fa 100644 --- a/src/common/src/tname.c +++ b/src/common/src/tname.c @@ -37,3 +37,16 @@ char* extractDBName(const char* tableId, char* name) { return strncpy(name, &tableId[offset1 + 1], len); } + +SSchema tGetTableNameColumnSchema() { + SSchema s = {0}; + s.bytes = TSDB_TABLE_NAME_LEN - 1 + VARSTR_HEADER_SIZE; + s.type = TSDB_DATA_TYPE_BINARY; + s.colId = TSDB_TBNAME_COLUMN_INDEX; + strncpy(s.name, TSQL_TBNAME_L, TSDB_COL_NAME_LEN); + return s; +} + +bool tscValidateTableNameLength(size_t len) { + return len < TSDB_TABLE_NAME_LEN; +} \ No newline at end of file diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index 251e3a9e4031cc0c4e48fe7c89ba1f1c1535c704..be9c0b5ef6b3476f53b2055c3aaeb47c10f0c716 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -200,7 +200,7 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size); #define TSDB_MIN_COLUMNS 2 //PRIMARY COLUMN(timestamp) + other columns #define TSDB_NODE_NAME_LEN 64 -#define TSDB_TABLE_NAME_LEN 193 +#define TSDB_TABLE_NAME_LEN 193 // it is a null-terminated string #define TSDB_DB_NAME_LEN 33 #define TSDB_COL_NAME_LEN 65 #define TSDB_MAX_SAVED_SQL_LEN TSDB_MAX_COLUMNS * 64 diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index a2ddd9893f50495d3235d5feb8cc513638569209..adb8e261d4c2408b7ea93ad9b3d3073f905b1419 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -1078,8 +1078,9 @@ static int32_t mnodeGetShowSuperTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, int32_t cols = 0; SSchema *pSchema = pMeta->schema; - pShow->bytes[cols] = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + SSchema tbnameSchema = tGetTableNameColumnSchema(); + pShow->bytes[cols] = tbnameSchema.bytes; + pSchema[cols].type = tbnameSchema.type; strcpy(pSchema[cols].name, "name"); pSchema[cols].bytes = htons(pShow->bytes[cols]); cols++; @@ -2079,8 +2080,9 @@ static int32_t mnodeGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void int32_t cols = 0; SSchema *pSchema = pMeta->schema; - pShow->bytes[cols] = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + SSchema s = tGetTableNameColumnSchema(); + pShow->bytes[cols] = s.bytes; + pSchema[cols].type = s.type; strcpy(pSchema[cols].name, "table_name"); pSchema[cols].bytes = htons(pShow->bytes[cols]); cols++; @@ -2097,8 +2099,9 @@ static int32_t mnodeGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void pSchema[cols].bytes = htons(pShow->bytes[cols]); cols++; - pShow->bytes[cols] = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + SSchema tbCol = tGetTableNameColumnSchema(); + pShow->bytes[cols] = tbCol.bytes; + pSchema[cols].type = tbCol.type; strcpy(pSchema[cols].name, "stable_name"); pSchema[cols].bytes = htons(pShow->bytes[cols]); cols++; @@ -2268,8 +2271,9 @@ static int32_t mnodeGetStreamTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, vo int32_t cols = 0; SSchema *pSchema = pMeta->schema; - pShow->bytes[cols] = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + SSchema tbnameColSchema = tGetTableNameColumnSchema(); + pShow->bytes[cols] = tbnameColSchema.bytes; + pSchema[cols].type = tbnameColSchema.type; strcpy(pSchema[cols].name, "table_name"); pSchema[cols].bytes = htons(pShow->bytes[cols]); cols++; diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index cdb05d2288671f6fcb619b01f60e6437ffa5ed97..ebc06a7875ded48db61e191ba3dad189ef462294 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -1368,8 +1368,10 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int16_t order int32_t index = pSqlFuncMsg->colInfo.colIndex; if (TSDB_COL_IS_TAG(pIndex->flag)) { if (pIndex->colId == TSDB_TBNAME_COLUMN_INDEX) { // todo refactor - pCtx->inputBytes = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE; - pCtx->inputType = TSDB_DATA_TYPE_BINARY; + SSchema s = tGetTableNameColumnSchema(); + + pCtx->inputBytes = s.bytes; + pCtx->inputType = s.type; } else { pCtx->inputBytes = pQuery->tagColList[index].bytes; pCtx->inputType = pQuery->tagColList[index].type; @@ -5143,8 +5145,9 @@ static int32_t createQFunctionExprFromMsg(SQueryTableMsg *pQueryMsg, SExprInfo * type = TSDB_DATA_TYPE_DOUBLE; bytes = tDataTypeDesc[type].nSize; } else if (pExprs[i].base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX && pExprs[i].base.functionId == TSDB_FUNC_TAGPRJ) { // parse the normal column - type = TSDB_DATA_TYPE_BINARY; - bytes = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE; + SSchema s = tGetTableNameColumnSchema(); + type = s.type; + bytes = s.bytes; } else{ int32_t j = getColumnIndexInSource(pQueryMsg, &pExprs[i].base, pTagCols); assert(j < pQueryMsg->numOfCols || j < pQueryMsg->numOfTags || j == TSDB_TBNAME_COLUMN_INDEX); @@ -5154,10 +5157,11 @@ static int32_t createQFunctionExprFromMsg(SQueryTableMsg *pQueryMsg, SExprInfo * type = pCol->type; bytes = pCol->bytes; } else { - type = TSDB_DATA_TYPE_BINARY; - bytes = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; - } + SSchema s = tGetTableNameColumnSchema(); + type = s.type; + bytes = s.bytes; + } } int32_t param = pExprs[i].base.arg[0].argValue.i64; @@ -6025,6 +6029,7 @@ static void buildTagQueryResult(SQInfo* pQInfo) { qTrace("QInfo:%p create count(tbname) query, res:%d rows:1", pQInfo, count); } else { // return only the tags|table name etc. count = 0; + SSchema tbnameSchema = tGetTableNameColumnSchema(); while(pQInfo->tableIndex < num && count < pQuery->rec.capacity) { int32_t i = pQInfo->tableIndex++; @@ -6034,7 +6039,7 @@ static void buildTagQueryResult(SQInfo* pQInfo) { for(int32_t j = 0; j < pQuery->numOfOutput; ++j) { if (pExprInfo[j].base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) { char* data = tsdbGetTableName(pQInfo->tsdb, &item->id); - char* dst = pQuery->sdata[j]->data + count * ((TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE); + char* dst = pQuery->sdata[j]->data + count * tbnameSchema.bytes; memcpy(dst, data, varDataTLen(data)); } else {// todo refactor int16_t type = pExprInfo[j].type; diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index d3bc45e2e4706f2892b4bfd75e8b9b029aa0dc6e..e74ec3b06ad418f454b920702fc42cf5c5d1b685 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -1942,7 +1942,7 @@ int32_t tableGroupComparFn(const void *p1, const void *p2, const void *param) { f1 = (char*) pTable1->name; f2 = (char*) pTable2->name; type = TSDB_DATA_TYPE_BINARY; - bytes = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE; + bytes = tGetTableNameColumnSchema().bytes; } else { STColumn* pCol = schemaColAt(pTableGroupSupp->pTagSchema, colIndex); bytes = pCol->bytes;