diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 819f1af4f0396e1e65952418636bb994efc58cb7..27b839169cef6c7347c4877b7a3f7ad15e25a2bf 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -6078,10 +6078,12 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { SSchema* pSchema = tscGetTableTagSchema(pTableMetaInfo->pTableMeta); int16_t numOfTags = tscGetNumOfTags(pTableMetaInfo->pTableMeta); - int16_t i; + int32_t numOfCols = tscGetNumOfColumns(pTableMetaInfo->pTableMeta); + int32_t tagIndex = columnIndex.columnIndex - numOfCols; + assert(tagIndex>=0); uint32_t nLen = 0; - for (i = 0; i < numOfTags; ++i) { - nLen += (i != columnIndex.columnIndex) ? pSchema[i].bytes : pItem->bytes; + for (int i = 0; i < numOfTags; ++i) { + nLen += (i != tagIndex) ? pSchema[i].bytes : pItem->bytes; } if (nLen >= TSDB_MAX_TAGS_LEN) { return invalidOperationMsg(pMsg, msg24); diff --git a/tests/script/general/parser/alter_stable.sim b/tests/script/general/parser/alter_stable.sim index afdd7d3edf1ba4f2159569f497bf495cce8ec650..1406af608779eef2048de24b6e4aef6b99b54d7d 100644 --- a/tests/script/general/parser/alter_stable.sim +++ b/tests/script/general/parser/alter_stable.sim @@ -35,7 +35,10 @@ sql alter table tb1 set tag name = "" sql alter table tb1 set tag name = "shenzhen" sql alter table tb1 set tag len = 379 +# case TD-5594 +sql create stable st5520(ts timestamp, f int) tags(t0 bool, t1 nchar(4093), t2 nchar(1)) +sql_error alter stable st5520 modify tag t2 nchar(2); # test end sql drop database $db -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file +system sh/exec.sh -n dnode1 -s stop -x SIGINT