Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jJJ7B-00081h-2A for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Mar 2020 15:47:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jJJ79-0001Y4-Vb for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Mar 2020 15:47:43 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jJJ79-0001Xs-Om for pgsql-hackers@lists.postgresql.org; Tue, 31 Mar 2020 15:47:43 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jJJ77-0002L4-HM for pgsql-hackers@postgresql.org; Tue, 31 Mar 2020 15:47:42 +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 02VFlUao004903; Tue, 31 Mar 2020 11:47:31 -0400 From: Tom Lane To: Nikita Glukhov cc: Pgsql Hackers , =?UTF-8?Q?Filip_Rembia=c5=82kowski?= , Tomas Vondra , Alexander Korotkov , Oleg Bartunov , Thomas Munro , Teodor Sigaev Subject: Re: fix for BUG #3720: wrong results at using ltree In-reply-to: <6352.1585609100@sss.pgh.pa.us> References: <28639.1554565562@sss.pgh.pa.us> <5eedfd9e-2f14-a2df-3bd9-4c92eb0f08a5@postgrespro.ru> <20200124182915.zz7hzdkijzsb4ic4@development> <19375.1585438012@sss.pgh.pa.us> <15582.1585529626@sss.pgh.pa.us> <23304.1585591242@sss.pgh.pa.us> <943dc224-eb82-8abd-15c3-f4b516f89767@postgrespro.ru> <3007.1585605566@sss.pgh.pa.us> <3843.1585606362@sss.pgh.pa.us> <9247ddc2-d1e0-7d62-55a6-62a089e99a8a@postgrespro.ru> <5210.1585607748@sss.pgh.pa.us> <4c00219b-7094-e568-cc2c-6a52cf621701@postgrespro.ru> <6352.1585609100@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Mon, 30 Mar 2020 18:58:20 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4901.1585669650.1@sss.pgh.pa.us> Date: Tue, 31 Mar 2020 11:47:30 -0400 Message-ID: <4902.1585669650@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I wrote: > I've marked this RFC, and will push tomorrow unless somebody wants > to object to the loss of backwards compatibility. And done. I noticed in some final testing that it's possible to make this code take a long time by forcing it to backtrack a lot: regression=# SELECT (('1' || repeat('.1', 65534))::ltree) ~ '*.*.x'; ?column? ---------- f (1 row) Time: 54015.421 ms (00:54.015) so I threw in a CHECK_FOR_INTERRUPTS(). Maybe it'd be worth trying to optimize such cases, but I'm not sure that it'd ever matter for real-world cases with reasonable-size label strings. The old implementation seems to handle that particular case well, evidently because it more-or-less folds adjacent stars together. However, before anyone starts complaining about regressions, they should note that it's really easy to get the old code to fail via stack overflow: regression=# SELECT (('1' || repeat('.1', 65534))::ltree) ~ '*.!1.*'; ERROR: stack depth limit exceeded (That's as of five minutes ago, before that it dumped core.) So I don't feel bad about the tradeoff. At least now we have simple, visibly correct code that could serve as a starting point for optimization if anyone feels the need to. regards, tom lane