Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c0tlh-0007gt-GQ for pgsql-hackers@arkaria.postgresql.org; Sun, 30 Oct 2016 17:19:37 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1c0tlg-0001dB-Rf for pgsql-hackers@arkaria.postgresql.org; Sun, 30 Oct 2016 17:19:36 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1c0tlg-0001d4-4I for pgsql-hackers@postgresql.org; Sun, 30 Oct 2016 17:19:36 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1c0tld-00079m-AQ for pgsql-hackers@postgresql.org; Sun, 30 Oct 2016 17:19:35 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u9UHJQnb018953; Sun, 30 Oct 2016 13:19:26 -0400 From: Tom Lane To: Andreas Seltenreich cc: pgsql-hackers@postgresql.org Subject: Re: [sqlsmith] Missing CHECK_FOR_INTERRUPTS in tsquery_rewrite In-reply-to: <8760oasf2y.fsf@credativ.de> References: <8760oasf2y.fsf@credativ.de> Comments: In-reply-to Andreas Seltenreich message dated "Sun, 30 Oct 2016 04:14:45 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <18951.1477847966.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 30 Oct 2016 13:19:26 -0400 Message-ID: <18952.1477847966@sss.pgh.pa.us> X-Pg-Spam-Score: -3.4 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Andreas Seltenreich 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 --=20 Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers