From: Andreas Seltenreich <seltenreich@gmx.de>
To: pgsql-hackers@postgresql.org
Subject: [sqlsmith] Missing CHECK_FOR_INTERRUPTS in tsquery_rewrite
Date: Sun, 30 Oct 2016 04:14:45 +0100
Message-ID: <8760oasf2y.fsf@credativ.de> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
Hi,
testing with sqlsmith yielded an uncancellable backend hogging CPU time.
Gdb showed it was busy in findeq() of tsquery_rewrite.c. This function
appears to have exponential complexity wrt. the size of the involved
tsqueries. The following query runs for 12s on my machine with no way
to cancel it and incrementing the length of the first argument by 1
doubles this time.
select ts_rewrite(
(select string_agg(i::text, '&')::tsquery from generate_series(1,32) g(i)),
(select string_agg(i::text, '&')::tsquery from generate_series(1,19) g(i)),
'foo');
The attached patch adds a CHECK_FOR_INTERRUPTS to make it cancellable.
regards,
Andreas
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackersAttachments:0001-Add-CHECK_FOR_INTERRUPTS-in-tsquery_rewrite-loop.patch (text/x-diff, 999B) download
From d9910a96c9bd73c16e29ecaa0577945d5e1c091c Mon Sep 17 00:00:00 2001
From: Andreas Seltenreich <seltenreich@gmx.de>
Date: Sun, 30 Oct 2016 03:25:55 +0100
Subject: [PATCH] Add CHECK_FOR_INTERRUPTS in tsquery_rewrite loop.
The loop in findeq() appears to have exponential complexity and
runtime becomes excessive for more than about 30 tokens in the
tsvectors. Add a CHECK_FOR_INTERRUPTS to make it cancellable.
---
src/backend/utils/adt/tsquery_rewrite.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/backend/utils/adt/tsquery_rewrite.c b/src/backend/utils/adt/tsquery_rewrite.cindex 28f328d..ef6444f 100644--- a/src/backend/utils/adt/tsquery_rewrite.c+++ b/src/backend/utils/adt/tsquery_rewrite.c@@ -95,6 +95,10 @@ findeq(QTNode *node, QTNode *ex, QTNode *subs, bool *isfind)
do
{
+ /* This loop is rather heavyweight, it better be+ * cancellable. */+ CHECK_FOR_INTERRUPTS();+
tnode->sign = 0;
for (i = 0; i < ex->nchild; i++)
{
--
2.9.3
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: seltenreich@gmx.de
Subject: Re: [sqlsmith] Missing CHECK_FOR_INTERRUPTS in tsquery_rewrite
In-Reply-To: <8760oasf2y.fsf@credativ.de>
References: <8760oasf2y.fsf@credativ.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox