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

Commit 8f4a1ab

Browse files
committed
Fix bug in the new ResourceOwner implementation.
When the hash table is in use, ResoureOwnerSort() moves any elements from the small fixed-size array to the hash table, and sorts it. When the hash table is not in use, it sorts the elements in the small fixed-size array directly. However, ResourceOwnerSort() and ResourceOwnerReleaseAll() had different idea on when the hash table is in use: ResourceOwnerSort() checked owner->nhash != 0, and ResourceOwnerReleaseAll() checked owner->hash != NULL. If the hash table was allocated but was currently empty, you hit an assertion failure. Reported-by: Alexander Lakhin <exclusion@gmail.com> Discussion: https://www.postgresql.org/message-id/be58d565-9e95-d417-4e47-f6bd408dea4b@gmail.com
1 parent 322f55b commit 8f4a1ab

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/backend/utils/resowner/resowner.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,13 @@ ResourceOwnerReleaseAll(ResourceOwner owner, ResourceReleasePhase phase,
349349
ResourceElem *items;
350350
uint32 nitems;
351351

352-
/* ResourceOwnerSort must've been called already */
352+
/*
353+
* ResourceOwnerSort must've been called already. All the resources are
354+
* either in the array or the hash.
355+
*/
353356
Assert(owner->releasing);
354357
Assert(owner->sorted);
355-
if (!owner->hash)
358+
if (owner->nhash == 0)
356359
{
357360
items = owner->arr;
358361
nitems = owner->narr;
@@ -393,7 +396,7 @@ ResourceOwnerReleaseAll(ResourceOwner owner, ResourceReleasePhase phase,
393396
kind->ReleaseResource(value);
394397
nitems--;
395398
}
396-
if (!owner->hash)
399+
if (owner->nhash == 0)
397400
owner->narr = nitems;
398401
else
399402
owner->nhash = nitems;

0 commit comments

Comments
 (0)