Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hiz74-00050p-8Z for pgsql-bugs@arkaria.postgresql.org; Thu, 04 Jul 2019 10:37:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hiz72-00063K-5w for pgsql-bugs@arkaria.postgresql.org; Thu, 04 Jul 2019 10:37:12 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hiz71-000603-Ph for pgsql-bugs@lists.postgresql.org; Thu, 04 Jul 2019 10:37:11 +0000 Received: from mail.verite.pro ([185.16.44.216]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hiz6z-00083x-4N for pgsql-bugs@lists.postgresql.org; Thu, 04 Jul 2019 10:37:10 +0000 Received: from genius-map.net (verite.pro [195.154.189.246]) by mail.verite.pro (Postfix) with ESMTP id F41E18C0273; Thu, 4 Jul 2019 12:31:07 +0200 (CEST) Received: by genius-map.net (Postfix, from userid 1001) id 133F838A07CC; Thu, 4 Jul 2019 12:37:05 +0200 (CEST) Content-Type: text/plain; charset="iso-8859-15" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: BUG #15892: URGENT: Using an ICU collation in a primary key column breaks ILIKE query From: "Daniel Verite" To: james.inform@pharmapp.de,pgsql-bugs@lists.postgresql.org In-Reply-To: <15892-e5d2bea3e8a04a1b@postgresql.org> Date: Thu, 04 Jul 2019 12:36:59 +0200 Message-Id: X-Mailer: Manitou v1.7.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form wrote: > -- Just create a simple table with one column=20 > create table icutest(data text not null collate "de-x-icu" primary key);= =20 >=20 > -- Insert a record with uppercase string=20 > insert into icutest values ('MYTEST');=20 >=20 > -- This is not giving a match=20 > select * from icutest where data ilike 'mytest';=20 This also happens on v10 and on the master branch. The bug seems to come from a mistake in like_support.c: =20 /*=09=09=09=09=09=09=09=09=09=20=20=20=20=20=20 * Check whether char is a letter (and, hence, subject to case-folding)=20= =20=20=20=20=20=20 *=09=09=09=09=09=09=09=09=09=20=20=20=20=20=20 * In multibyte character sets or with ICU, we can't use isalpha, and it do= es=20 * not seem worth trying to convert to wchar_t to use iswalpha. Instead, just=20=20 * assume any multibyte char is potentially case-varying.=09=09=20=20=20=20= =20=20 */ static int pattern_char_isalpha(char c, bool is_multibyte, pg_locale_t locale, bool locale_is_c) { if (locale_is_c) return (c >=3D 'A' && c <=3D 'Z') || (c >=3D 'a' && c <=3D 'z'); else if (is_multibyte && IS_HIGHBIT_SET(c)) return true; else if (locale && locale->provider =3D=3D COLLPROVIDER_ICU) return IS_HIGHBIT_SET(c) ? true : false; With an ICU locale, this returns false for all characters in 'mytest'. I think this eventually leads the caller to incorrectly believe that it can optimize the test into an exact match (data=3D'mytest'), given there are otherwise no wildcards in the pattern. On fixing the bug, if we make this function returns true for all characters under an ICU locale, it appears to work, but we're loosing an opportunity to optimize for some patterns. If OTOH we wanted to use an ICU call like u_isalpha(), to be closer to what's done with libc, we'd need to pass a UChar32 argument, not a char, and since we're in a char-oriented context, I don't see how to do that. Best regards, --=20 Daniel V=E9rit=E9 PostgreSQL-powered mailer: http://www.manitou-mail.org Twitter: @DanielVerite