Re: Use a hash table for the regexp cache

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Tianyi Gao <gtydoit(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Use a hash table for the regexp cache
Date: 2026-11-01 13:55:57
Message-ID: CACJufxHL2KBstA=8D_KXRAXiJDYjNVqo_kkhE4kPHtaUSqQh_w@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Oct 13, 2026 at 11:32 AM Tianyi Gao <gtydoit(at)gmail(dot)com> 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/8584.1213826927@sss.pgh.pa.us
>
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/

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jim Jones 2026-11-01 14:27:00 Re: PoC: Simplify recovery after dropping a table by LOGGING the restore LSN
Previous Message Alexander Lakhin 2026-11-01 13:00:00 007_pre_auth.pl fails if injection_points_wakeup hits unintended process