diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index f31af59ae9..197e914202 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -7085,6 +7085,15 @@ ATExecDropColumn(List **wqueue, Relation rel, const char *colName, ReleaseSysCache(tuple); /* + * Perform the actual column deletion + */ + object.classId = RelationRelationId; + object.objectId = RelationGetRelid(rel); + object.objectSubId = attnum; + + performDeletion(&object, behavior, 0); + + /* * Propagate to children as appropriate. Unlike most other ALTER * routines, we have to do this one level of recursion at a time; we can't * use find_all_inheritors to do it in one pass. @@ -7175,15 +7184,6 @@ ATExecDropColumn(List **wqueue, Relation rel, const char *colName, table_close(attr_rel, RowExclusiveLock); } - /* - * Perform the actual column deletion - */ - object.classId = RelationRelationId; - object.objectId = RelationGetRelid(rel); - object.objectSubId = attnum; - - performDeletion(&object, behavior, 0); - return object; } diff --git a/src/test/regress/expected/indexing.out b/src/test/regress/expected/indexing.out index c143df5114..28498b220d 100644 --- a/src/test/regress/expected/indexing.out +++ b/src/test/regress/expected/indexing.out @@ -1258,3 +1258,20 @@ ERROR: cannot drop inherited constraint "parted_uniq_detach_test1_a_key" of rel alter table parted_uniq_detach_test detach partition parted_uniq_detach_test1; alter table parted_uniq_detach_test1 drop constraint parted_uniq_detach_test1_a_key; drop table parted_uniq_detach_test, parted_uniq_detach_test1; +-- check that dropping a column takes with it any partitioned indexes +-- depending on it +create table parted_index_col_drop(a int, b int, c int) partition by list (a); +create table parted_index_col_drop1 partition of parted_index_col_drop for values in (1) partition by list (a); +create table parted_index_col_drop11 partition of parted_index_col_drop1 for values in (1); +create index on parted_index_col_drop (b, c); +alter table parted_index_col_drop drop c; +\d parted_index_col_drop + Partitioned table "public.parted_index_col_drop" + Column | Type | Collation | Nullable | Default +--------+---------+-----------+----------+--------- + a | integer | | | + b | integer | | | +Partition key: LIST (a) +Number of partitions: 1 (Use \d+ to list them.) + +drop table parted_index_col_drop; diff --git a/src/test/regress/sql/indexing.sql b/src/test/regress/sql/indexing.sql index cc3d0abfb7..8ba054b907 100644 --- a/src/test/regress/sql/indexing.sql +++ b/src/test/regress/sql/indexing.sql @@ -703,3 +703,13 @@ alter table parted_uniq_detach_test1 drop constraint parted_uniq_detach_test1_a_ alter table parted_uniq_detach_test detach partition parted_uniq_detach_test1; alter table parted_uniq_detach_test1 drop constraint parted_uniq_detach_test1_a_key; drop table parted_uniq_detach_test, parted_uniq_detach_test1; + +-- check that dropping a column takes with it any partitioned indexes +-- depending on it +create table parted_index_col_drop(a int, b int, c int) partition by list (a); +create table parted_index_col_drop1 partition of parted_index_col_drop for values in (1) partition by list (a); +create table parted_index_col_drop11 partition of parted_index_col_drop1 for values in (1); +create index on parted_index_col_drop (b, c); +alter table parted_index_col_drop drop c; +\d parted_index_col_drop +drop table parted_index_col_drop;