diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 70fd74afc0a80b327265e17d2cb5f1a8d0069769..8a6bd079a4a61e40812c075dade90c4b65c93f73 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -1578,9 +1578,11 @@ static int32_t mndAlterStbColumnBytes(SMnode *pMnode, const SStbObj *pOld, SStbO return -1; } + col_id_t colId = pOld->pColumns[col].colId; + uint32_t nLen = 0; for (int32_t i = 0; i < pOld->numOfColumns; ++i) { - nLen += (pOld->pColumns[i].colId == col) ? pField->bytes : pOld->pColumns[i].bytes; + nLen += (pOld->pColumns[i].colId == colId) ? pField->bytes : pOld->pColumns[i].bytes; } if (nLen > TSDB_MAX_BYTES_PER_ROW) { @@ -1588,7 +1590,6 @@ static int32_t mndAlterStbColumnBytes(SMnode *pMnode, const SStbObj *pOld, SStbO return -1; } - col_id_t colId = pOld->pColumns[col].colId; if (mndCheckColAndTagModifiable(pMnode, pOld->name, pOld->uid, colId) != 0) { return -1; } diff --git a/tests/script/tsim/alter/table.sim b/tests/script/tsim/alter/table.sim index 0cf291523a7b4b6ca2cbf321a797c65656dfd59f..b1f18328270e28da013c862ff58577314494f339 100644 --- a/tests/script/tsim/alter/table.sim +++ b/tests/script/tsim/alter/table.sim @@ -671,6 +671,12 @@ sql alter table tb2023 add column v nchar(16379); sql_error alter table tb2023 modify column v nchar(16380); sql desc tb2023 +print =============== modify column for normal table +sql create table ntb_ts3841(ts timestamp, c0 varchar(64000)); +sql alter table ntb_ts3841 modify column c0 varchar(64001); +sql create table ntb1_ts3841(ts timestamp, c0 nchar(15000)); +sql alter table ntb1_ts3841 modify column c0 nchar(15001); + print =============== error for super table sql create table stb2023(ts timestamp, f int) tags(t1 int); sql_error alter table stb2023 add column v varchar(65518); @@ -685,6 +691,20 @@ sql alter table stb2023 add column v nchar(16379); sql_error alter table stb2023 modify column v nchar(16380); sql desc stb2023 +print =============== modify column/tag for super table +sql create table stb_ts3841(ts timestamp, c0 varchar(64000)) tags(t1 binary(16380)); +sql alter table stb_ts3841 modify column c0 varchar(64001); +sql alter table stb_ts3841 modify tag t1 binary(16381); +sql alter table stb_ts3841 modify tag t1 binary(16382); +sql_error alter table stb_ts3841 modify tag t1 binary(16383); + +sql create table stb1_ts3841(ts timestamp, c0 nchar(15000)) tags(t1 nchar(4093)); +sql alter table stb1_ts3841 modify column c0 nchar(15001); +sql alter table stb1_ts3841 modify tag t1 nchar(4094); +sql alter table stb1_ts3841 modify tag t1 nchar(4095); +sql_error alter table stb1_ts3841 modify tag t1 nchar(4096); +sql_error alter table stb1_ts3841 modify tag t1 binary(16382); + print ======= over sql drop database d1 sql select * from information_schema.ins_databases