Skip to content

Commit 41d87d8

Browse files
committed
lock parent pefore first access to its structure, don't forget to unlock children
1 parent aa162a1 commit 41d87d8

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

src/relation_info.c

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ refresh_pathman_relation_info(Oid relid,
9494
* NOTE: Trick clang analyzer (first access without NULL pointer check).
9595
* Access to field 'valid' results in a dereference of a null pointer.
9696
*/
97-
prel->cmp_proc = InvalidOid;
97+
prel->cmp_proc = InvalidOid;
9898

9999
/* Clear outdated resources */
100100
if (found_entry && PrelIsValid(prel))
@@ -104,6 +104,23 @@ refresh_pathman_relation_info(Oid relid,
104104
FreeRangesArray(prel);
105105
}
106106

107+
/* Try locking parent, exit fast if 'allow_incomplete' */
108+
if (allow_incomplete)
109+
{
110+
if (!ConditionalLockRelationOid(relid, lockmode))
111+
return NULL; /* leave an invalid entry */
112+
}
113+
else LockRelationOid(relid, lockmode);
114+
115+
/* Check if parent exists */
116+
if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(relid)))
117+
{
118+
/* Nope, it doesn't, remove this entry and exit */
119+
UnlockRelationOid(relid, lockmode);
120+
remove_pathman_relation_info(relid);
121+
return NULL; /* exit */
122+
}
123+
107124
/* First we assume that this entry is invalid */
108125
prel->valid = false;
109126

@@ -137,23 +154,6 @@ refresh_pathman_relation_info(Oid relid,
137154
prel->cmp_proc = typcache->cmp_proc;
138155
prel->hash_proc = typcache->hash_proc;
139156

140-
/* Try locking parent, exit fast if 'allow_incomplete' */
141-
if (allow_incomplete)
142-
{
143-
if (!ConditionalLockRelationOid(relid, lockmode))
144-
return NULL; /* leave an invalid entry */
145-
}
146-
else LockRelationOid(relid, lockmode);
147-
148-
/* Check if parent exists */
149-
if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(relid)))
150-
{
151-
/* Nope, it doesn't, remove this entry and exit */
152-
UnlockRelationOid(relid, lockmode);
153-
remove_pathman_relation_info(relid);
154-
return NULL; /* exit */
155-
}
156-
157157
/* Try searching for children (don't wait if we can't lock) */
158158
switch (find_inheritance_children_array(relid, lockmode,
159159
allow_incomplete,
@@ -189,10 +189,16 @@ refresh_pathman_relation_info(Oid relid,
189189
*/
190190
fill_prel_with_partitions(prel_children, prel_children_count, prel);
191191

192-
/* Add "partition+parent" pair to cache */
192+
/* Peform some actions for each child */
193193
for (i = 0; i < prel_children_count; i++)
194+
{
195+
/* Add "partition+parent" pair to cache */
194196
cache_parent_of_partition(prel_children[i], relid);
195197

198+
/* Now it's time to unlock this child */
199+
UnlockRelationOid(prel_children[i], lockmode);
200+
}
201+
196202
pfree(prel_children);
197203

198204
/* Read additional parameters ('enable_parent' and 'auto' at the moment) */

0 commit comments

Comments
 (0)