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 1jimkY-0006xK-QU for pgsql-bugs@arkaria.postgresql.org; Tue, 09 Jun 2020 22:29:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jimkX-0004YS-L3 for pgsql-bugs@arkaria.postgresql.org; Tue, 09 Jun 2020 22:29:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jimkX-0004YG-3v for pgsql-bugs@lists.postgresql.org; Tue, 09 Jun 2020 22:29:41 +0000 Received: from mail.dalibo.com ([212.85.157.172]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jimkT-0000Fb-Kh for pgsql-bugs@lists.postgresql.org; Tue, 09 Jun 2020 22:29:40 +0000 Received: from firost (larco.ioguix.net [82.66.0.6]) by mail.dalibo.com (Postfix) with ESMTPSA id A3A2822F6D; Wed, 10 Jun 2020 00:29:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dalibo.com; s=a; t=1591741774; bh=KWcDyERWia0MABS/klJkN+jpJkAxeYsLqxornlpKmIY=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=PZY3UmkZmNqIrCKUrv9906K7yVLoyayIs6zH52XF+RIzjP7D8W0kSggQnRVlF8Q1p 2YSTvbMGDArZDhs99DWH9/JWSnHGTrZZqxoIu3dNh7vATLXThz+pZ7wjnc1Qh3jbeQ BREuyAx8bw8DiE1FeC+ZlsUaSfed2QFTyDcS515Y= Date: Wed, 10 Jun 2020 00:29:33 +0200 From: Jehan-Guillaume de Rorthais To: Thomas Munro Cc: Peter Geoghegan , =?UTF-8?B?0KDQvtC80LDQvSDQm9C40YLQvtCy?= =?UTF-8?B?0YfQtdC90LrQvg==?= , PostgreSQL mailing lists Subject: Re: BUG #15285: Query used index over field with ICU collation in some cases wrongly return 0 rows Message-ID: <20200610002933.6a6d482b@firost> In-Reply-To: References: <153201618542.1404.3611626898935613264@wrigleys.postgresql.org> Organization: Dalibo MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hello, I didn't find any other discussion related to this bug, neither on pgsql-bugs or pgsql-hackers. Hopefully, this is the best thread to give some update. On Sat, 21 Jul 2018 13:39:12 +1200 Thomas Munro wrote: > On Fri, Jul 20, 2018 at 11:26 AM, Peter Geoghegan wrote: > > On Thu, Jul 19, 2018 at 9:44 AM, Peter Geoghegan wrote: > >> It appears that the main support function 1 routine disagrees with the > >> CREATE INDEX sort order, which is wrong. I'll try to isolate the > >> problem a bit further. > > > > As far as I can tell, this is an ICU bug. ucol_strcollUTF8() is buggy > > with this digitslast collation, which ucol_nextSortKeyPart() fails to > > be bug-compatible with. Other similar customized collations (e.g. > > 'en-u-kf-upper') work fine. (Ugh, that's familiar in an unpleasant > > way.) > > > > I'm using libicu60. What version are you using, Roman? > > > > I tried to find something that matches this on the ICU bug tracker. > > This might be a match: https://ssl.icu-project.org/trac/ticket/12518 > > FWIW I see the same result with icu 61.1 and 62.1_1 from FreeBSD ports. Some colleagues hit this bug as well last week and reported it to me. I can reproduce this bug with ICU current master branch, version post 67.1. I wrote a regression test for icu4c and posted it on ICU-12518. See: https://unicode-org.atlassian.net/browse/ICU-12518 As Peter wrote, ucol_strcollUTF8 (and ucol_strcoll) functions are affected. A quick and dirty patch to replace ucol_strcoll* by ucol_getSortKey/strcmp everywhere fixed the bug for my tests. After playing with ICU regression tests, I found functions ucol_strcollIter and ucol_nextSortKeyPart are safe. I'll do some performance tests and report here. In the meantime, I've been working on various workarounds. The only one I found is to use "fr-u-kr-latn-digit-kn" instead of "fr-u-kr-latn-digit". Unfortunately, the two collations are not equivalent, but I believe it might be useful in many case. I've been working on a second workaround: creating a type (a char variant for our usecase), its operators and opfamily. All operators and function 1 relies on ucol_getSortKey. Most of the workaround works good but surprisingly, the sort order is only enforced if the field is in the first position: * this works: "SORT BY f1 COLLATE digitslast" * this fails: "SORT BY f2, f1 COLLATE digitslast" I hadn't time to investigate further on this last topic. Regards,