Skip to content

Commit 7067ba1

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 55aea0c commit 7067ba1

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
@@ -1347,6 +1347,17 @@ RemoveRelations(DropStmt *drop)
13471347
flags |= PERFORM_DELETION_CONCURRENTLY;
13481348
}
13491349

1350+
/*
1351+
* Concurrent index drop cannot be used with partitioned indexes,
1352+
* either.
1353+
*/
1354+
if ((flags & PERFORM_DELETION_CONCURRENTLY) != 0 &&
1355+
get_rel_relkind(relOid) == RELKIND_PARTITIONED_INDEX)
1356+
ereport(ERROR,
1357+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1358+
errmsg("cannot drop partitioned index \"%s\" concurrently",
1359+
rel->relname)));
1360+
13501361
/* OK, we're ready to delete this one */
13511362
obj.classId = RelationRelationId;
13521363
obj.objectId = relOid;

src/test/regress/expected/indexing.out

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ create table idxpart1 partition of idxpart for values from (0) to (10);
173173
drop index idxpart1_a_idx; -- no way
174174
ERROR: cannot drop index idxpart1_a_idx because index idxpart_a_idx requires it
175175
HINT: You can drop index idxpart_a_idx instead.
176+
drop index concurrently idxpart_a_idx; -- unsupported
177+
ERROR: cannot drop partitioned index "idxpart_a_idx" concurrently
176178
drop index idxpart_a_idx; -- both indexes go away
177179
select relname, relkind from pg_class
178180
where relname like 'idxpart%' order by relname;
@@ -193,6 +195,24 @@ select relname, relkind from pg_class
193195
(2 rows)
194196

195197
drop table idxpart;
198+
-- DROP behavior with temporary partitioned indexes
199+
create temp table idxpart_temp (a int) partition by range (a);
200+
create index on idxpart_temp(a);
201+
create temp table idxpart1_temp partition of idxpart_temp
202+
for values from (0) to (10);
203+
drop index idxpart1_temp_a_idx; -- error
204+
ERROR: cannot drop index idxpart1_temp_a_idx because index idxpart_temp_a_idx requires it
205+
HINT: You can drop index idxpart_temp_a_idx instead.
206+
-- non-concurrent drop is enforced here, so it is a valid case.
207+
drop index concurrently idxpart_temp_a_idx;
208+
select relname, relkind from pg_class
209+
where relname like 'idxpart_temp%' order by relname;
210+
relname | relkind
211+
--------------+---------
212+
idxpart_temp | p
213+
(1 row)
214+
215+
drop table idxpart_temp;
196216
-- ALTER INDEX .. ATTACH, error cases
197217
create table idxpart (a int, b int) partition by range (a, b);
198218
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
@@ -92,6 +92,7 @@ create table idxpart (a int) partition by range (a);
9292
create index on idxpart (a);
9393
create table idxpart1 partition of idxpart for values from (0) to (10);
9494
drop index idxpart1_a_idx; -- no way
95+
drop index concurrently idxpart_a_idx; -- unsupported
9596
drop index idxpart_a_idx; -- both indexes go away
9697
select relname, relkind from pg_class
9798
where relname like 'idxpart%' order by relname;
@@ -101,6 +102,18 @@ select relname, relkind from pg_class
101102
where relname like 'idxpart%' order by relname;
102103
drop table idxpart;
103104

105+
-- DROP behavior with temporary partitioned indexes
106+
create temp table idxpart_temp (a int) partition by range (a);
107+
create index on idxpart_temp(a);
108+
create temp table idxpart1_temp partition of idxpart_temp
109+
for values from (0) to (10);
110+
drop index idxpart1_temp_a_idx; -- error
111+
-- non-concurrent drop is enforced here, so it is a valid case.
112+
drop index concurrently idxpart_temp_a_idx;
113+
select relname, relkind from pg_class
114+
where relname like 'idxpart_temp%' order by relname;
115+
drop table idxpart_temp;
116+
104117
-- ALTER INDEX .. ATTACH, error cases
105118
create table idxpart (a int, b int) partition by range (a, b);
106119
create table idxpart1 partition of idxpart for values from (0, 0) to (10, 10);

0 commit comments

Comments
 (0)