Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cykLy-0001Ar-Jm for pgsql-bugs@arkaria.postgresql.org; Thu, 13 Apr 2017 19:24:26 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cykLy-0000qw-6r for pgsql-bugs@arkaria.postgresql.org; Thu, 13 Apr 2017 19:24:26 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cykLx-0000mn-6G for pgsql-bugs@postgresql.org; Thu, 13 Apr 2017 19:24:25 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cykLu-0006Pd-VP for pgsql-bugs@postgresql.org; Thu, 13 Apr 2017 19:24:23 +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 v3DJOL5q021077; Thu, 13 Apr 2017 15:24:21 -0400 From: Tom Lane To: jeff.janes@gmail.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #14623: pg_trgm doesn't correctly process some regexp with negative lookahead In-reply-to: <20170413180503.25948.94871@wrigleys.postgresql.org> References: <20170413180503.25948.94871@wrigleys.postgresql.org> Comments: In-reply-to jeff.janes@gmail.com message dated "Thu, 13 Apr 2017 18:05:03 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <21075.1492111461.1@sss.pgh.pa.us> Date: Thu, 13 Apr 2017 15:24:21 -0400 Message-ID: <21076.1492111461@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org jeff.janes@gmail.com writes: > This simplified case is easy to reproduce back to at least 9.4, and is still > present in 10dev HEAD. Matches are missed when using the trgm index, but > not when doing the full table scan. > select * from foobar where x ~ 'eldrazi (?!scion)'; -- returns 0 rows > The trigrams seem to be extracted correctly, but the graph stuffed into > extra_data is not correct. Looking at /tmp/packed.dot, there are no arrays > pointing to the successful termination state s1. Instead, I get lead to a > dead-end state s7. Hm. I think what is happening here is that regexport.c is being too simplistic by ignoring LACON arcs. Because it does so, there's actually no path in the exported search NFA that can reach the success state, which explains your observation of the lack of such a path in /tmp/packed.dot. It's not entirely unreasonable for pg_trgm to be assuming that such a path must exist. What regexport.c should be doing is assuming that every LACON constraint succeeds, hence treating such an arc as a traversable but zero-input-consuming arc. Since there's no notion of zero input consumption in the exported representation, we're going to need some logic in regexport.c to convert that (by traversing to the arc target state and emitting its output arcs, possibly recursively). > If I change the regexp to 'eldrazi (?!s)', then bug goes away, and > /tmp/packed.dot shows the correct graph pointing to s1. That seems to be because processlacons will simplify a single-character LACON into a plain AHEAD/BEHIND constraint, which leads to an NFA that doesn't confuse the export logic. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs