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 1hj5t5-0000rt-45 for pgsql-bugs@arkaria.postgresql.org; Thu, 04 Jul 2019 17:51:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hj5t4-0007Uu-0F for pgsql-bugs@arkaria.postgresql.org; Thu, 04 Jul 2019 17:51:14 +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 1hj4mT-0004n6-EU for pgsql-bugs@lists.postgresql.org; Thu, 04 Jul 2019 16:40:21 +0000 Received: from mout.kundenserver.de ([212.227.17.13]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hj4mM-0002vH-5R for pgsql-bugs@lists.postgresql.org; Thu, 04 Jul 2019 16:40:20 +0000 Received: from oxbsltgw38.schlund.de ([172.19.249.48]) by mrelayeu.kundenserver.de (mreue109 [213.165.67.113]) with ESMTPSA (Nemesis) id 1M5wTt-1hcCtE0g5z-007XS0 for ; Thu, 04 Jul 2019 18:40:11 +0200 Date: Thu, 4 Jul 2019 18:40:11 +0200 (CEST) From: James Inform Reply-To: James Inform To: pgsql-bugs@lists.postgresql.org Message-ID: <1820097204.279159.1562258411044@email.ionos.de> In-Reply-To: References: <15892-e5d2bea3e8a04a1b@postgresql.org> Subject: Re: BUG #15892: URGENT: Using an ICU collation in a primary key column breaks ILIKE query MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Priority: 3 Importance: Medium X-Mailer: Open-Xchange Mailer v7.8.4-Rev58 X-Originating-Client: open-xchange-appsuite X-Provags-ID: V03:K1:IrRupI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M0I3yFxLaWLR0OKR8Ow8+Uer g2NA/a4 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk The weird thing is, that this behavior only occures when used on a field fi= eld a primary key: If you do:=20 create database testdb; \c testdb; -- Just create a simple table with one column create table icutest(data text not null collate "de-x-icu" primary key, dat= a2 text collate "de-x-icu"); -- Insert a record with uppercase string insert into icutest values ('MYTEST','MYTEST'); -- This is not giving a match select * from icutest where data ilike 'mytest'; -- BUT THIS GIVES A MATCH: select * from icutest where data2 ilike 'mytest'; -- So it seems to be especially related to the scenario where a primary key= / index exists. > On July 4, 2019 at 12:36 PM Daniel Verite wrote= : >=20 >=20 > 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. >=20 > The bug seems to come from a mistake in like_support.c: >=20 > =20 > /* * Check whether char is a letter (and, hence, subject to case-folding)= =20 > * * In multibyte character sets or with ICU, we can't use isalpha, and i= t does * not seem worth trying to convert to wchar_t to use iswalpha. Inste= ad, > just * assume any multibyte char is potentially case-varying.=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; >=20 >=20 > With an ICU locale, this returns false for all characters in 'mytest'. >=20 > 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. >=20 > 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. >=20 >=20 > Best regards, > --=20 > Daniel V=C3=A9rit=C3=A9 > PostgreSQL-powered mailer: http://www.manitou-mail.org > Twitter: @DanielVerite