Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3fe773b

Browse files
committed
Track detached partitions more accurately in partdescs
In d6b8d29 I (Álvaro) was sloppy about recording whether a partition descripor does or does not include detached partitions, when the snapshot checking does not see the pg_inherits row marked detached. In that case no partition was omitted, yet in the relcache entry we were saving the partdesc as omitting partitions. Flip that (so we save it as a partdesc not omitting partitions, which indeed it doesn't), which hopefully makes the code easier to reason about. Author: Amit Langote <amitlangote09@gmail.com> Discussion: https://postgr.es/m/CA+HiwqE7GxGU4VdzwZzfiz+Ont5SsopoFkgtrZGEdPqWRL+biA@mail.gmail.com
1 parent c38cadc commit 3fe773b

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/backend/partitioning/partdesc.c

+16-6
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ RelationGetPartitionDesc(Relation rel, bool omit_detached)
9696
*/
9797
if (omit_detached &&
9898
rel->rd_partdesc_nodetached &&
99-
TransactionIdIsValid(rel->rd_partdesc_nodetached_xmin) &&
10099
ActiveSnapshotSet())
101100
{
102101
Snapshot activesnap;
103102

103+
Assert(TransactionIdIsValid(rel->rd_partdesc_nodetached_xmin));
104104
activesnap = GetActiveSnapshot();
105105

106106
if (!XidInMVCCSnapshot(rel->rd_partdesc_nodetached_xmin, activesnap))
@@ -163,6 +163,7 @@ RelationBuildPartitionDesc(Relation rel, bool omit_detached)
163163
omit_detached, NoLock,
164164
&detached_exist,
165165
&detached_xmin);
166+
166167
nparts = list_length(inhoids);
167168

168169
/* Allocate working arrays for OIDs, leaf flags, and boundspecs. */
@@ -310,10 +311,17 @@ RelationBuildPartitionDesc(Relation rel, bool omit_detached)
310311
}
311312

312313
/*
313-
* Are we working with the partition that omits detached partitions, or
314-
* the one that includes them?
314+
* Are we working with the partdesc that omits the detached partition, or
315+
* the one that includes it?
316+
*
317+
* Note that if a partition was found by the catalog's scan to have been
318+
* detached, but the pg_inherit tuple saying so was not visible to the
319+
* active snapshot (find_inheritance_children_extended will not have set
320+
* detached_xmin in that case), we consider there to be no "omittable"
321+
* detached partitions.
315322
*/
316-
is_omit = omit_detached && detached_exist && ActiveSnapshotSet();
323+
is_omit = omit_detached && detached_exist && ActiveSnapshotSet() &&
324+
TransactionIdIsValid(detached_xmin);
317325

318326
/*
319327
* We have a fully valid partdesc. Reparent it so that it has the right
@@ -343,9 +351,11 @@ RelationBuildPartitionDesc(Relation rel, bool omit_detached)
343351
* For partdescs built excluding detached partitions, which we save
344352
* separately, we also record the pg_inherits.xmin of the detached
345353
* partition that was omitted; this informs a future potential user of
346-
* such a cached partdescs. (This might be InvalidXid; see comments
347-
* in struct RelationData).
354+
* such a cached partdesc to only use it after cross-checking that the
355+
* xmin is indeed visible to the snapshot it is going to be working
356+
* with.
348357
*/
358+
Assert(TransactionIdIsValid(detached_xmin));
349359
rel->rd_partdesc_nodetached_xmin = detached_xmin;
350360
}
351361
else

src/include/utils/rel.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,7 @@ typedef struct RelationData
138138
* rd_partdesc_nodetached. This informs a future user of that partdesc:
139139
* if this value is not in progress for the active snapshot, then the
140140
* partdesc can be used, otherwise they have to build a new one. (This
141-
* matches what find_inheritance_children_extended would do). In the rare
142-
* case where the pg_inherits tuple has been frozen, this will be
143-
* InvalidXid; behave as if the partdesc is unusable in that case.
141+
* matches what find_inheritance_children_extended would do).
144142
*/
145143
TransactionId rd_partdesc_nodetached_xmin;
146144

0 commit comments

Comments
 (0)