diff --git a/src/inc/tsdb.h b/src/inc/tsdb.h index 79d9029dbc..7575951246 100644 --- a/src/inc/tsdb.h +++ b/src/inc/tsdb.h @@ -117,7 +117,7 @@ typedef struct { void tsdbClearTableCfg(STableCfg *config); -void *tsdbGetTableTagVal(const void *pTable, int32_t colId, int16_t type, int16_t bytes); +void *tsdbGetTableTagVal(const void *pTable, int32_t colId, int16_t type, int16_t* bytes); char *tsdbGetTableName(void *pTable); #define TSDB_TABLEID(_table) ((STableId*) (_table)) diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 77ceabbd63..4a5dc4f506 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -2819,7 +2819,7 @@ static void doSetTagValueInParam(void* pTable, int32_t tagColId, tVariant *tag, val = tsdbGetTableName(pTable); assert(val != NULL); } else { - val = tsdbGetTableTagVal(pTable, tagColId, type, bytes); + val = tsdbGetTableTagVal(pTable, tagColId, type, &bytes); } if (val == NULL || isNull(val, type)) { @@ -6011,7 +6011,7 @@ static SSDataBlock* doTagScan(void* param, bool* newgroup) { if (pExprInfo->base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) { data = tsdbGetTableName(item->pTable); } else { - data = tsdbGetTableTagVal(item->pTable, pExprInfo->base.colInfo.colId, type, bytes); + data = tsdbGetTableTagVal(item->pTable, pExprInfo->base.colInfo.colId, type, &bytes); } doSetTagValueToResultBuf(output, data, type, bytes); @@ -6050,7 +6050,7 @@ static SSDataBlock* doTagScan(void* param, bool* newgroup) { if (pExprInfo[j].base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) { data = tsdbGetTableName(item->pTable); } else { - data = tsdbGetTableTagVal(item->pTable, pExprInfo[j].base.colInfo.colId, type, bytes); + data = tsdbGetTableTagVal(item->pTable, pExprInfo[j].base.colInfo.colId, type, &bytes); } dst = pColInfo->pData + count * pExprInfo[j].base.resBytes; diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 8174698197..52ba3dfb4e 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -201,7 +201,7 @@ _err: return -1; } -void *tsdbGetTableTagVal(const void* pTable, int32_t colId, int16_t type, int16_t bytes) { +void *tsdbGetTableTagVal(const void* pTable, int32_t colId, int16_t type, int16_t* bytes) { // TODO: this function should be changed also STSchema *pSchema = tsdbGetTableTagSchema((STable*) pTable); @@ -211,8 +211,16 @@ void *tsdbGetTableTagVal(const void* pTable, int32_t colId, int16_t type, int16_ } char *val = tdGetKVRowValOfCol(((STable*)pTable)->tagVal, colId); - assert(type == pCol->type && bytes == pCol->bytes); + assert(type == pCol->type && + // if var data type,bytes may >= col bytes,in case of tag width has beed modified + ((IS_VAR_DATA_TYPE(type) && *bytes >= pCol->bytes) || + // otherwise, bytes must be equal to colomn bytes + (!IS_VAR_DATA_TYPE(type) && *bytes == pCol->bytes))); + // in case tag width has been modified bigger but vnode has not been notified + if (val != NULL && IS_VAR_DATA_TYPE(type) && *bytes > pCol->bytes) { + *bytes = pCol->bytes; + } // if (val != NULL && IS_VAR_DATA_TYPE(type)) { // assert(varDataLen(val) < pCol->bytes); // }