Re: BUG #15892: URGENT: Using an ICU collation in a primary key column breaks ILIKE query

From: "Daniel Verite" <daniel(at)manitou-mail(dot)org>
To: "James Inform" <james(dot)inform(at)pharmapp(dot)de>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #15892: URGENT: Using an ICU collation in a primary key column breaks ILIKE query
Date: 2019-07-04 16:50:27
Message-ID: 8be770db-3fd9-428a-968e-333fc67a50db@manitou-mail.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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

Attachment Content-Type Size
fix-selfuncs-ilike.patch text/plain 738 bytes

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David G. Johnston 2019-07-04 17:06:48 Re: ALTER TABLE results in "ERROR: could not open relation with OID 43707388"
Previous Message Manuel Rigger 2019-07-04 16:40:38 Re: ALTER TABLE results in "ERROR: could not open relation with OID 43707388"