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

Commit71a05b2

Browse files
committed
Don't mark partitioned indexes invalid unnecessarily
When an indexes is created on a partitioned table using ONLY (don'trecurse to partitions), it gets marked invalid until index partitionsare attached for each table partition. But there's no reason to do thisif there are no partitions ... and moreover, there's no way to get theindex to become valid afterwards, because all partitions that getcreated/attached get their own index partition already attached to theparent index, so there's no chance to do ALTER INDEX ... ATTACH PARTITIONthat would make the parent index valid.Fix by not marking the index as invalid to begin with.This is very similar to9139aa1, but the pg_dump aspect does notappear to be relevant until we add FKs that can point to PKs onpartitioned tables. (I tried to cause the pg_upgrade test to break byleaving some of these bogus tables around, but wasn't able to.)Making this change means that an index that was supposed to be invalidin the insert_conflict regression test is no longer invalid; reorder theDDL so that the test continues to verify the behavior we want it to.Author: Álvaro HerreraReviewed-by: Amit LangoteDiscussion:https://postgr.es/m/20181203225019.2vvdef2ybnkxt364@alvherre.pgsql
1 parent99f9cce commit71a05b2

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

‎src/backend/commands/indexcmds.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,8 +833,18 @@ DefineIndex(Oid relationId,
833833
flags |=INDEX_CREATE_PARTITIONED;
834834
if (stmt->primary)
835835
flags |=INDEX_CREATE_IS_PRIMARY;
836+
837+
/*
838+
* If the table is partitioned, and recursion was declined but partitions
839+
* exist, mark the index as invalid.
840+
*/
836841
if (partitioned&&stmt->relation&& !stmt->relation->inh)
837-
flags |=INDEX_CREATE_INVALID;
842+
{
843+
PartitionDescpd=RelationGetPartitionDesc(rel);
844+
845+
if (pd->nparts!=0)
846+
flags |=INDEX_CREATE_INVALID;
847+
}
838848

839849
if (stmt->deferrable)
840850
constr_flags |=INDEX_CONSTR_CREATE_DEFERRABLE;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,10 +813,10 @@ drop table parted_conflict;
813813
-- partition
814814
create table parted_conflict (a int, b text) partition by range (a);
815815
create table parted_conflict_1 partition of parted_conflict for values from (0) to (1000) partition by range (a);
816+
create table parted_conflict_1_1 partition of parted_conflict_1 for values from (0) to (500);
816817
create unique index on only parted_conflict_1 (a);
817818
create unique index on only parted_conflict (a);
818819
alter index parted_conflict_a_idx attach partition parted_conflict_1_a_idx;
819-
create table parted_conflict_1_1 partition of parted_conflict_1 for values from (0) to (500);
820820
insert into parted_conflict values (40, 'forty');
821821
insert into parted_conflict_1 values (40, 'cuarenta')
822822
on conflict (a) do update set b = excluded.b;

‎src/test/regress/sql/insert_conflict.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,10 +528,10 @@ drop table parted_conflict;
528528
-- partition
529529
createtableparted_conflict (aint, btext) partition by range (a);
530530
createtableparted_conflict_1 partition of parted_conflict forvaluesfrom (0) to (1000) partition by range (a);
531+
createtableparted_conflict_1_1 partition of parted_conflict_1 forvaluesfrom (0) to (500);
531532
createunique indexon only parted_conflict_1 (a);
532533
createunique indexon only parted_conflict (a);
533534
alterindex parted_conflict_a_idx attach partition parted_conflict_1_a_idx;
534-
createtableparted_conflict_1_1 partition of parted_conflict_1 forvaluesfrom (0) to (500);
535535
insert into parted_conflictvalues (40,'forty');
536536
insert into parted_conflict_1values (40,'cuarenta')
537537
on conflict (a) doupdateset b=excluded.b;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp