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

Commit7cd0fd6

Browse files
committed
Invalid parent's relcache after CREATE TABLE .. PARTITION OF.
Otherwise, subsequent commands in the same transaction see the wrongpartition descriptor.Amit Langote. Reported by Tomas Vondra and David Fetter. Reviewedby me.Discussion:http://postgr.es/m/22dd313b-d7fd-22b5-0787-654845c8f849%402ndquadrant.comDiscussion:http://postgr.es/m/20161215090916.GB20659%40fetter.org
1 parente13029a commit7cd0fd6

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

‎src/backend/catalog/heap.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3230,9 +3230,12 @@ RemovePartitionKeyByRelId(Oid relid)
32303230
* StorePartitionBound
32313231
*Update pg_class tuple of rel to store the partition bound and set
32323232
*relispartition to true
3233+
*
3234+
* Also, invalidate the parent's relcache, so that the next rebuild will load
3235+
* the new partition's info into its partition descriptor.
32333236
*/
32343237
void
3235-
StorePartitionBound(Relationrel,Node*bound)
3238+
StorePartitionBound(Relationrel,Relationparent,Node*bound)
32363239
{
32373240
RelationclassRel;
32383241
HeapTupletuple,
@@ -3273,4 +3276,6 @@ StorePartitionBound(Relation rel, Node *bound)
32733276
CatalogUpdateIndexes(classRel,newtuple);
32743277
heap_freetuple(newtuple);
32753278
heap_close(classRel,RowExclusiveLock);
3279+
3280+
CacheInvalidateRelcache(parent);
32763281
}

‎src/backend/commands/tablecmds.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -777,10 +777,11 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
777777
* it does not return on error.
778778
*/
779779
check_new_partition_bound(relname,parent,bound);
780-
heap_close(parent,NoLock);
781780

782781
/* Update the pg_class entry. */
783-
StorePartitionBound(rel,bound);
782+
StorePartitionBound(rel,parent,bound);
783+
784+
heap_close(parent,NoLock);
784785

785786
/*
786787
* The code that follows may also update the pg_class tuple to update
@@ -13141,7 +13142,7 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
1314113142
cmd->bound);
1314213143

1314313144
/* Update the pg_class entry. */
13144-
StorePartitionBound(attachRel,cmd->bound);
13145+
StorePartitionBound(attachRel,rel,cmd->bound);
1314513146

1314613147
/*
1314713148
* Generate partition constraint from the partition bound specification.
@@ -13352,12 +13353,6 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
1335213353
}
1335313354
}
1335413355

13355-
/*
13356-
* Invalidate the parent's relcache so that the new partition is now
13357-
* included its partition descriptor.
13358-
*/
13359-
CacheInvalidateRelcache(rel);
13360-
1336113356
ObjectAddressSet(address,RelationRelationId,RelationGetRelid(attachRel));
1336213357

1336313358
/* keep our lock until commit */

‎src/include/catalog/heap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,6 @@ extern void StorePartitionKey(Relation rel,
143143
Oid*partopclass,
144144
Oid*partcollation);
145145
externvoidRemovePartitionKeyByRelId(Oidrelid);
146-
externvoidStorePartitionBound(Relationrel,Node*bound);
146+
externvoidStorePartitionBound(Relationrel,Relationparent,Node*bound);
147147

148148
#endif/* HEAP_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp