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

Commit75839fc

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 parent53fc42c commit75839fc

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
@@ -3563,7 +3563,6 @@ transformPartitionCmd(CreateStmtContext *cxt, PartitionCmd *cmd)
35633563
break;
35643564
caseRELKIND_PARTITIONED_INDEX:
35653565
/* nothing to check */
3566-
Assert(cmd->bound==NULL);
35673566
break;
35683567
caseRELKIND_RELATION:
35693568
/* 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
@@ -94,6 +94,22 @@ Partition of: idxparti2
9494
No partition constraint
9595
btree, for table "public.idxpart1"
9696

97+
-- ALTER TABLE when attaching or detaching an index to a partition.
98+
create index idxpart_c on only idxpart (c);
99+
create index idxpart1_c on idxpart1 (c);
100+
alter table idxpart_c attach partition idxpart1_c for values from (10) to (20);
101+
alter index idxpart_c attach partition idxpart1_c;
102+
select relname, relpartbound from pg_class
103+
where relname in ('idxpart_c', 'idxpart1_c')
104+
order by relname;
105+
relname | relpartbound
106+
------------+--------------
107+
idxpart1_c |
108+
idxpart_c |
109+
(2 rows)
110+
111+
alter table idxpart_c detach partition idxpart1_c;
112+
ERROR: "idxpart_c" is not a table
97113
drop table idxpart;
98114
-- If a partition already has an index, don't create a duplicative one
99115
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
@@ -46,6 +46,16 @@ alter table idxpart attach partition idxpart1 for values from (0) to (10);
4646
\d idxpart1
4747
\d+ idxpart1_a_idx
4848
\d+ idxpart1_b_c_idx
49+
50+
-- ALTER TABLE when attaching or detaching an index to a partition.
51+
createindexidxpart_con only idxpart (c);
52+
createindexidxpart1_con idxpart1 (c);
53+
altertable idxpart_c attach partition idxpart1_c forvaluesfrom (10) to (20);
54+
alterindex idxpart_c attach partition idxpart1_c;
55+
select relname, relpartboundfrom pg_class
56+
where relnamein ('idxpart_c','idxpart1_c')
57+
order by relname;
58+
altertable idxpart_c detach partition idxpart1_c;
4959
droptable idxpart;
5060

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp