Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fe6tg-00068I-GY for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Jul 2018 22:50:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fe6tf-0006ax-05 for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Jul 2018 22:50:43 +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.89) (envelope-from ) id 1fe6te-0006ap-PT for pgsql-hackers@lists.postgresql.org; Fri, 13 Jul 2018 22:50:42 +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.89) (envelope-from ) id 1fe6tc-0003VE-2M for pgsql-hackers@postgresql.org; Fri, 13 Jul 2018 22:50: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 w6DMoXhw029352; Fri, 13 Jul 2018 18:50:34 -0400 From: Tom Lane To: Pierre Ducroquet cc: pgsql-hackers@postgresql.org, Oleg Bartunov , Teodor Sigaev Subject: Re: function lca('{}'::ltree[]) caused DB Instance crash In-reply-to: <993.1531492016@sss.pgh.pa.us> References: <5b0d8e4f-f2a3-1305-d612-e00e35a7be66@qunar.com> <4285558.KOck4HGOto@peanuts2> <993.1531492016@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Fri, 13 Jul 2018 10:26:56 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <29350.1531522233.1@sss.pgh.pa.us> Date: Fri, 13 Jul 2018 18:50:33 -0400 Message-ID: <29351.1531522233@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I wrote: > However, I don't understand why this code is returning NULL, rather than > a zero-length ltree, in the case that there's no common prefix. That > doesn't seem consistent to me. After looking more closely, I see that what lca() returns is the longest common *ancestor* of the input paths, not the longest common *prefix* ... at least, by my understanding of what a prefix is. If the longest prefix is empty, then there's no common ancestor, so returning null in that case isn't so insane after all. However, the documentation seems very misleading on this point. I changed it around along with pushing the crash fix. I wonder whether there isn't a need for an lcp() that would return the common prefix as that's usually understood. regards, tom lane