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

Commit5616300

Browse files
committed
Fix relcache handling of the 'default' partition
My commit4dba331 that moved around CommandCounterIncrement callsin partitioning DDL code unearthed a problem with the relcache handlingfor the 'default' partition: the construction of a correct relcacheentry for the partitioned table was at the mercy of lack of CCI calls innon-trivial amounts of code. This was prone to creating problems lateron, as the code develops. This was visible as a test failure in acompile with RELCACHE_FORCE_RELASE (buildfarm member prion).The problem is that after the mentioned commit it was possible to createa relcache entry that had incomplete information regarding the defaultpartition because I introduced a CCI between adding the catalog entriesfor the default partition (StorePartitionBound) and the update ofpg_partitioned_table entry for its parent partitioned table(update_default_partition_oid). It seems the best fix is to move thelatter so that it occurs inside the former; the purposeful lack ofintervening CCI should be more obvious, and harder to break.I also remove a check in RelationBuildPartitionDesc that returns NULL ifthe key is not set. I couldn't find any place that needs this hackanymore; probably it was required because of bugs that have since beenfixed.Fix a few typos I noticed while reviewing the code involved.Discussion:https://postgr.es/m/20180320182659.nyzn3vqtjbbtfgwq@alvherre.pgsql
1 parente51a048 commit5616300

File tree

3 files changed

+21
-27
lines changed

3 files changed

+21
-27
lines changed

‎src/backend/catalog/heap.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,7 +1773,8 @@ heap_drop_with_catalog(Oid relid)
17731773
* could attempt to access the just-dropped relation as its partition. We
17741774
* must therefore take a table lock strong enough to prevent all queries
17751775
* on the table from proceeding until we commit and send out a
1776-
* shared-cache-inval notice that will make them update their index lists.
1776+
* shared-cache-inval notice that will make them update their partition
1777+
* descriptors.
17771778
*/
17781779
tuple=SearchSysCache1(RELOID,ObjectIdGetDatum(relid));
17791780
if (!HeapTupleIsValid(tuple))
@@ -3251,6 +3252,9 @@ RemovePartitionKeyByRelId(Oid relid)
32513252
*Update pg_class tuple of rel to store the partition bound and set
32523253
*relispartition to true
32533254
*
3255+
* If this is the default partition, also update the default partition OID in
3256+
* pg_partitioned_table.
3257+
*
32543258
* Also, invalidate the parent's relcache, so that the next rebuild will load
32553259
* the new partition's info into its partition descriptor.  If there is a
32563260
* default partition, we must invalidate its relcache entry as well.
@@ -3302,7 +3306,15 @@ StorePartitionBound(Relation rel, Relation parent, PartitionBoundSpec *bound)
33023306
heap_freetuple(newtuple);
33033307
heap_close(classRel,RowExclusiveLock);
33043308

3305-
/* Make update visible */
3309+
/*
3310+
* If we're storing bounds for the default partition, update
3311+
* pg_partitioned_table too.
3312+
*/
3313+
if (bound->is_default)
3314+
update_default_partition_oid(RelationGetRelid(parent),
3315+
RelationGetRelid(rel));
3316+
3317+
/* Make these updates visible */
33063318
CommandCounterIncrement();
33073319

33083320
/*

‎src/backend/catalog/partition.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,6 @@ RelationBuildPartitionDesc(Relation rel)
227227
/* Range partitioning specific */
228228
PartitionRangeBound**rbounds=NULL;
229229

230-
/*
231-
* The following could happen in situations where rel has a pg_class entry
232-
* but not the pg_partitioned_table entry yet.
233-
*/
234-
if (key==NULL)
235-
return;
236-
237230
/* Get partition oids from pg_inherits */
238231
inhoids=find_inheritance_children(RelationGetRelid(rel),NoLock);
239232

‎src/backend/commands/tablecmds.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -860,10 +860,6 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
860860
/* Update the pg_class entry. */
861861
StorePartitionBound(rel,parent,bound);
862862

863-
/* Update the default partition oid */
864-
if (bound->is_default)
865-
update_default_partition_oid(RelationGetRelid(parent),relationId);
866-
867863
heap_close(parent,NoLock);
868864
}
869865

@@ -14021,11 +14017,6 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
1402114017
/* OK to create inheritance. Rest of the checks performed there */
1402214018
CreateInheritance(attachrel,rel);
1402314019

14024-
/* Update the default partition oid */
14025-
if (cmd->bound->is_default)
14026-
update_default_partition_oid(RelationGetRelid(rel),
14027-
RelationGetRelid(attachrel));
14028-
1402914020
/*
1403014021
* Check that the new partition's bound is valid and does not overlap any
1403114022
* of existing partitions of the parent - note that it does not return on
@@ -14286,7 +14277,7 @@ ATExecDetachPartition(Relation rel, RangeVar *name)
1428614277

1428714278
/*
1428814279
* We must lock the default partition, because detaching this partition
14289-
* willchanging its partitionconstrant.
14280+
* willchange its partitionconstraint.
1429014281
*/
1429114282
defaultPartOid=
1429214283
get_default_oid_from_partdesc(RelationGetPartitionDesc(rel));
@@ -14329,19 +14320,17 @@ ATExecDetachPartition(Relation rel, RangeVar *name)
1432914320
if (OidIsValid(defaultPartOid))
1433014321
{
1433114322
/*
14332-
* If the detach relation is the default partition itself, invalidate
14333-
* its entry in pg_partitioned_table.
14323+
* If the relation being detached is the default partition itself,
14324+
* remove it from the parent's pg_partitioned_table entry.
14325+
*
14326+
* If not, we must invalidate default partition's relcache entry, as
14327+
* in StorePartitionBound: its partition constraint depends on every
14328+
* other partition's partition constraint.
1433414329
*/
1433514330
if (RelationGetRelid(partRel)==defaultPartOid)
1433614331
update_default_partition_oid(RelationGetRelid(rel),InvalidOid);
1433714332
else
14338-
{
14339-
/*
14340-
* We must invalidate default partition's relcache, for the same
14341-
* reasons explained in StorePartitionBound().
14342-
*/
1434314333
CacheInvalidateRelcacheByRelid(defaultPartOid);
14344-
}
1434514334
}
1434614335

1434714336
/* detach indexes too */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp