summaryrefslogtreecommitdiff
path: root/contrib/pg_trgm
diff options
context:
space:
mode:
authorDaniel Gustafsson <dgustafsson@postgresql.org>2022-09-05 11:10:57 +0200
committerDaniel Gustafsson <dgustafsson@postgresql.org>2022-09-05 11:10:57 +0200
commitae4fc52ae24785f51e3dc5a4c7e5b4d206356bdc (patch)
treef6cdfaa115f45e31693559b2994d55675e92df72 /contrib/pg_trgm
parent519be095f2bf7150fe7a36c4f5cd0c1825126427 (diff)
downloadpostgresql-ae4fc52ae24785f51e3dc5a4c7e5b4d206356bdc.tar.gz
Check for interrupts in pg_trgm word similarity
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 <tharakan@gmail.com> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/CAEP4nAxvmfc_XWTz73bqXRhgjONi=1HaX4_NhsopA3L6UvnN1g@mail.gmail.com
Diffstat (limited to 'contrib/pg_trgm')
-rw-r--r--contrib/pg_trgm/trgm_op.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/contrib/pg_trgm/trgm_op.c b/contrib/pg_trgm/trgm_op.c
index 49b3609de9..c140fcdbbe 100644
--- a/contrib/pg_trgm/trgm_op.c
+++ b/contrib/pg_trgm/trgm_op.c
@@ -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])