Feed ObjectAddress to event triggers for ALTER TABLE ATTACH/DETACH
authorMichael Paquier <michael@paquier.xyz>
Sun, 31 Jul 2022 04:04:43 +0000 (13:04 +0900)
committerMichael Paquier <michael@paquier.xyz>
Sun, 31 Jul 2022 04:04:43 +0000 (13:04 +0900)
These flavors of ALTER TABLE were already shaped to report the
ObjectAddress of the partition attached or detached, but this data was
not added to what is collected for event triggers.  The tests of
test_ddl_deparse are updated to show the modification in the data
reported.

Author: Hou Zhijie
Reviewed-by: Álvaro Herrera, Amit Kapila, Hayato Kuroda, Michael Paquier
Discussion: https://postgr.es/m/OS0PR01MB571626984BD099DADF53F38394899@OS0PR01MB5716.jpnprd01.prod.outlook.com

src/backend/commands/tablecmds.c
src/test/modules/test_ddl_deparse/expected/alter_table.out

index e7aef2f6b08e32b63f8ab54f76b8d51cf99fc829..d22dd44712a6a034866c10be760f13bae4ae17c4 100644 (file)
@@ -5202,11 +5202,11 @@ ATExecCmd(List **wqueue, AlteredTableInfo *tab,
                                      cur_pass, context);
            Assert(cmd != NULL);
            if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
-               ATExecAttachPartition(wqueue, rel, (PartitionCmd *) cmd->def,
-                                     context);
+               address = ATExecAttachPartition(wqueue, rel, (PartitionCmd *) cmd->def,
+                                               context);
            else
-               ATExecAttachPartitionIdx(wqueue, rel,
-                                        ((PartitionCmd *) cmd->def)->name);
+               address = ATExecAttachPartitionIdx(wqueue, rel,
+                                                  ((PartitionCmd *) cmd->def)->name);
            break;
        case AT_DetachPartition:
            cmd = ATParseTransformCmd(wqueue, tab, rel, cmd, false, lockmode,
@@ -5214,12 +5214,12 @@ ATExecCmd(List **wqueue, AlteredTableInfo *tab,
            Assert(cmd != NULL);
            /* ATPrepCmd ensures it must be a table */
            Assert(rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
-           ATExecDetachPartition(wqueue, tab, rel,
-                                 ((PartitionCmd *) cmd->def)->name,
-                                 ((PartitionCmd *) cmd->def)->concurrent);
+           address = ATExecDetachPartition(wqueue, tab, rel,
+                                           ((PartitionCmd *) cmd->def)->name,
+                                           ((PartitionCmd *) cmd->def)->concurrent);
            break;
        case AT_DetachPartitionFinalize:
-           ATExecDetachPartitionFinalize(rel, ((PartitionCmd *) cmd->def)->name);
+           address = ATExecDetachPartitionFinalize(rel, ((PartitionCmd *) cmd->def)->name);
            break;
        default:                /* oops */
            elog(ERROR, "unrecognized alter table type: %d",
index 5445fb04e4dcc6c6eed3087be6b8bb761527f6d5..87a1ab7aabce045e3e99f5f38983eea9d0922956 100644 (file)
@@ -50,10 +50,10 @@ CREATE TABLE part2 (a int);
 NOTICE:  DDL test: type simple, tag CREATE TABLE
 ALTER TABLE part ATTACH PARTITION part2 FOR VALUES FROM (101) to (200);
 NOTICE:  DDL test: type alter table, tag ALTER TABLE
-NOTICE:    subcommand: type ATTACH PARTITION desc <NULL>
+NOTICE:    subcommand: type ATTACH PARTITION desc table part2
 ALTER TABLE part DETACH PARTITION part2;
 NOTICE:  DDL test: type alter table, tag ALTER TABLE
-NOTICE:    subcommand: type DETACH PARTITION desc <NULL>
+NOTICE:    subcommand: type DETACH PARTITION desc table part2
 DROP TABLE part2;
 ALTER TABLE part ADD PRIMARY KEY (a);
 NOTICE:  DDL test: type alter table, tag ALTER TABLE