Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitafc7e0a

Browse files
committed
Raise error on concurrent drop of partitioned index
We were already raising an error for DROP INDEX CONCURRENTLY on apartitioned table, albeit a different and confusing one: ERROR: DROP INDEX CONCURRENTLY must be first action in transactionChange that to throw a more comprehensible error: ERROR: cannot drop partitioned index \"%s\" concurrentlyMichael Paquier authored the test case for indexes on temporarypartitioned 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 parentb55b4da commitafc7e0a

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
createindexon idxpart (a);
9393
createtableidxpart1 partition of idxpart forvaluesfrom (0) to (10);
9494
dropindex idxpart1_a_idx;-- no way
95+
dropindex concurrently idxpart_a_idx;-- unsupported
9596
dropindex idxpart_a_idx;-- both indexes go away
9697
select relname, relkindfrom pg_class
9798
where relnamelike'idxpart%'order by relname;
@@ -101,6 +102,18 @@ select relname, relkind from pg_class
101102
where relnamelike'idxpart%'order by relname;
102103
droptable idxpart;
103104

105+
-- DROP behavior with temporary partitioned indexes
106+
create temp table idxpart_temp (aint) partition by range (a);
107+
createindexon idxpart_temp(a);
108+
create temp table idxpart1_temp partition of idxpart_temp
109+
forvaluesfrom (0) to (10);
110+
dropindex idxpart1_temp_a_idx;-- error
111+
-- non-concurrent drop is enforced here, so it is a valid case.
112+
dropindex concurrently idxpart_temp_a_idx;
113+
select relname, relkindfrom pg_class
114+
where relnamelike'idxpart_temp%'order by relname;
115+
droptable idxpart_temp;
116+
104117
-- ALTER INDEX .. ATTACH, error cases
105118
createtableidxpart (aint, bint) partition by range (a, b);
106119
createtableidxpart1 partition of idxpart forvaluesfrom (0,0) to (10,10);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp