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

Commitf10815c

Browse files
committed
Fix failure when creating cloned indexes for a partition
When using CREATE TABLE for a new partition, the partitioned indexes ofthe parent are created automatically in a fashion similar to LIKEINDEXES. The new partition and its parent use a mapping for attributenumbers for this operation, and while the mapping was correctly built,its length was defined as the number of attributes of the newly-createdchild, and not the parent. If the parent includes dropped columns, thiscould cause failures.This is wrong since8b08f7d which has introduced the concept ofpartitioned indexes, so backpatch down to 11.Reported-by: Wyatt AltAuthor: Michael PaquierReviewed-by: Amit LangoteDiscussion:https://postgr.es/m/CAGem3qCcRmhbs4jYMkenYNfP2kEusDXvTfw-q+eOhM0zTceG-g@mail.gmail.comBackpatch-through: 11
1 parent61f2383 commitf10815c

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
961961
gettext_noop("could not convert row type"));
962962
idxstmt=
963963
generateClonedIndexStmt(NULL,RelationGetRelid(rel),idxRel,
964-
attmap,RelationGetDescr(rel)->natts,
964+
attmap,RelationGetDescr(parent)->natts,
965965
&constraintOid);
966966
DefineIndex(RelationGetRelid(rel),
967967
idxstmt,

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,3 +1006,52 @@ CONTEXT: SQL statement "create table tab_part_create_1 partition of tab_part_cr
10061006
PL/pgSQL function func_part_create() line 3 at EXECUTE
10071007
drop table tab_part_create;
10081008
drop function func_part_create();
1009+
-- tests of column drop with partition tables and indexes using
1010+
-- predicates and expressions.
1011+
create table part_column_drop (
1012+
useless_1 int,
1013+
id int,
1014+
useless_2 int,
1015+
d int,
1016+
b int,
1017+
useless_3 int
1018+
) partition by range (id);
1019+
alter table part_column_drop drop column useless_1;
1020+
alter table part_column_drop drop column useless_2;
1021+
alter table part_column_drop drop column useless_3;
1022+
create index part_column_drop_b_pred on part_column_drop(b) where b = 1;
1023+
create index part_column_drop_b_expr on part_column_drop((b = 1));
1024+
create index part_column_drop_d_pred on part_column_drop(d) where d = 2;
1025+
create index part_column_drop_d_expr on part_column_drop((d = 2));
1026+
create table part_column_drop_1_10 partition of
1027+
part_column_drop for values from (1) to (10);
1028+
\d part_column_drop
1029+
Table "public.part_column_drop"
1030+
Column | Type | Collation | Nullable | Default
1031+
--------+---------+-----------+----------+---------
1032+
id | integer | | |
1033+
d | integer | | |
1034+
b | integer | | |
1035+
Partition key: RANGE (id)
1036+
Indexes:
1037+
"part_column_drop_b_expr" btree ((b = 1))
1038+
"part_column_drop_b_pred" btree (b) WHERE b = 1
1039+
"part_column_drop_d_expr" btree ((d = 2))
1040+
"part_column_drop_d_pred" btree (d) WHERE d = 2
1041+
Number of partitions: 1 (Use \d+ to list them.)
1042+
1043+
\d part_column_drop_1_10
1044+
Table "public.part_column_drop_1_10"
1045+
Column | Type | Collation | Nullable | Default
1046+
--------+---------+-----------+----------+---------
1047+
id | integer | | |
1048+
d | integer | | |
1049+
b | integer | | |
1050+
Partition of: part_column_drop FOR VALUES FROM (1) TO (10)
1051+
Indexes:
1052+
"part_column_drop_1_10_b_idx" btree (b) WHERE b = 1
1053+
"part_column_drop_1_10_d_idx" btree (d) WHERE d = 2
1054+
"part_column_drop_1_10_expr_idx" btree ((b = 1))
1055+
"part_column_drop_1_10_expr_idx1" btree ((d = 2))
1056+
1057+
drop table part_column_drop;

‎src/test/regress/sql/create_table.sql

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,3 +814,26 @@ create trigger trig_part_create before insert on tab_part_create
814814
insert into tab_part_createvalues (1);
815815
droptable tab_part_create;
816816
dropfunction func_part_create();
817+
818+
-- tests of column drop with partition tables and indexes using
819+
-- predicates and expressions.
820+
createtablepart_column_drop (
821+
useless_1int,
822+
idint,
823+
useless_2int,
824+
dint,
825+
bint,
826+
useless_3int
827+
) partition by range (id);
828+
altertable part_column_drop drop column useless_1;
829+
altertable part_column_drop drop column useless_2;
830+
altertable part_column_drop drop column useless_3;
831+
createindexpart_column_drop_b_predon part_column_drop(b)where b=1;
832+
createindexpart_column_drop_b_expron part_column_drop((b=1));
833+
createindexpart_column_drop_d_predon part_column_drop(d)where d=2;
834+
createindexpart_column_drop_d_expron part_column_drop((d=2));
835+
createtablepart_column_drop_1_10 partition of
836+
part_column_drop forvaluesfrom (1) to (10);
837+
\d part_column_drop
838+
\d part_column_drop_1_10
839+
droptable part_column_drop;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp