> Hi hackers,
> 
> I found a case where Memoize rescans its inner plan even though the complete 
> result for the requested key is already cached.
> 
> When the cache exceeds its memory limit, Memoize removes older entries. 
> Removing an entry from the hash table can move other entries to different 
> buckets, including the entry currently being filled.
> 
> The code that stores a tuple accounts for this movement and updates 
> node->entry. However, its caller then marks the entry as complete using the 
> old local pointer:
> 
> ```
> entry->complete = node->singlerow;
> ```
> 
> This writes to the old bucket and leaves the actual entry marked incomplete. 
> When the same key is requested again, Memoize discards the cached tuples and 
> rescans the inner plan.

Good catch! Your analysis is right for me.

> Using the updated pointer fixes this:
> 
> - entry->complete = node->singlerow;
> + node->entry->complete = node->singlerow;
> 
> Thoughts?

Patch LGTM and we need backpatch to all supported version.

--
Regards,
ChangAo Chen

Reply via email to