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

Commit0b48f13

Browse files
committed
Fix assertion failure with ALTER TABLE ATTACH PARTITION and indexes
Using ALTER TABLE ATTACH PARTITION causes an assertion failure whenattempting to work on a partitioned index, because partitioned indexescannot have partition bounds.The grammar of ALTER TABLE ATTACH PARTITION requires partition bounds,but not ALTER INDEX, so mixing ALTER TABLE with partitioned indexes isconfusing. Hence, on HEAD, prevent ALTER TABLE to attach a partition ifthe relation involved is a partitioned index. On back-branches, asapplications may rely on the existing behavior, just remove theculprit assertion.Reported-by: Alexander LakhinAuthor: Amit Langote, Michael PaquierDiscussion:https://postgr.es/m/16276-5cd1dcc8fb8be7b5@postgresql.orgBackpatch-through: 11
1 parent54a4f52 commit0b48f13

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

‎src/backend/parser/parse_utilcmd.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3698,8 +3698,16 @@ transformPartitionCmd(CreateStmtContext *cxt, PartitionCmd *cmd)
36983698
cmd->bound);
36993699
break;
37003700
caseRELKIND_PARTITIONED_INDEX:
3701-
/* nothing to check */
3702-
Assert(cmd->bound==NULL);
3701+
3702+
/*
3703+
* A partitioned index cannot have a partition bound set. ALTER
3704+
* INDEX prevents that with its grammar, but not ALTER TABLE.
3705+
*/
3706+
if (cmd->bound!=NULL)
3707+
ereport(ERROR,
3708+
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3709+
errmsg("\"%s\" is not a partitioned table",
3710+
RelationGetRelationName(parentRel))));
37033711
break;
37043712
caseRELKIND_RELATION:
37053713
/* the table must be partitioned */

‎src/test/regress/expected/indexing.out

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,23 @@ Partition of: idxparti2
121121
No partition constraint
122122
btree, for table "public.idxpart1"
123123

124+
-- Forbid ALTER TABLE when attaching or detaching an index to a partition.
125+
create index idxpart_c on only idxpart (c);
126+
create index idxpart1_c on idxpart1 (c);
127+
alter table idxpart_c attach partition idxpart1_c for values from (10) to (20);
128+
ERROR: "idxpart_c" is not a partitioned table
129+
alter index idxpart_c attach partition idxpart1_c;
130+
select relname, relpartbound from pg_class
131+
where relname in ('idxpart_c', 'idxpart1_c')
132+
order by relname;
133+
relname | relpartbound
134+
------------+--------------
135+
idxpart1_c |
136+
idxpart_c |
137+
(2 rows)
138+
139+
alter table idxpart_c detach partition idxpart1_c;
140+
ERROR: "idxpart_c" is not a table
124141
drop table idxpart;
125142
-- If a partition already has an index, don't create a duplicative one
126143
create table idxpart (a int, b int) partition by range (a, b);

‎src/test/regress/sql/indexing.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ alter table idxpart attach partition idxpart1 for values from (0) to (10);
6363
\d idxpart1
6464
\d+ idxpart1_a_idx
6565
\d+ idxpart1_b_c_idx
66+
67+
-- Forbid ALTER TABLE when attaching or detaching an index to a partition.
68+
createindexidxpart_con only idxpart (c);
69+
createindexidxpart1_con idxpart1 (c);
70+
altertable idxpart_c attach partition idxpart1_c forvaluesfrom (10) to (20);
71+
alterindex idxpart_c attach partition idxpart1_c;
72+
select relname, relpartboundfrom pg_class
73+
where relnamein ('idxpart_c','idxpart1_c')
74+
order by relname;
75+
altertable idxpart_c detach partition idxpart1_c;
6676
droptable idxpart;
6777

6878
-- If a partition already has an index, don't create a duplicative one

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp