Merge pull request #2233 from taosdata/feature/query
[td-582] fix crash.
This commit is contained in:
commit
00abe27151
|
@ -151,7 +151,6 @@ typedef struct SRateInfo {
|
||||||
double sum; // for sum/avg
|
double sum; // for sum/avg
|
||||||
} SRateInfo;
|
} SRateInfo;
|
||||||
|
|
||||||
|
|
||||||
int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionId, int32_t param, int16_t *type,
|
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) {
|
int16_t *bytes, int32_t *interBytes, int16_t extLength, bool isSuperTable) {
|
||||||
if (!isValidDataType(dataType, dataBytes)) {
|
if (!isValidDataType(dataType, dataBytes)) {
|
||||||
|
|
|
@ -348,7 +348,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pToken->n >= TSDB_TABLE_NAME_LEN) {
|
if (!tscValidateTableNameLength(pToken->n)) {
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1056,7 +1056,7 @@ int32_t setObjFullName(char* fullName, const char* account, SSQLToken* pDB, SSQL
|
||||||
totalLen += 1;
|
totalLen += 1;
|
||||||
|
|
||||||
/* here we only check the table name length limitation */
|
/* 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;
|
return TSDB_CODE_TSC_INVALID_SQL;
|
||||||
}
|
}
|
||||||
} else { // pDB == NULL, the db prefix name is specified in tableName
|
} 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) {
|
if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) {
|
||||||
SSchema colSchema = {.type = TSDB_DATA_TYPE_BINARY, .bytes = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE};
|
SSchema colSchema = tGetTableNameColumnSchema();
|
||||||
strcpy(colSchema.name, TSQL_TBNAME_L);
|
|
||||||
|
|
||||||
tscAddSpecialColumnForSelect(pQueryInfo, startPos, TSDB_FUNC_TAGPRJ, &index, &colSchema, true);
|
tscAddSpecialColumnForSelect(pQueryInfo, startPos, TSDB_FUNC_TAGPRJ, &index, &colSchema, true);
|
||||||
} else {
|
} else {
|
||||||
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex);
|
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex);
|
||||||
|
@ -1914,9 +1912,7 @@ int32_t addExprAndResultField(SQueryInfo* pQueryInfo, int32_t colIndex, tSQLExpr
|
||||||
|
|
||||||
SSchema s = {0};
|
SSchema s = {0};
|
||||||
if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) {
|
if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) {
|
||||||
s.bytes = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE;
|
s = tGetTableNameColumnSchema();
|
||||||
s.type = TSDB_DATA_TYPE_BINARY;
|
|
||||||
s.colId = TSDB_TBNAME_COLUMN_INDEX;
|
|
||||||
} else {
|
} else {
|
||||||
s = pTagSchema[index.columnIndex];
|
s = pTagSchema[index.columnIndex];
|
||||||
}
|
}
|
||||||
|
@ -2230,7 +2226,7 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg6);
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg6);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pCmd->payloadLen >= TSDB_TABLE_NAME_LEN) {
|
if (!tscValidateTableNameLength(pCmd->payloadLen)) {
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2861,7 +2857,7 @@ static int32_t tablenameListToString(tSQLExpr* pExpr, SStringBuilder* sb) {
|
||||||
taosStringBuilderAppendString(sb, TBNAME_LIST_SEP);
|
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;
|
return TSDB_CODE_TSC_INVALID_SQL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5233,9 +5229,10 @@ static int32_t doAddGroupbyColumnsOnDemand(SQueryInfo* pQueryInfo) {
|
||||||
|
|
||||||
int16_t colIndex = pColIndex->colIndex;
|
int16_t colIndex = pColIndex->colIndex;
|
||||||
if (colIndex == TSDB_TBNAME_COLUMN_INDEX) {
|
if (colIndex == TSDB_TBNAME_COLUMN_INDEX) {
|
||||||
type = TSDB_DATA_TYPE_BINARY;
|
SSchema s = tGetTableNameColumnSchema();
|
||||||
bytes = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE; // todo extract method
|
type = s.type;
|
||||||
name = TSQL_TBNAME_L;
|
bytes = s.bytes;
|
||||||
|
name = s.name;
|
||||||
} else {
|
} else {
|
||||||
if (TSDB_COL_IS_TAG(pColIndex->flag)) {
|
if (TSDB_COL_IS_TAG(pColIndex->flag)) {
|
||||||
SSchema* tagSchema = tscGetTableTagSchema(pTableMetaInfo->pTableMeta);
|
SSchema* tagSchema = tscGetTableTagSchema(pTableMetaInfo->pTableMeta);
|
||||||
|
|
|
@ -50,14 +50,6 @@ int32_t tscGetNumOfColumns(const STableMeta* pTableMeta) {
|
||||||
|
|
||||||
SSchema *tscGetTableSchema(const STableMeta *pTableMeta) {
|
SSchema *tscGetTableSchema(const STableMeta *pTableMeta) {
|
||||||
assert(pTableMeta != NULL);
|
assert(pTableMeta != NULL);
|
||||||
|
|
||||||
// if (pTableMeta->tableType == TSDB_CHILD_TABLE) {
|
|
||||||
// STableMeta* pSTableMeta = pTableMeta->pSTable;
|
|
||||||
// assert (pSTableMeta != NULL);
|
|
||||||
//
|
|
||||||
// return pSTableMeta->schema;
|
|
||||||
// }
|
|
||||||
|
|
||||||
return (SSchema*) pTableMeta->schema;
|
return (SSchema*) pTableMeta->schema;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,5 +23,8 @@ void extractTableName(const char *tableId, char *name);
|
||||||
|
|
||||||
char* extractDBName(const char *tableId, char *name);
|
char* extractDBName(const char *tableId, char *name);
|
||||||
|
|
||||||
|
SSchema tGetTableNameColumnSchema();
|
||||||
|
|
||||||
|
bool tscValidateTableNameLength(size_t len);
|
||||||
|
|
||||||
#endif // TDENGINE_NAME_H
|
#endif // TDENGINE_NAME_H
|
||||||
|
|
|
@ -37,3 +37,16 @@ char* extractDBName(const char* tableId, char* name) {
|
||||||
|
|
||||||
return strncpy(name, &tableId[offset1 + 1], len);
|
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;
|
||||||
|
}
|
|
@ -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_MIN_COLUMNS 2 //PRIMARY COLUMN(timestamp) + other columns
|
||||||
|
|
||||||
#define TSDB_NODE_NAME_LEN 64
|
#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_DB_NAME_LEN 33
|
||||||
#define TSDB_TABLE_ID_LEN (TSDB_ACCT_LEN + TSDB_DB_NAME_LEN + TSDB_TABLE_NAME_LEN)
|
#define TSDB_TABLE_ID_LEN (TSDB_ACCT_LEN + TSDB_DB_NAME_LEN + TSDB_TABLE_NAME_LEN)
|
||||||
#define TSDB_COL_NAME_LEN 65
|
#define TSDB_COL_NAME_LEN 65
|
||||||
|
|
|
@ -1078,8 +1078,9 @@ static int32_t mnodeGetShowSuperTableMeta(STableMetaMsg *pMeta, SShowObj *pShow,
|
||||||
int32_t cols = 0;
|
int32_t cols = 0;
|
||||||
SSchema *pSchema = pMeta->schema;
|
SSchema *pSchema = pMeta->schema;
|
||||||
|
|
||||||
pShow->bytes[cols] = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE;
|
SSchema tbnameSchema = tGetTableNameColumnSchema();
|
||||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
pShow->bytes[cols] = tbnameSchema.bytes;
|
||||||
|
pSchema[cols].type = tbnameSchema.type;
|
||||||
strcpy(pSchema[cols].name, "name");
|
strcpy(pSchema[cols].name, "name");
|
||||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||||
cols++;
|
cols++;
|
||||||
|
@ -2079,8 +2080,9 @@ static int32_t mnodeGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void
|
||||||
int32_t cols = 0;
|
int32_t cols = 0;
|
||||||
SSchema *pSchema = pMeta->schema;
|
SSchema *pSchema = pMeta->schema;
|
||||||
|
|
||||||
pShow->bytes[cols] = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE;
|
SSchema s = tGetTableNameColumnSchema();
|
||||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
pShow->bytes[cols] = s.bytes;
|
||||||
|
pSchema[cols].type = s.type;
|
||||||
strcpy(pSchema[cols].name, "table_name");
|
strcpy(pSchema[cols].name, "table_name");
|
||||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||||
cols++;
|
cols++;
|
||||||
|
@ -2097,8 +2099,9 @@ static int32_t mnodeGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void
|
||||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||||
cols++;
|
cols++;
|
||||||
|
|
||||||
pShow->bytes[cols] = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE;
|
SSchema tbCol = tGetTableNameColumnSchema();
|
||||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
pShow->bytes[cols] = tbCol.bytes;
|
||||||
|
pSchema[cols].type = tbCol.type;
|
||||||
strcpy(pSchema[cols].name, "stable_name");
|
strcpy(pSchema[cols].name, "stable_name");
|
||||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||||
cols++;
|
cols++;
|
||||||
|
@ -2268,8 +2271,9 @@ static int32_t mnodeGetStreamTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, vo
|
||||||
int32_t cols = 0;
|
int32_t cols = 0;
|
||||||
SSchema *pSchema = pMeta->schema;
|
SSchema *pSchema = pMeta->schema;
|
||||||
|
|
||||||
pShow->bytes[cols] = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE;
|
SSchema tbnameColSchema = tGetTableNameColumnSchema();
|
||||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
pShow->bytes[cols] = tbnameColSchema.bytes;
|
||||||
|
pSchema[cols].type = tbnameColSchema.type;
|
||||||
strcpy(pSchema[cols].name, "table_name");
|
strcpy(pSchema[cols].name, "table_name");
|
||||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||||
cols++;
|
cols++;
|
||||||
|
|
|
@ -1368,8 +1368,10 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int16_t order
|
||||||
int32_t index = pSqlFuncMsg->colInfo.colIndex;
|
int32_t index = pSqlFuncMsg->colInfo.colIndex;
|
||||||
if (TSDB_COL_IS_TAG(pIndex->flag)) {
|
if (TSDB_COL_IS_TAG(pIndex->flag)) {
|
||||||
if (pIndex->colId == TSDB_TBNAME_COLUMN_INDEX) { // todo refactor
|
if (pIndex->colId == TSDB_TBNAME_COLUMN_INDEX) { // todo refactor
|
||||||
pCtx->inputBytes = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE;
|
SSchema s = tGetTableNameColumnSchema();
|
||||||
pCtx->inputType = TSDB_DATA_TYPE_BINARY;
|
|
||||||
|
pCtx->inputBytes = s.bytes;
|
||||||
|
pCtx->inputType = s.type;
|
||||||
} else {
|
} else {
|
||||||
pCtx->inputBytes = pQuery->tagColList[index].bytes;
|
pCtx->inputBytes = pQuery->tagColList[index].bytes;
|
||||||
pCtx->inputType = pQuery->tagColList[index].type;
|
pCtx->inputType = pQuery->tagColList[index].type;
|
||||||
|
@ -5143,8 +5145,9 @@ static int32_t createQFunctionExprFromMsg(SQueryTableMsg *pQueryMsg, SExprInfo *
|
||||||
type = TSDB_DATA_TYPE_DOUBLE;
|
type = TSDB_DATA_TYPE_DOUBLE;
|
||||||
bytes = tDataTypeDesc[type].nSize;
|
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
|
} 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;
|
SSchema s = tGetTableNameColumnSchema();
|
||||||
bytes = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE;
|
type = s.type;
|
||||||
|
bytes = s.bytes;
|
||||||
} else{
|
} else{
|
||||||
int32_t j = getColumnIndexInSource(pQueryMsg, &pExprs[i].base, pTagCols);
|
int32_t j = getColumnIndexInSource(pQueryMsg, &pExprs[i].base, pTagCols);
|
||||||
assert(j < pQueryMsg->numOfCols || j < pQueryMsg->numOfTags || j == TSDB_TBNAME_COLUMN_INDEX);
|
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;
|
type = pCol->type;
|
||||||
bytes = pCol->bytes;
|
bytes = pCol->bytes;
|
||||||
} else {
|
} else {
|
||||||
type = TSDB_DATA_TYPE_BINARY;
|
SSchema s = tGetTableNameColumnSchema();
|
||||||
bytes = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
type = s.type;
|
||||||
|
bytes = s.bytes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t param = pExprs[i].base.arg[0].argValue.i64;
|
int32_t param = pExprs[i].base.arg[0].argValue.i64;
|
||||||
|
@ -6064,6 +6068,7 @@ static void buildTagQueryResult(SQInfo* pQInfo) {
|
||||||
qTrace("QInfo:%p create count(tbname) query, res:%d rows:1", pQInfo, count);
|
qTrace("QInfo:%p create count(tbname) query, res:%d rows:1", pQInfo, count);
|
||||||
} else { // return only the tags|table name etc.
|
} else { // return only the tags|table name etc.
|
||||||
count = 0;
|
count = 0;
|
||||||
|
SSchema tbnameSchema = tGetTableNameColumnSchema();
|
||||||
while(pQInfo->tableIndex < num && count < pQuery->rec.capacity) {
|
while(pQInfo->tableIndex < num && count < pQuery->rec.capacity) {
|
||||||
int32_t i = pQInfo->tableIndex++;
|
int32_t i = pQInfo->tableIndex++;
|
||||||
|
|
||||||
|
@ -6073,7 +6078,7 @@ static void buildTagQueryResult(SQInfo* pQInfo) {
|
||||||
for(int32_t j = 0; j < pQuery->numOfOutput; ++j) {
|
for(int32_t j = 0; j < pQuery->numOfOutput; ++j) {
|
||||||
if (pExprInfo[j].base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) {
|
if (pExprInfo[j].base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) {
|
||||||
char* data = tsdbGetTableName(pQInfo->tsdb, &item->id);
|
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));
|
memcpy(dst, data, varDataTLen(data));
|
||||||
} else {// todo refactor
|
} else {// todo refactor
|
||||||
int16_t type = pExprInfo[j].type;
|
int16_t type = pExprInfo[j].type;
|
||||||
|
|
|
@ -1942,7 +1942,7 @@ int32_t tableGroupComparFn(const void *p1, const void *p2, const void *param) {
|
||||||
f1 = (char*) pTable1->name;
|
f1 = (char*) pTable1->name;
|
||||||
f2 = (char*) pTable2->name;
|
f2 = (char*) pTable2->name;
|
||||||
type = TSDB_DATA_TYPE_BINARY;
|
type = TSDB_DATA_TYPE_BINARY;
|
||||||
bytes = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE;
|
bytes = tGetTableNameColumnSchema().bytes;
|
||||||
} else {
|
} else {
|
||||||
STColumn* pCol = schemaColAt(pTableGroupSupp->pTagSchema, colIndex);
|
STColumn* pCol = schemaColAt(pTableGroupSupp->pTagSchema, colIndex);
|
||||||
bytes = pCol->bytes;
|
bytes = pCol->bytes;
|
||||||
|
|
Loading…
Reference in New Issue