On Tue, Oct 13, 2026 at 11:32 AM Tianyi Gao <[email protected]> wrote: > > Hi hackers, > > This is about the TODO item "Better regexp cache management" [1]. > > So 0001 is meant for commit on its own, and I'd like to get agreement > on the next step before writing it. > > [1] https://wiki.postgresql.org/wiki/Todo#Cache_Usage > [2] https://postgr.es/m/[email protected] > Hi.
In https://wiki.postgresql.org/wiki/Todo we also have an entry {Consider a special data type for regular expressions} which directs to https://www.postgresql.org/message-id/3786.1188497432%40sss.pgh.pa.us Currently, compiled regular expressions are cached in RegexpCacheMemoryContext, which is session-level. Another possible direction is to cache them in query-level instead. Nearly all callers of RE_compile_and_cache() can be reached from a function that has an fcinfo: the regex operators, the regexp_* functions, textregexsubstr() and textregexreplace(). We can cache the compiled regex in fcinfo->flinfo->fn_extra, the same way array_sort_internal() caches its ArraySortCachedInfo. The compiled regex would then be freed automatically when the query ends. With that, RegexpCacheMemoryContext and the backend-global cache could be removed entirely. This is just an alternative way to look at it. I haven’t tried implementing it myself. but it looks doable.) -- jian https://www.enterprisedb.com/
