Add CHECK_FOR_INTERRUPTS() to the repeat() function
authorJoe Conway
Thu, 28 May 2020 17:16:56 +0000 (13:16 -0400)
committerJoe Conway
Thu, 28 May 2020 17:19:10 +0000 (13:19 -0400)
The repeat() function loops for potentially a long time without
ever checking for interrupts. This prevents, for example, a query
cancel from interrupting until the work is all done. Fix by
inserting a CHECK_FOR_INTERRUPTS() into the loop.

Backpatch to all supported versions.

Discussion: https://www.postgresql.org/message-id/flat/8692553c-7fe8-17d9-cbc1-7cddb758f4c6%40joeconway.com

src/backend/utils/adt/oracle_compat.c

index 0fdfee5825373b15c4e7972f99dabb0793662283..ecd8268b23b51282a4ba847bba6d1bef27fa54f4 100644 (file)
@@ -19,7 +19,7 @@
 #include "utils/builtins.h"
 #include "utils/formatting.h"
 #include "mb/pg_wchar.h"
-
+#include "miscadmin.h"
 
 static text *dotrim(const char *string, int stringlen,
                    const char *set, int setlen,
@@ -1062,6 +1062,7 @@ repeat(PG_FUNCTION_ARGS)
    {
        memcpy(cp, sp, slen);
        cp += slen;
+       CHECK_FOR_INTERRUPTS();
    }
 
    PG_RETURN_TEXT_P(result);