pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andreas Seltenreich <seltenreich@gmx.de>
Cc: pgsql-hackers@postgresql.org
Subject: Re: [sqlsmith] Missing CHECK_FOR_INTERRUPTS in tsquery_rewrite
Date: Sun, 30 Oct 2016 13:19:26 -0400
Message-ID: <18952.1477847966@sss.pgh.pa.us> (raw)
In-Reply-To: <8760oasf2y.fsf@credativ.de>
References: <8760oasf2y.fsf@credativ.de>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

Andreas Seltenreich <seltenreich@gmx.de> writes:
> 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.

A CHECK_FOR_INTERRUPTS is probably a good idea, but man is this code
stupid.  It seems to be checking for subset inclusion by forming every
possible subset of the test node and then checking for exact equality
to the target set.  Seems like we should be able to do better.

Also, I think this is outright *wrong* for phrase search --- dropping some
of the child nodes without any other adjustment isn't valid is it?

			regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



view thread (3+ messages)  latest in thread

Message-ID: <18952.1477847966@sss.pgh.pa.us>
Permalink:  ../18952.1477847966@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/18952.1477847966@sss.pgh.pa.us

 · 

reply

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: tgl@sss.pgh.pa.us, seltenreich@gmx.de
  Subject: Re: [sqlsmith] Missing CHECK_FOR_INTERRUPTS in tsquery_rewrite
  In-Reply-To: <18952.1477847966@sss.pgh.pa.us>
  References: <8760oasf2y.fsf@credativ.de> <18952.1477847966@sss.pgh.pa.us>

* 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