Re: Using regexp from table has unpredictable poor performance

From: Justin Pryzby <pryzby(at)telsasoft(dot)com>
To: Jack Christensen <jack(at)jncsoftware(dot)com>
Cc: pgsql-performance(at)lists(dot)postgresql(dot)org
Subject: Re: Using regexp from table has unpredictable poor performance
Date: 2021-08-25 21:05:00
Message-ID: 20210825210500.GF10479@telsasoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Wed, Aug 25, 2021 at 11:47:43AM -0500, Jack Christensen wrote:
> I have items that need to be categorized by user defined matching rules.
> Trusted users can create rules that include regular expressions. I've
> reduced the problem to this example.

> I use the following query to find matches:
>
> select r.id, i.id
> from items i
> join matching_rules r on i.name ~ r.name_matches;
>
> When there are few rules the query runs quickly. But as the number of rules
> increases the runtime often increases at a greater than linear rate.

Maybe it's because the REs are cached by RE_compile_and_cache(), but if you
loop over the REs in the inner loop, then the caching is ineffecive.

Maybe you can force it to join with REs on the outer loop by writing it as:
| rules LEFT JOIN items WHERE rules.id IS NOT NULL,
..to improve performance, or at least test that theory.

--
Justin

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Jack Christensen 2021-08-25 21:21:55 Re: Using regexp from table has unpredictable poor performance
Previous Message Jack Christensen 2021-08-25 16:47:43 Using regexp from table has unpredictable poor performance