已合并
B兼容性取消分类型批量执行策略,保持和mysql一致 #2347
B兼容性取消分类型批量执行策略,保持和mysql一致 #2347
已合并
wofanzheng创建于 1月8日
共 3 个文件变更+68-0
@@ -575,6 +575,22 @@ drop index if exists id_grammar0029;
575NOTICE: index "id_grammar0029" does not exist, skipping575NOTICE: index "id_grammar0029" does not exist, skipping
576create index id_grammar0029 on t_grammar0029 using psort(id) tablespace pg_default;576create index id_grammar0029 on t_grammar0029 using psort(id) tablespace pg_default;
577alter table t_grammar0029 drop key id_grammar0029;577alter table t_grammar0029 drop key id_grammar0029;
578+-- test alter order with after/first
579+create table alter_order_test(a int, b int);
580+alter table alter_order_test
581+ add column c int after a,
582+ add column d int after c,
583+ change column b b int after d;
584+\d alter_order_test
585+Table "db_alter_table.alter_order_test"
586+ Column | Type | Modifiers
587+--------+---------+-----------
588+ a | integer |
589+ c | integer |
590+ d | integer |
591+ b | integer |
592+ 
593+drop table alter_order_test;
578drop schema db_alter_table cascade;594drop schema db_alter_table cascade;
579NOTICE: drop cascades to 3 other objects595NOTICE: drop cascades to 3 other objects
580DETAIL: drop cascades to type lockmodes596DETAIL: drop cascades to type lockmodes
@@ -231,5 +231,14 @@ drop index if exists id_grammar0029;
231create index id_grammar0029 on t_grammar0029 using psort(id) tablespace pg_default;231create index id_grammar0029 on t_grammar0029 using psort(id) tablespace pg_default;
232alter table t_grammar0029 drop key id_grammar0029;232alter table t_grammar0029 drop key id_grammar0029;
233 233 
234+-- test alter order with after/first
235+create table alter_order_test(a int, b int);
236+alter table alter_order_test
237+ add column c int after a,
238+ add column d int after c,
239+ change column b b int after d;
240+\d alter_order_test
241+drop table alter_order_test;
242+ 
234drop schema db_alter_table cascade;243drop schema db_alter_table cascade;
235reset current_schema;244reset current_schema;
@@ -8960,6 +8960,12 @@ static void ATPrepCmd(List** wqueue, Relation rel, AlterTableCmd* cmd, bool recu
8960 cmd = (AlterTableCmd*)copyObject(cmd);8960 cmd = (AlterTableCmd*)copyObject(cmd);
8961 8961 
8962 cmd->recursing = recursing;8962 cmd->recursing = recursing;
8963+ if (u_sess->attr.attr_sql.sql_compatibility == B_FORMAT) {
8964+ tab->b_compat_subcmds = lappend(tab->b_compat_subcmds, cmd);
8965+ if (cmd->subtype == AT_AlterColumnType || cmd->subtype == AT_ModifyColumn) {
8966+ tab->b_compat_has_alter_type = true;
8967+ }
8968+ }
8963 /*8969 /*
8964 * Do permissions checking, recursion to child tables if needed, and any8970 * Do permissions checking, recursion to child tables if needed, and any
8965 * additional phase-1 processing needed.8971 * additional phase-1 processing needed.
@@ -9600,6 +9606,43 @@ static void ATRewriteCatalogs(List** wqueue, LOCKMODE lockmode, bool fromReplace
9600 OnlineDDLRelOperators* operators = ((OnlineDDLRelOperators*)u_sess->online_ddl_operators);9606 OnlineDDLRelOperators* operators = ((OnlineDDLRelOperators*)u_sess->online_ddl_operators);
9601 bool enableOnlineDDL = (operators != NULL && operators->getStatus() == ONLINE_DDL_STATUS_REWRITE_CATALOG);9607 bool enableOnlineDDL = (operators != NULL && operators->getStatus() == ONLINE_DDL_STATUS_REWRITE_CATALOG);
9602 9608 
9609+ bool b_compat_order = (u_sess->attr.attr_sql.sql_compatibility == B_FORMAT);
9610+ 
9611+ if (b_compat_order) {
9612+ /* Clear phase-1 pass lists to avoid double execution in B format. */
9613+ foreach (ltab, *wqueue) {
9614+ AlteredTableInfo* tab = (AlteredTableInfo*)lfirst(ltab);
9615+ if (tab->b_compat_subcmds == NIL) {
9616+ continue;
9617+ }
9618+ for (pass = 0; pass < AT_NUM_PASSES; pass++) {
9619+ tab->subcmds[pass] = NIL;
9620+ }
9621+ }
9622+ 
9623+ /* Execute original subcommands in written order for B format. */
9624+ foreach (ltab, *wqueue) {
9625+ AlteredTableInfo* tab = (AlteredTableInfo*)lfirst(ltab);
9626+ ListCell* lcmd = NULL;
9627+ Relation rel;
9628+ 
9629+ if (tab->b_compat_subcmds == NIL) {
9630+ continue;
9631+ }
9632+ 
9633+ rel = relation_open(tab->relid, NoLock);
9634+ foreach (lcmd, tab->b_compat_subcmds) {
9635+ ATExecCmd(wqueue, tab, rel, (AlterTableCmd*)lfirst(lcmd), lockmode, fromReplace);
9636+ }
9637+ 
9638+ if (tab->b_compat_has_alter_type && !tab->isDeltaTable) {
9639+ ATPostAlterTypeCleanup(wqueue, tab, lockmode);
9640+ }
9641+ 
9642+ relation_close(rel, NoLock);
9643+ }
9644+ }
9645+ 
9603 /*9646 /*
9604 * We process all the tables "in parallel", one pass at a time. This is9647 * We process all the tables "in parallel", one pass at a time. This is
9605 * needed because we may have to propagate work from one table to another9648 * needed because we may have to propagate work from one table to another