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 1hj4wQ-0006R8-2C for pgsql-bugs@arkaria.postgresql.org; Thu, 04 Jul 2019 16:50:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hj4wO-0002RU-U1 for pgsql-bugs@arkaria.postgresql.org; Thu, 04 Jul 2019 16:50:36 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1hj4wO-0002RM-MJ for pgsql-bugs@lists.postgresql.org; Thu, 04 Jul 2019 16:50:36 +0000 Received: from mail.verite.pro ([185.16.44.216]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hj4wL-0000hN-QJ for pgsql-bugs@lists.postgresql.org; Thu, 04 Jul 2019 16:50:36 +0000 Received: from genius-map.net (verite.pro [195.154.189.246]) by mail.verite.pro (Postfix) with ESMTP id BBAA88C0273; Thu, 4 Jul 2019 18:44:32 +0200 (CEST) Received: by genius-map.net (Postfix, from userid 1001) id DDB2238A0DAB; Thu, 4 Jul 2019 18:50:29 +0200 (CEST) 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" Cc: pgsql-bugs@lists.postgresql.org In-Reply-To: <1797229370.392447.1562247705371@email.ionos.de> Date: Thu, 04 Jul 2019 18:50:27 +0200 Message-Id: <8be770db-3fd9-428a-968e-333fc67a50db@manitou-mail.org> X-Mailer: Manitou v1.7.0 Content-type: multipart/mixed; boundary="----------=_1562259029-20727-17" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format... ------------=_1562259029-20727-17 Content-Type: text/plain; charset="iso-8859-15" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable James Inform wrote: > -- This is not giving a match > select * from icutest where data ilike 'mytest'; >=20 > -- BUT THIS GIVES A MATCH: >=20 > select * from icutest where data2 ilike 'mytest'; >=20 > -- So it seems to be especially related to the scenario where a primary k= ey > / index exists. >=20 Yes. It is because of the index that the code checks if the ILIKE can be evaluated with an index lookup. Otherwise it doesn't. If you feel like recompiling with a temporary fix against v11.4 to do your own tests, please try the attached patch. Here's the result for me: * Unpatched version: postgres=3D# explain analyze select * from icutest where data ilike 'mytest= '; QUERY PLAN=09=20=20=20=20=20=20 ---------------------------------------------------------------------------= ---------------------------- --------------------- Index Only Scan using icutest_pkey on icutest (cost=3D0.15..8.17 rows=3D1 width=3D32) (actual time=3D0.013..0 .013 rows=3D0 loops=3D1) Index Cond: (data =3D 'mytest'::text) Filter: (data ~~* 'mytest'::text) Heap Fetches: 0 Planning Time: 0.593 ms Execution Time: 0.035 ms * Patched version: postgres=3D# explain analyze select * from icutest where data ilike 'mytest= '; QUERY PLAN=09=09=09=20=20=20=20=20=20 ---------------------------------------------------------------------------= ------------------------ Seq Scan on icutest (cost=3D0.00..27.00 rows=3D1 width=3D32) (actual time=3D0.122..0.123 rows=3D1 loops=3D1) Filter: (data ~~* 'mytest'::text) Planning Time: 0.081 ms Execution Time: 0.144 ms Notice how the patched version ignores the index and correctly finds the row versus the unpatched version. Best regards, --=20 Daniel V=E9rit=E9 PostgreSQL-powered mailer: http://www.manitou-mail.org Twitter: @DanielVerite ------------=_1562259029-20727-17 Content-Type: text-x-patch; name="fix-selfuncs-ilike.patch" Content-Disposition: attachment; filename="fix-selfuncs-ilike.patch" Content-Transfer-Encoding: base64 ZGlmZiAtcnUgcG9zdGdyZXNxbC0xMS40L3NyYy9iYWNrZW5kL3V0aWxzL2Fk dC9zZWxmdW5jcy5jIHBvc3RncmVzcWwtMTEuNC1maXgvc3JjL2JhY2tlbmQv dXRpbHMvYWR0L3NlbGZ1bmNzLmMKLS0tIHBvc3RncmVzcWwtMTEuNC9zcmMv YmFja2VuZC91dGlscy9hZHQvc2VsZnVuY3MuYwkyMDE5LTA2LTE3IDIzOjE1 OjMwLjAwMDAwMDAwMCArMDIwMAorKysgcG9zdGdyZXNxbC0xMS40LWZpeC9z cmMvYmFja2VuZC91dGlscy9hZHQvc2VsZnVuY3MuYwkyMDE5LTA3LTA0IDE4 OjI4OjI2LjA5Nzg3MDY3MyArMDIwMApAQCAtNTc3MCw3ICs1NzcwLDcgQEAK IAllbHNlIGlmIChpc19tdWx0aWJ5dGUgJiYgSVNfSElHSEJJVF9TRVQoYykp CiAJCXJldHVybiB0cnVlOwogCWVsc2UgaWYgKGxvY2FsZSAmJiBsb2NhbGUt PnByb3ZpZGVyID09IENPTExQUk9WSURFUl9JQ1UpCi0JCXJldHVybiBJU19I SUdIQklUX1NFVChjKSA/IHRydWUgOiBmYWxzZTsKKwkJcmV0dXJuIHRydWU7 IC8qIElTX0hJR0hCSVRfU0VUKGMpID8gdHJ1ZSA6IGZhbHNlOyAqLwogI2lm ZGVmIEhBVkVfTE9DQUxFX1QKIAllbHNlIGlmIChsb2NhbGUgJiYgbG9jYWxl LT5wcm92aWRlciA9PSBDT0xMUFJPVklERVJfTElCQykKIAkJcmV0dXJuIGlz YWxwaGFfbCgodW5zaWduZWQgY2hhcikgYywgbG9jYWxlLT5pbmZvLmx0KTsK T25seSBpbiBwb3N0Z3Jlc3FsLTExLjQtZml4L3NyYy9iYWNrZW5kL3V0aWxz L2FkdDogc2VsZnVuY3MuY34K ------------=_1562259029-20727-17--