diff --git a/pkg/vm/engine/disttae/txn_table.go b/pkg/vm/engine/disttae/txn_table.go index af921fb5c1d9e..6c5d57618816d 100644 --- a/pkg/vm/engine/disttae/txn_table.go +++ b/pkg/vm/engine/disttae/txn_table.go @@ -1106,6 +1106,11 @@ func (tbl *txnTable) TableDefs(ctx context.Context) ([]engine.TableDef, error) { return defs, nil } +func (tbl *txnTable) RefeshTableDef(ctx context.Context) { + tbl.tableDef = nil + tbl.GetTableDef(ctx) +} + func (tbl *txnTable) GetTableDef(ctx context.Context) *plan.TableDef { if tbl.tableDef == nil { var clusterByDef *plan.ClusterByDef @@ -1393,13 +1398,15 @@ func (tbl *txnTable) AlterTable(ctx context.Context, c *engine.ConstraintDef, re panic("not equal cstr") } + var baseDefs []engine.TableDef // update TableDef if hasReplaceDef { // When ReplaceDef exists, replace the entire table definition replaceDef := replaceDefReq.GetReplaceDef() - defs, _, _ := engine.PlanDefsToExeDefs(replaceDef.Def) - defs = append(defs, engine.PlanColsToExeCols(replaceDef.Def.Cols)...) - tbl.defs = defs + baseDefs, _, _ = engine.PlanDefsToExeDefs(replaceDef.Def) + baseDefs = append(baseDefs, engine.PlanColsToExeCols(replaceDef.Def.Cols)...) + } else { + baseDefs = append([]engine.TableDef{}, tbl.defs...) } // 0. check if the table is created in txn. @@ -1436,16 +1443,16 @@ func (tbl *txnTable) AlterTable(ctx context.Context, c *engine.ConstraintDef, re } } - tbl.defs = append(tbl.defs, appendDef...) - tbl.tableDef = nil - tbl.GetTableDef(ctx) - //------------------------------------------------------------------------------------------------------------------ // 1. delete old table metadata if _, err := tbl.db.deleteTable(ctx, oldTableName, true, !createdInTxn); err != nil { return err } + // update table defs after deleting old table metadata + tbl.defs = append(baseDefs, appendDef...) + tbl.RefeshTableDef(ctx) + //------------------------------------------------------------------------------------------------------------------ // 2. insert new table metadata if err := tbl.db.createWithID(ctx, tbl.tableName, tbl.tableId, tbl.defs, !createdInTxn, tbl.extraInfo); err != nil { diff --git a/test/distributed/cases/benchmark/tpch/02_LOAD/11_select_count_snapshot.result b/test/distributed/cases/benchmark/tpch/02_LOAD/11_select_count_snapshot.result index aa252d7373022..f06a828ba1e80 100644 --- a/test/distributed/cases/benchmark/tpch/02_LOAD/11_select_count_snapshot.result +++ b/test/distributed/cases/benchmark/tpch/02_LOAD/11_select_count_snapshot.result @@ -8,9 +8,6 @@ drop table if exists orders; drop table if exists part; drop table if exists partsupp; drop table if exists supplier; -select sleep(10); -sleep(10) -0 select count(*) from customer {snapshot = 'tpch_snapshot'}; count(*) 150 @@ -181,9 +178,6 @@ select count(*) from supplier; count(*) 10 drop database tpch; -select sleep(10); -sleep(10) -0 select count(*) from tpch.customer {snapshot = 'tpch_snapshot'}; count(*) 150 diff --git a/test/distributed/cases/benchmark/tpch/02_LOAD/11_select_count_snapshot.sql b/test/distributed/cases/benchmark/tpch/02_LOAD/11_select_count_snapshot.sql index 68b780d1e017d..52a2a2dfb175f 100644 --- a/test/distributed/cases/benchmark/tpch/02_LOAD/11_select_count_snapshot.sql +++ b/test/distributed/cases/benchmark/tpch/02_LOAD/11_select_count_snapshot.sql @@ -9,7 +9,6 @@ drop table if exists part; drop table if exists partsupp; drop table if exists supplier; -select sleep(10); -- customer select count(*) from customer {snapshot = 'tpch_snapshot'}; select count(*) from customer {snapshot = 'tpch_snapshot'}; @@ -90,7 +89,6 @@ select count(*) from supplier; select count(*) from supplier; drop database tpch; -select sleep(10); select count(*) from tpch.customer {snapshot = 'tpch_snapshot'}; select count(*) from tpch.customer {snapshot = 'tpch_snapshot'}; diff --git a/test/distributed/cases/ddl/alter.result b/test/distributed/cases/ddl/alter.result index 5602bc1924c67..a137ef2497636 100644 --- a/test/distributed/cases/ddl/alter.result +++ b/test/distributed/cases/ddl/alter.result @@ -64,13 +64,18 @@ drop table tm1; drop table ti2; drop table tm2; drop table if exists foreign01; + create temporary table foreign01(col1 int primary key, col2 varchar(20), col3 int, col4 bigint); + insert into foreign01 values(1,'shujuku',100,3247984); + insert into foreign01 values(2,'数据库',328932,32324423432); + drop table if exists foreign02; + create temporary table foreign02(col1 int, col2 int, col3 int primary key, @@ -81,6 +86,7 @@ no such table test.foreign02 insert into foreign02 values(2,2,2); no such table test.foreign02 delete from foreign01 where col3 = 100; + show create table foreign02; no such table test.foreign02 alter table foreign02 drop foreign key fk; @@ -88,20 +94,33 @@ no such table test.foreign02 show create table foreign02; no such table test.foreign02 drop table foreign01; + drop table foreign02; no such table test.foreign02 drop table if exists ti1; + drop table if exists tm1; + drop table if exists ti2; + drop table if exists tm2; + create temporary table ti1(a INT not null, b INT, c INT); + create temporary table tm1(a INT not null, b INT, c INT); + create temporary table ti2(a INT primary key AUTO_INCREMENT, b INT, c INT); + create temporary table tm2(a INT primary key AUTO_INCREMENT, b INT, c INT); + insert into ti1 values (1,1,1), (2,2,2); + insert into ti2 values (1,1,1), (2,2,2); + insert into tm1 values (1,1,1), (2,2,2); + insert into tm2 values (1,1,1), (2,2,2); + alter table ti1 add constraint fi1 foreign key (b) references ti2(a); alter table for temporary table is not yet implemented alter table tm1 add constraint fm1 foreign key (b) references tm2(a); @@ -113,7 +132,9 @@ show create table tm1; Table Create Table tm1 CREATE TABLE `tm1` (\n `a` int NOT NULL,\n `b` int DEFAULT NULL,\n `c` int DEFAULT NULL\n) delete from ti2 where c = 1; + delete from tm2 where c = 1; + alter table ti1 drop foreign key fi1; alter table for temporary table is not yet implemented alter table tm1 drop foreign key fm1; @@ -125,11 +146,17 @@ show create table tm1; Table Create Table tm1 CREATE TABLE `tm1` (\n `a` int NOT NULL,\n `b` int DEFAULT NULL,\n `c` int DEFAULT NULL\n) delete from ti2 where c = 1; + delete from tm2 where c = 1; + drop table ti1; + drop table tm1; + drop table ti2; + drop table tm2; + drop table if exists index01; create table index01(col1 int,key key1(col1)); show index from index01; @@ -556,6 +583,18 @@ id content show create table t5; Table Create Table t5 CREATE TABLE `t5` (\n `id` int NOT NULL,\n `content` varchar(1000) DEFAULT NULL,\n PRIMARY KEY (`id`)\n) +begin; +alter table t5 rename column content to new_content; +select mo_ctl('dn', 'flush', 'mo_catalog.mo_columns'); +mo_ctl(dn, flush, mo_catalog.mo_columns) +{\n "method": "Flush",\n "result": [\n {\n "returnStr": "OK"\n }\n ]\n}\n +select sleep(0.51); +sleep(0.51) +0 +commit; +show create table t5; +Table Create Table +t5 CREATE TABLE `t5` (\n `id` int NOT NULL,\n `new_content` varchar(1000) DEFAULT NULL,\n PRIMARY KEY (`id`)\n) drop table t1; drop table t2; drop table t3; diff --git a/test/distributed/cases/ddl/alter.sql b/test/distributed/cases/ddl/alter.sql index 9c47b6e385e72..752247cacecca 100644 --- a/test/distributed/cases/ddl/alter.sql +++ b/test/distributed/cases/ddl/alter.sql @@ -489,6 +489,20 @@ alter table t5 modify column content varchar(1000); select * from t5; show create table t5; +begin; + +alter table t5 rename column content to new_content; + +-- @separator:table +select mo_ctl('dn', 'flush', 'mo_catalog.mo_columns'); + +select sleep(0.51); + +commit; + +show create table t5; + + -- Cleanup drop table t1; drop table t2; diff --git a/test/distributed/cases/view/system_view.result b/test/distributed/cases/view/system_view.result index e86afac01ffb9..db58aa24d711d 100644 --- a/test/distributed/cases/view/system_view.result +++ b/test/distributed/cases/view/system_view.result @@ -1,6 +1,6 @@ begin; -select sleep(10); -sleep(10) +select sleep(5); +sleep(5) 0 select count(*) > 0 from mo_sessions() t; count(*) > 0 diff --git a/test/distributed/cases/view/system_view.sql b/test/distributed/cases/view/system_view.sql index ac7425f97bd77..19411faa98357 100644 --- a/test/distributed/cases/view/system_view.sql +++ b/test/distributed/cases/view/system_view.sql @@ -2,7 +2,7 @@ -- @session:id=1{ begin; -select sleep(10); +select sleep(5); -- @session} select count(*) > 0 from mo_sessions() t; @@ -24,4 +24,4 @@ select count(*) >0 from mo_configurations() t; select count(*) >0 from mo_configurations() t where node_type = 'cn'; select distinct node_type,default_value from mo_configurations() t where name like '%frontend.port'; -select count(*) > 0 from mo_configurations() t where internal = 'advanced'; \ No newline at end of file +select count(*) > 0 from mo_configurations() t where internal = 'advanced';