Merge pull request #6996 from taosdata/hotfix/td-5484
[TD-5484]<fix>:tag nchar/binary length exceed limit error when alter table add tag
This commit is contained in:
commit
2ede8e74a8
|
@ -6020,7 +6020,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
||||||
int16_t i;
|
int16_t i;
|
||||||
uint32_t nLen = 0;
|
uint32_t nLen = 0;
|
||||||
for (i = 0; i < numOfColumns; ++i) {
|
for (i = 0; i < numOfColumns; ++i) {
|
||||||
nLen += pSchema[i].colId != columnIndex.columnIndex ? pSchema[i].bytes : pItem->bytes;
|
nLen += (i != columnIndex.columnIndex) ? pSchema[i].bytes : pItem->bytes;
|
||||||
}
|
}
|
||||||
if (nLen >= TSDB_MAX_BYTES_PER_ROW) {
|
if (nLen >= TSDB_MAX_BYTES_PER_ROW) {
|
||||||
return invalidOperationMsg(pMsg, msg24);
|
return invalidOperationMsg(pMsg, msg24);
|
||||||
|
@ -6066,14 +6066,14 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
||||||
return invalidOperationMsg(pMsg, msg22);
|
return invalidOperationMsg(pMsg, msg22);
|
||||||
}
|
}
|
||||||
|
|
||||||
SSchema* pSchema = (SSchema*) pTableMetaInfo->pTableMeta->schema;
|
SSchema* pSchema = tscGetTableTagSchema(pTableMetaInfo->pTableMeta);
|
||||||
int16_t numOfColumns = pTableMetaInfo->pTableMeta->tableInfo.numOfColumns;
|
int16_t numOfTags = tscGetNumOfTags(pTableMetaInfo->pTableMeta);
|
||||||
int16_t i;
|
int16_t i;
|
||||||
uint32_t nLen = 0;
|
uint32_t nLen = 0;
|
||||||
for (i = 0; i < numOfColumns; ++i) {
|
for (i = 0; i < numOfTags; ++i) {
|
||||||
nLen += pSchema[i].colId != columnIndex.columnIndex ? pSchema[i].bytes : pItem->bytes;
|
nLen += (i != columnIndex.columnIndex) ? pSchema[i].bytes : pItem->bytes;
|
||||||
}
|
}
|
||||||
if (nLen >= TSDB_MAX_BYTES_PER_ROW) {
|
if (nLen >= TSDB_MAX_TAGS_LEN) {
|
||||||
return invalidOperationMsg(pMsg, msg24);
|
return invalidOperationMsg(pMsg, msg24);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -712,9 +712,8 @@ void tSetColumnType(TAOS_FIELD *pField, SStrToken *type) {
|
||||||
} else {
|
} else {
|
||||||
int32_t bytes = -(int32_t)(type->type);
|
int32_t bytes = -(int32_t)(type->type);
|
||||||
if (bytes > (TSDB_MAX_NCHAR_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) {
|
if (bytes > (TSDB_MAX_NCHAR_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) {
|
||||||
// we have to postpone reporting the error because it cannot be done here
|
// overflowed. set bytes to -1 so that error can be reported
|
||||||
// as pField->bytes is int16_t, use 'TSDB_MAX_NCHAR_LEN + 1' to avoid overflow
|
bytes = -1;
|
||||||
bytes = TSDB_MAX_NCHAR_LEN + 1;
|
|
||||||
} else {
|
} else {
|
||||||
bytes = bytes * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
|
bytes = bytes * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
|
||||||
}
|
}
|
||||||
|
@ -727,8 +726,8 @@ void tSetColumnType(TAOS_FIELD *pField, SStrToken *type) {
|
||||||
} else {
|
} else {
|
||||||
int32_t bytes = -(int32_t)(type->type);
|
int32_t bytes = -(int32_t)(type->type);
|
||||||
if (bytes > TSDB_MAX_BINARY_LEN - VARSTR_HEADER_SIZE) {
|
if (bytes > TSDB_MAX_BINARY_LEN - VARSTR_HEADER_SIZE) {
|
||||||
// refer comment for NCHAR above
|
// overflowed. set bytes to -1 so that error can be reported
|
||||||
bytes = TSDB_MAX_BINARY_LEN + 1;
|
bytes = -1;
|
||||||
} else {
|
} else {
|
||||||
bytes += VARSTR_HEADER_SIZE;
|
bytes += VARSTR_HEADER_SIZE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue