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

Commit7e7c57b

Browse files
committed
Fix dependency recording bug for partitioned PKs
When DefineIndex recurses to create constraints on partitions, it needsto use the value returned by index_constraint_create to set up partitiondependencies. However, in the course of fixing the DEPENDENCY_INTERNAL_AUTOmess, commit1d92a0c introduced some code to that function thatclobbered the return value, causing the recorded OID to be of the wrongobject. Close examination of pg_depend after creating the tables leadsto indescribable objects :-( My sin (in commitbdc3d7f, whilepreparing for DDL deparsing in event triggers) was to use a variablename for the return value that's typically used for throwaway objects independency-setting calls ("referenced"). Fix by changing the variablenames to match extended practice (the return value is "myself" ratherthan "referenced".)The pg_upgrade test notices the problem (in an indirect way: the pg_dumpoutputs are in different order), but only if you create the objects in aspecific way that wasn't being used in the existing tests. Add a stanzato leave some objects around that shows the bug.Catversion bump because preexisting databases might have bogus pg_dependentries.Discussion:https://postgr.es/m/20190318204235.GA30360@alvherre.pgsql
1 parentbfb456c commit7e7c57b

File tree

3 files changed

+44
-12
lines changed

3 files changed

+44
-12
lines changed

‎src/backend/catalog/index.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,7 @@ index_constraint_create(Relation heapRelation,
12471247
{
12481248
OidnamespaceId=RelationGetNamespace(heapRelation);
12491249
ObjectAddressmyself,
1250-
referenced;
1250+
idxaddr;
12511251
OidconOid;
12521252
booldeferrable;
12531253
boolinitdeferred;
@@ -1341,23 +1341,18 @@ index_constraint_create(Relation heapRelation,
13411341
* Note that the constraint has a dependency on the table, so we don't
13421342
* need (or want) any direct dependency from the index to the table.
13431343
*/
1344-
myself.classId=RelationRelationId;
1345-
myself.objectId=indexRelationId;
1346-
myself.objectSubId=0;
1347-
1348-
referenced.classId=ConstraintRelationId;
1349-
referenced.objectId=conOid;
1350-
referenced.objectSubId=0;
1351-
1352-
recordDependencyOn(&myself,&referenced,DEPENDENCY_INTERNAL);
1344+
ObjectAddressSet(myself,ConstraintRelationId,conOid);
1345+
ObjectAddressSet(idxaddr,RelationRelationId,indexRelationId);
1346+
recordDependencyOn(&idxaddr,&myself,DEPENDENCY_INTERNAL);
13531347

13541348
/*
13551349
* Also, if this is a constraint on a partition, give it partition-type
13561350
* dependencies on the parent constraint as well as the table.
13571351
*/
13581352
if (OidIsValid(parentConstraintId))
13591353
{
1360-
ObjectAddressSet(myself,ConstraintRelationId,conOid);
1354+
ObjectAddressreferenced;
1355+
13611356
ObjectAddressSet(referenced,ConstraintRelationId,parentConstraintId);
13621357
recordDependencyOn(&myself,&referenced,DEPENDENCY_PARTITION_PRI);
13631358
ObjectAddressSet(referenced,RelationRelationId,
@@ -1444,7 +1439,7 @@ index_constraint_create(Relation heapRelation,
14441439
table_close(pg_index,RowExclusiveLock);
14451440
}
14461441

1447-
returnreferenced;
1442+
returnmyself;
14481443
}
14491444

14501445
/*

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,24 @@ alter index idxpart2_a_idx attach partition idxpart22_a_idx;
14111411
create index on idxpart (a);
14121412
create table idxpart_another (a int, b int, primary key (a, b)) partition by range (a);
14131413
create table idxpart_another_1 partition of idxpart_another for values from (0) to (100);
1414+
-- More objects intentionally left behind, to verify some pg_dump/pg_upgrade
1415+
-- behavior; see https://postgr.es/m/20190321204928.GA17535@alvherre.pgsql
1416+
create schema regress_indexing;
1417+
set search_path to regress_indexing;
1418+
create table pk (a int primary key) partition by range (a);
1419+
create table pk1 partition of pk for values from (0) to (1000);
1420+
create table pk2 (b int, a int);
1421+
alter table pk2 drop column b;
1422+
alter table pk2 alter a set not null;
1423+
alter table pk attach partition pk2 for values from (1000) to (2000);
1424+
create table pk3 partition of pk for values from (2000) to (3000);
1425+
create table pk4 (like pk);
1426+
alter table pk attach partition pk4 for values from (3000) to (4000);
1427+
create table pk5 (like pk) partition by range (a);
1428+
create table pk51 partition of pk5 for values from (4000) to (4500);
1429+
create table pk52 partition of pk5 for values from (4500) to (5000);
1430+
alter table pk attach partition pk5 for values from (4000) to (5000);
1431+
reset search_path;
14141432
-- Test that covering partitioned indexes work in various cases
14151433
create table covidxpart (a int, b int) partition by list (a);
14161434
create unique index on covidxpart (a) include (b);

‎src/test/regress/sql/indexing.sql

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,25 @@ create index on idxpart (a);
748748
createtableidxpart_another (aint, bint,primary key (a, b)) partition by range (a);
749749
createtableidxpart_another_1 partition of idxpart_another forvaluesfrom (0) to (100);
750750

751+
-- More objects intentionally left behind, to verify some pg_dump/pg_upgrade
752+
-- behavior; see https://postgr.es/m/20190321204928.GA17535@alvherre.pgsql
753+
createschemaregress_indexing;
754+
set search_path to regress_indexing;
755+
createtablepk (aintprimary key) partition by range (a);
756+
createtablepk1 partition of pk forvaluesfrom (0) to (1000);
757+
createtablepk2 (bint, aint);
758+
altertable pk2 drop column b;
759+
altertable pk2 alter asetnot null;
760+
altertable pk attach partition pk2 forvaluesfrom (1000) to (2000);
761+
createtablepk3 partition of pk forvaluesfrom (2000) to (3000);
762+
createtablepk4 (like pk);
763+
altertable pk attach partition pk4 forvaluesfrom (3000) to (4000);
764+
createtablepk5 (like pk) partition by range (a);
765+
createtablepk51 partition of pk5 forvaluesfrom (4000) to (4500);
766+
createtablepk52 partition of pk5 forvaluesfrom (4500) to (5000);
767+
altertable pk attach partition pk5 forvaluesfrom (4000) to (5000);
768+
reset search_path;
769+
751770
-- Test that covering partitioned indexes work in various cases
752771
createtablecovidxpart (aint, bint) partition by list (a);
753772
createunique indexon covidxpart (a) include (b);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp