public inbox for [email protected]
help / color / mirror / Atom feedFrom: Tom Lane <[email protected]>
To: Michał Kłeczek <[email protected]>
Cc: PostgreSQL Hackers <[email protected]>
Subject: Re: Is it safe to cache data by GiST consistent function
Date: Wed, 03 Apr 2024 13:02:13 -0400
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
<[email protected]>
<[email protected]>
=?utf-8?Q?Micha=C5=82_K=C5=82eczek?= <[email protected]> writes:
> On 3 Apr 2024, at 16:27, Tom Lane <[email protected]> wrote:
>> AFAIK it works. I don't see any of the in-core ones doing so,
>> but at least range_gist_consistent and multirange_gist_consistent
>> are missing a bet by repeating their cache search every time.
> pg_trgm consistent caches tigrams but it has some logic to make sure cached values are recalculated:
> cache = (gtrgm_consistent_cache *) fcinfo->flinfo->fn_extra;
> if (cache == NULL ||
> cache->strategy != strategy ||
> VARSIZE(cache->query) != querysize ||
> memcmp((char *) cache->query, (char *) query, querysize) != 0)
> What I don’t understand is if it is necessary or it is enough to check fn_extra==NULL.
Ah, I didn't think to search contrib. Yes, you need to validate the
cache entry. In this example, a rescan could insert a new query
value. In general, an opclass support function could get called using
a pretty long-lived FunctionCallInfo (e.g. one in the index's relcache
entry), so it's unwise to assume that cached data is relevant to the
current call without checking.
regards, tom lane
view thread (4+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: Is it safe to cache data by GiST consistent function
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox