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

Commit37798a8

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 parent367f362 commit37798a8

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
@@ -834,8 +834,18 @@ DefineIndex(Oid relationId,
834834
flags |=INDEX_CREATE_PARTITIONED;
835835
if (stmt->primary)
836836
flags |=INDEX_CREATE_IS_PRIMARY;
837+
838+
/*
839+
* If the table is partitioned, and recursion was declined but partitions
840+
* exist, mark the index as invalid.
841+
*/
837842
if (partitioned&&stmt->relation&& !stmt->relation->inh)
838-
flags |=INDEX_CREATE_INVALID;
843+
{
844+
PartitionDescpd=RelationGetPartitionDesc(rel);
845+
846+
if (pd->nparts!=0)
847+
flags |=INDEX_CREATE_INVALID;
848+
}
839849

840850
if (stmt->deferrable)
841851
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
@@ -876,10 +876,10 @@ drop table parted_conflict;
876876
-- partition
877877
create table parted_conflict (a int, b text) partition by range (a);
878878
create table parted_conflict_1 partition of parted_conflict for values from (0) to (1000) partition by range (a);
879+
create table parted_conflict_1_1 partition of parted_conflict_1 for values from (0) to (500);
879880
create unique index on only parted_conflict_1 (a);
880881
create unique index on only parted_conflict (a);
881882
alter index parted_conflict_a_idx attach partition parted_conflict_1_a_idx;
882-
create table parted_conflict_1_1 partition of parted_conflict_1 for values from (0) to (500);
883883
insert into parted_conflict values (40, 'forty');
884884
insert into parted_conflict_1 values (40, 'cuarenta')
885885
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
@@ -551,10 +551,10 @@ drop table parted_conflict;
551551
-- partition
552552
createtableparted_conflict (aint, btext) partition by range (a);
553553
createtableparted_conflict_1 partition of parted_conflict forvaluesfrom (0) to (1000) partition by range (a);
554+
createtableparted_conflict_1_1 partition of parted_conflict_1 forvaluesfrom (0) to (500);
554555
createunique indexon only parted_conflict_1 (a);
555556
createunique indexon only parted_conflict (a);
556557
alterindex parted_conflict_a_idx attach partition parted_conflict_1_a_idx;
557-
createtableparted_conflict_1_1 partition of parted_conflict_1 forvaluesfrom (0) to (500);
558558
insert into parted_conflictvalues (40,'forty');
559559
insert into parted_conflict_1values (40,'cuarenta')
560560
on conflict (a) doupdateset b=excluded.b;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp