Re: Missing CFI in iterate_word_similarity() - Mailing list pgsql-hackers

From Daniel Gustafsson
Subject Re: Missing CFI in iterate_word_similarity()
Date
Msg-id 9732D8A2-EABD-4F5B-8BA0-A97DA4AB51A7@yesql.se
Whole thread Raw
In response to Missing CFI in iterate_word_similarity()  (Robins Tharakan <tharakan@gmail.com>)
Responses Re: Missing CFI in iterate_word_similarity()
List pgsql-hackers
> On 2 Aug 2022, at 04:41, Robins Tharakan <tharakan@gmail.com> wrote:

> For long strings, iterate_word_similarity() can run into long-running
> tight-loops without honouring interrupts or statement_timeouts.

> Adding CHECK_FOR_INTERRUPTS() ensures that such queries respond to
> statement_timeout & Ctrl-C signals. With the patch applied, the
> above query will interrupt more quickly:

Makes sense.  While this might be a bit of a theoretical issue given the
lengths required, the fix is still sane and any such query should honor
statement timeouts (especially in a trusted extension).

> Please find the patch attached. The patch does not show any performance
> regressions when run against the above use-case.

I wasn't able to find one either.

+       CHECK_FOR_INTERRUPTS();
+
        /* Get index of next trigram */
        int         trgindex = trg2indexes[i];

Placing code before declarations will generate a compiler warning, so the check
must go after trgindex is declared.  I've fixed that in the attached to get the
cfbot green.  Marking this ready for committer in the meantime.

Looking at this I also noticed that commit be8a7a68662 changed the check_only
param to instead use a flag value but didn't update all comments.  0002 fixes
that while in there.

--
Daniel Gustafsson        https://vmware.com/


Attachment

pgsql-hackers by date:

Previous
From: Richard Guo
Date:
Subject: Re: make additional use of optimized linear search routines
Next
From: Ranier Vilela
Date:
Subject: Re: Fix possible bogus array out of bonds (src/backend/access/brin/brin_minmax_multi.c)