Skip to content

Commit afc7e0a

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 b55b4da commit afc7e0a

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
@@ -1373,6 +1373,17 @@ RemoveRelations(DropStmt *drop)
13731373
flags |= PERFORM_DELETION_CONCURRENTLY;
13741374
}
13751375

1376+
/*
1377+
* Concurrent index drop cannot be used with partitioned indexes,
1378+
* either.
1379+
*/
1380+
if ((flags & PERFORM_DELETION_CONCURRENTLY) != 0 &&
1381+
get_rel_relkind(relOid) == RELKIND_PARTITIONED_INDEX)
1382+
ereport(ERROR,
1383+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1384+
errmsg("cannot drop partitioned index \"%s\" concurrently",
1385+
rel->relname)));
1386+
13761387
/* OK, we're ready to delete this one */
13771388
obj.classId = RelationRelationId;
13781389
obj.objectId = relOid;

src/test/regress/expected/indexing.out

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

196198
drop table idxpart;
199+
-- DROP behavior with temporary partitioned indexes
200+
create temp table idxpart_temp (a int) partition by range (a);
201+
create index on idxpart_temp(a);
202+
create temp table idxpart1_temp partition of idxpart_temp
203+
for values from (0) to (10);
204+
drop index idxpart1_temp_a_idx; -- error
205+
ERROR: cannot drop index idxpart1_temp_a_idx because index idxpart_temp_a_idx requires it
206+
HINT: You can drop index idxpart_temp_a_idx instead.
207+
-- non-concurrent drop is enforced here, so it is a valid case.
208+
drop index concurrently idxpart_temp_a_idx;
209+
select relname, relkind from pg_class
210+
where relname like 'idxpart_temp%' order by relname;
211+
relname | relkind
212+
--------------+---------
213+
idxpart_temp | p
214+
(1 row)
215+
216+
drop table idxpart_temp;
197217
-- ALTER INDEX .. ATTACH, error cases
198218
create table idxpart (a int, b int) partition by range (a, b);
199219
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy