Re: Missing CFI in iterate_word_similarity()

From: Daniel Gustafsson <daniel(at)yesql(dot)se>
To: Robins Tharakan <tharakan(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Missing CFI in iterate_word_similarity()
Date: 2022-09-02 12:26:50
Message-ID: 9732D8A2-EABD-4F5B-8BA0-A97DA4AB51A7@yesql.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On 2 Aug 2022, at 04:41, Robins Tharakan <tharakan(at)gmail(dot)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 Content-Type Size
v2-0002-Update-out-of-date-comments-in-pg_trgm.patch application/octet-stream 1.5 KB
v2-0001-Check-for-interrupts-in-pg_trgm-word-similarity.patch application/octet-stream 1.2 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ranier Vilela 2022-09-02 12:36:50 Re: Fix possible bogus array out of bonds (src/backend/access/brin/brin_minmax_multi.c)
Previous Message Richard Guo 2022-09-02 12:15:46 Re: make additional use of optimized linear search routines