Check for interrupts in pg_trgm word similarity
authorDaniel Gustafsson <[email protected]>
Mon, 5 Sep 2022 09:10:57 +0000 (11:10 +0200)
committerDaniel Gustafsson <[email protected]>
Mon, 5 Sep 2022 09:10:57 +0000 (11:10 +0200)
Calculating similarity between large strings can be timesconsuming
and overrun configured statement timeouts. Check for interrupts in
the main loop to ensure query cancellation can be performed.

Author: Robins Tharakan <[email protected]>
Reviewed-by: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/CAEP4nAxvmfc_XWTz73bqXRhgjONi=1HaX4_NhsopA3L6UvnN1g@mail.gmail.com

contrib/pg_trgm/trgm_op.c

index 49b3609de93b4fbb88557891ad49e2b58a8ed334..c140fcdbbe8ba5e7fb22dcb9278d30d7a8e8e802 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "catalog/pg_type.h"
 #include "lib/qunique.h"
+#include "miscadmin.h"
 #include "trgm.h"
 #include "tsearch/ts_locale.h"
 #include "utils/lsyscache.h"
@@ -492,8 +493,12 @@ iterate_word_similarity(int *trg2indexes,
 
        for (i = 0; i < len2; i++)
        {
+               int                     trgindex;
+
+               CHECK_FOR_INTERRUPTS();
+
                /* Get index of next trigram */
-               int                     trgindex = trg2indexes[i];
+               trgindex = trg2indexes[i];
 
                /* Update last position of this trigram */
                if (lower >= 0 || found[trgindex])