Skip to content

Commit f00f5e0

Browse files
committed
Raise error on concurrent drop of partitioned index
We were already raising an error for DROP INDEX CONCURRENTLY on a partitioned table, albeit a different and confusing one: ERROR: DROP INDEX CONCURRENTLY must be first action in transaction Change that to throw a more comprehensible error: ERROR: cannot drop partitioned index \"%s\" concurrently Michael Paquier authored the test case for indexes on temporary partitioned tables. Backpatch to 11, where indexes on partitioned tables were added. Reported-by: Jan Mussler <jan.mussler@zalando.de> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/16594-d2956ca909585067@postgresql.org
1 parent df8020b commit f00f5e0

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

doc/src/sgml/ref/drop_index.sgml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ DROP INDEX [ CONCURRENTLY ] [ IF EXISTS ] <replaceable class="parameter">name</r
5757
Also, regular <command>DROP INDEX</command> commands can be
5858
performed within a transaction block, but
5959
<command>DROP INDEX CONCURRENTLY</command> cannot.
60+
Lastly, indexes on partitioned tables cannot be dropped using this
61+
option.
6062
</para>
6163
<para>
6264
For temporary tables, <command>DROP INDEX</command> is always

src/backend/commands/tablecmds.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,17 @@ RemoveRelations(DropStmt *drop)
12161216
flags |= PERFORM_DELETION_CONCURRENTLY;
12171217
}
12181218

1219+
/*
1220+
* Concurrent index drop cannot be used with partitioned indexes,
1221+
* either.
1222+
*/
1223+
if ((flags & PERFORM_DELETION_CONCURRENTLY) != 0 &&
1224+
get_rel_relkind(relOid) == RELKIND_PARTITIONED_INDEX)
1225+
ereport(ERROR,
1226+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1227+
errmsg("cannot drop partitioned index \"%s\" concurrently",
1228+
rel->relname)));
1229+
12191230
/* OK, we're ready to delete this one */
12201231
obj.classId = RelationRelationId;
12211232
obj.objectId = relOid;

src/test/regress/expected/indexing.out

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ create table idxpart1 partition of idxpart for values from (0) to (10);
146146
drop index idxpart1_a_idx; -- no way
147147
ERROR: cannot drop index idxpart1_a_idx because index idxpart_a_idx requires it
148148
HINT: You can drop index idxpart_a_idx instead.
149+
drop index concurrently idxpart_a_idx; -- unsupported
150+
ERROR: cannot drop partitioned index "idxpart_a_idx" concurrently
149151
drop index idxpart_a_idx; -- both indexes go away
150152
select relname, relkind from pg_class
151153
where relname like 'idxpart%' order by relname;
@@ -166,6 +168,24 @@ select relname, relkind from pg_class
166168
(2 rows)
167169

168170
drop table idxpart;
171+
-- DROP behavior with temporary partitioned indexes
172+
create temp table idxpart_temp (a int) partition by range (a);
173+
create index on idxpart_temp(a);
174+
create temp table idxpart1_temp partition of idxpart_temp
175+
for values from (0) to (10);
176+
drop index idxpart1_temp_a_idx; -- error
177+
ERROR: cannot drop index idxpart1_temp_a_idx because index idxpart_temp_a_idx requires it
178+
HINT: You can drop index idxpart_temp_a_idx instead.
179+
-- non-concurrent drop is enforced here, so it is a valid case.
180+
drop index concurrently idxpart_temp_a_idx;
181+
select relname, relkind from pg_class
182+
where relname like 'idxpart_temp%' order by relname;
183+
relname | relkind
184+
--------------+---------
185+
idxpart_temp | p
186+
(1 row)
187+
188+
drop table idxpart_temp;
169189
-- ALTER INDEX .. ATTACH, error cases
170190
create table idxpart (a int, b int) partition by range (a, b);
171191
create table idxpart1 partition of idxpart for values from (0, 0) to (10, 10);

src/test/regress/sql/indexing.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ create table idxpart (a int) partition by range (a);
7575
create index on idxpart (a);
7676
create table idxpart1 partition of idxpart for values from (0) to (10);
7777
drop index idxpart1_a_idx; -- no way
78+
drop index concurrently idxpart_a_idx; -- unsupported
7879
drop index idxpart_a_idx; -- both indexes go away
7980
select relname, relkind from pg_class
8081
where relname like 'idxpart%' order by relname;
@@ -84,6 +85,18 @@ select relname, relkind from pg_class
8485
where relname like 'idxpart%' order by relname;
8586
drop table idxpart;
8687

88+
-- DROP behavior with temporary partitioned indexes
89+
create temp table idxpart_temp (a int) partition by range (a);
90+
create index on idxpart_temp(a);
91+
create temp table idxpart1_temp partition of idxpart_temp
92+
for values from (0) to (10);
93+
drop index idxpart1_temp_a_idx; -- error
94+
-- non-concurrent drop is enforced here, so it is a valid case.
95+
drop index concurrently idxpart_temp_a_idx;
96+
select relname, relkind from pg_class
97+
where relname like 'idxpart_temp%' order by relname;
98+
drop table idxpart_temp;
99+
87100
-- ALTER INDEX .. ATTACH, error cases
88101
create table idxpart (a int, b int) partition by range (a, b);
89102
create table idxpart1 partition of idxpart for values from (0, 0) to (10, 10);

0 commit comments

Comments
 (0)