Re: Using regexp from table has unpredictable poor performance - Mailing list pgsql-performance

From Justin Pryzby
Subject Re: Using regexp from table has unpredictable poor performance
Date
Msg-id 20210825210500.GF10479@telsasoft.com
Whole thread Raw
In response to Using regexp from table has unpredictable poor performance  (Jack Christensen <jack@jncsoftware.com>)
Responses Re: Using regexp from table has unpredictable poor performance
List 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



pgsql-performance by date:

Previous
From: Jack Christensen
Date:
Subject: Using regexp from table has unpredictable poor performance
Next
From: Jack Christensen
Date:
Subject: Re: Using regexp from table has unpredictable poor performance