Subject: Is it safe to cache data by GiST consistent function

From: Michał Kłeczek <[email-masked]>
Date: Wed, 3 Apr 2024 08:43:17 +0200

Hello,

When implementing a GiST consistent function I found the need to cache pre-processed query across invocations.
I am not sure if it is safe to do (or I need to perform some steps to make sure cached info is not leaked between rescans).

The comment in gistrescan says:

		/*
		 * If this isn't the first time through, preserve the fn_extra
		 * pointers, so that if the consistentFns are using them to cache
		 * data, that data is not leaked across a rescan.
		 */

which seems to me self-contradictory as fn_extra is preserved between rescans (so leaks are indeed possible).

Am I missing something?

Thanks,
Michal