diff --git a/src/backend/catalog/pg_inherits.c b/src/backend/catalog/pg_inherits.c index f810e5de0d..eb5377e7c0 100644 --- a/src/backend/catalog/pg_inherits.c +++ b/src/backend/catalog/pg_inherits.c @@ -60,7 +60,7 @@ typedef struct SeenRelsEntry List * find_inheritance_children(Oid parentrelId, LOCKMODE lockmode) { - return find_inheritance_children_extended(parentrelId, true, + return find_inheritance_children_extended(parentrelId, ActiveSnapshotSet() ? GetActiveSnapshot() : NULL, lockmode, NULL, NULL); @@ -75,7 +75,7 @@ find_inheritance_children(Oid parentrelId, LOCKMODE lockmode) * If a partition's pg_inherits row is marked "detach pending", * *detached_exist (if not null) is set true. * - * If omit_detached is true and the caller passed 'omit_detached_snapshot', + * If the caller passed 'omit_detached_snapshot', * the partition whose pg_inherits tuple marks it as "detach pending" is * omitted from the output list if the tuple is visible to that snapshot. * That is, such a partition is omitted from the output list depending on @@ -84,7 +84,7 @@ find_inheritance_children(Oid parentrelId, LOCKMODE lockmode) * NULL) is set to the xmin of that pg_inherits tuple. */ List * -find_inheritance_children_extended(Oid parentrelId, bool omit_detached, +find_inheritance_children_extended(Oid parentrelId, Snapshot omit_detached_snapshot, LOCKMODE lockmode, bool *detached_exist, TransactionId *detached_xmin) @@ -146,7 +146,7 @@ find_inheritance_children_extended(Oid parentrelId, bool omit_detached, if (detached_exist) *detached_exist = true; - if (omit_detached && omit_detached_snapshot) + if (omit_detached_snapshot) { TransactionId xmin; diff --git a/src/backend/partitioning/partdesc.c b/src/backend/partitioning/partdesc.c index 863b04c17d..23f1334dbc 100644 --- a/src/backend/partitioning/partdesc.c +++ b/src/backend/partitioning/partdesc.c @@ -48,7 +48,6 @@ typedef struct PartitionDirectoryEntry } PartitionDirectoryEntry; static PartitionDesc RelationBuildPartitionDesc(Relation rel, - bool omit_detached, Snapshot omit_detached_snapshot); @@ -76,8 +75,7 @@ static PartitionDesc RelationBuildPartitionDesc(Relation rel, * that the data doesn't become stale. */ PartitionDesc -RelationGetPartitionDescExt(Relation rel, bool omit_detached, - Snapshot omit_detached_snapshot) +RelationGetPartitionDescExt(Relation rel, Snapshot omit_detached_snapshot) { Assert(rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE); @@ -91,7 +89,7 @@ RelationGetPartitionDescExt(Relation rel, bool omit_detached, * so we we can used the cached descriptor in that case too. */ if (likely(rel->rd_partdesc && - (!rel->rd_partdesc->detached_exist || !omit_detached || + (!rel->rd_partdesc->detached_exist || omit_detached_snapshot == NULL))) return rel->rd_partdesc; @@ -106,9 +104,7 @@ RelationGetPartitionDescExt(Relation rel, bool omit_detached, * have been passed when rd_partdesc_nodetached was built, then we can * reuse it. Otherwise we must build one from scratch. */ - if (omit_detached && - rel->rd_partdesc_nodetached && - omit_detached_snapshot) + if (rel->rd_partdesc_nodetached && omit_detached_snapshot) { Assert(TransactionIdIsValid(rel->rd_partdesc_nodetached_xmin)); @@ -117,8 +113,7 @@ RelationGetPartitionDescExt(Relation rel, bool omit_detached, return rel->rd_partdesc_nodetached; } - return RelationBuildPartitionDesc(rel, omit_detached, - omit_detached_snapshot); + return RelationBuildPartitionDesc(rel, omit_detached_snapshot); } /* @@ -129,9 +124,11 @@ RelationGetPartitionDescExt(Relation rel, bool omit_detached, PartitionDesc RelationGetPartitionDesc(Relation rel, bool omit_detached) { - return RelationGetPartitionDescExt(rel, omit_detached, - ActiveSnapshotSet() ? - GetActiveSnapshot() : NULL); + Snapshot snapshot = NULL; + + if (omit_detached && ActiveSnapshotSet()) + snapshot = GetActiveSnapshot(); + return RelationGetPartitionDescExt(rel, snapshot); } /* @@ -156,7 +153,7 @@ RelationGetPartitionDesc(Relation rel, bool omit_detached) * for them. */ static PartitionDesc -RelationBuildPartitionDesc(Relation rel, bool omit_detached, +RelationBuildPartitionDesc(Relation rel, Snapshot omit_detached_snapshot) { PartitionDesc partdesc; @@ -185,7 +182,6 @@ RelationBuildPartitionDesc(Relation rel, bool omit_detached, detached_exist = false; detached_xmin = InvalidTransactionId; inhoids = find_inheritance_children_extended(RelationGetRelid(rel), - omit_detached, omit_detached_snapshot, NoLock, &detached_exist, @@ -353,7 +349,7 @@ RelationBuildPartitionDesc(Relation rel, bool omit_detached, * have set detached_xmin in that case), we consider there to be no * "omittable" detached partitions. */ - is_omit = omit_detached && detached_exist && omit_detached_snapshot && + is_omit = detached_exist && omit_detached_snapshot && TransactionIdIsValid(detached_xmin); /* @@ -467,8 +463,7 @@ PartitionDirectoryLookup(PartitionDirectory pdir, Relation rel, Assert(omit_detached_snapshot == NULL); if (pdir->omit_detached && ActiveSnapshotSet()) omit_detached_snapshot = GetActiveSnapshot(); - pde->pd = RelationGetPartitionDescExt(rel, pdir->omit_detached, - omit_detached_snapshot); + pde->pd = RelationGetPartitionDescExt(rel, omit_detached_snapshot); Assert(pde->pd != NULL); } return pde->pd; diff --git a/src/include/catalog/pg_inherits.h b/src/include/catalog/pg_inherits.h index 67f148f2bf..14515d74d1 100644 --- a/src/include/catalog/pg_inherits.h +++ b/src/include/catalog/pg_inherits.h @@ -50,7 +50,7 @@ DECLARE_INDEX(pg_inherits_parent_index, 2187, InheritsParentIndexId, on pg_inher extern List *find_inheritance_children(Oid parentrelId, LOCKMODE lockmode); -extern List *find_inheritance_children_extended(Oid parentrelId, bool omit_detached, +extern List *find_inheritance_children_extended(Oid parentrelId, Snapshot omit_detached_snapshot, LOCKMODE lockmode, bool *detached_exist, TransactionId *detached_xmin); diff --git a/src/include/partitioning/partdesc.h b/src/include/partitioning/partdesc.h index f42d137fc1..f3d701d5b4 100644 --- a/src/include/partitioning/partdesc.h +++ b/src/include/partitioning/partdesc.h @@ -65,7 +65,7 @@ typedef struct PartitionDescData extern PartitionDesc RelationGetPartitionDesc(Relation rel, bool omit_detached); -extern PartitionDesc RelationGetPartitionDescExt(Relation rel, bool omit_detached, +extern PartitionDesc RelationGetPartitionDescExt(Relation rel, Snapshot omit_detached_snapshot); extern PartitionDirectory CreatePartitionDirectory(MemoryContext mcxt, bool omit_detached);