From: Daniel Verite <daniel@manitou-mail.org>
To: James Inform <james.inform@pharmapp.de>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #15892: URGENT: Using an ICU collation in a primary key column breaks ILIKE query
Date: Thu, 04 Jul 2019 18:50:27 +0200
Message-ID: <8be770db-3fd9-428a-968e-333fc67a50db@manitou-mail.org> (raw)
In-Reply-To: <1797229370.392447.1562247705371@email.ionos.de>
James Inform wrote:
> -- 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.
>
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=# explain analyze select * from icutest where data ilike 'mytest';
QUERY PLAN
-------------------------------------------------------------------------------------------------------
---------------------
Index Only Scan using icutest_pkey on icutest (cost=0.15..8.17 rows=1
width=32) (actual time=0.013..0
.013 rows=0 loops=1)
Index Cond: (data = 'mytest'::text)
Filter: (data ~~* 'mytest'::text)
Heap Fetches: 0
Planning Time: 0.593 ms
Execution Time: 0.035 ms
* Patched version:
postgres=# explain analyze select * from icutest where data ilike 'mytest';
QUERY PLAN
---------------------------------------------------------------------------------------------------
Seq Scan on icutest (cost=0.00..27.00 rows=1 width=32) (actual
time=0.122..0.123 rows=1 loops=1)
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,
--
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite
Attachments:fix-selfuncs-ilike.patch (text/plain, 738B) download
diff -ru postgresql-11.4/src/backend/utils/adt/selfuncs.c postgresql-11.4-fix/src/backend/utils/adt/selfuncs.c
--- postgresql-11.4/src/backend/utils/adt/selfuncs.c 2019-06-17 23:15:30.000000000 +0200+++ postgresql-11.4-fix/src/backend/utils/adt/selfuncs.c 2019-07-04 18:28:26.097870673 +0200@@ -5770,7 +5770,7 @@
else if (is_multibyte && IS_HIGHBIT_SET(c))
return true;
else if (locale && locale->provider == COLLPROVIDER_ICU)
- return IS_HIGHBIT_SET(c) ? true : false;+ return true; /* IS_HIGHBIT_SET(c) ? true : false; */
#ifdef HAVE_LOCALE_T
else if (locale && locale->provider == COLLPROVIDER_LIBC)
return isalpha_l((unsigned char) c, locale->info.lt);
Only in postgresql-11.4-fix/src/backend/utils/adt: selfuncs.c~
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: daniel@manitou-mail.org, james.inform@pharmapp.de
Subject: Re: BUG #15892: URGENT: Using an ICU collation in a primary key column breaks ILIKE query
In-Reply-To: <8be770db-3fd9-428a-968e-333fc67a50db@manitou-mail.org>
References: <1797229370.392447.1562247705371@email.ionos.de> <8be770db-3fd9-428a-968e-333fc67a50db@manitou-mail.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox