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

Commitdc83648

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 parentf22feed commitdc83648

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

‎src/backend/parser/parse_utilcmd.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3685,7 +3685,6 @@ transformPartitionCmd(CreateStmtContext *cxt, PartitionCmd *cmd)
36853685
break;
36863686
caseRELKIND_PARTITIONED_INDEX:
36873687
/* nothing to check */
3688-
Assert(cmd->bound==NULL);
36893688
break;
36903689
caseRELKIND_RELATION:
36913690
/* the table must be partitioned */

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

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

124+
-- 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+
alter index idxpart_c attach partition idxpart1_c;
129+
select relname, relpartbound from pg_class
130+
where relname in ('idxpart_c', 'idxpart1_c')
131+
order by relname;
132+
relname | relpartbound
133+
------------+--------------
134+
idxpart1_c |
135+
idxpart_c |
136+
(2 rows)
137+
138+
alter table idxpart_c detach partition idxpart1_c;
139+
ERROR: "idxpart_c" is not a table
124140
drop table idxpart;
125141
-- If a partition already has an index, don't create a duplicative one
126142
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+
-- 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