From: Andrus <eetasoft@online.ee>
To: pgsql-performance@postgresql.org
Subject: Re: How to force Postgres to use index on ILIKE
Date: Tue, 6 Jun 2006 12:57:31 +0300
Message-ID: <e63jit$28fk$2@news.hub.org> (raw)
References: <e620mg$15jr$1@news.hub.org>
<200606051426.56789.josh@agliodbs.com>
>> SELECT toode, nimetus
>> FROM toode
>> WHERE toode ILIKE 'x10%' ESCAPE '!'
>> ORDER BY UPPER(toode ),nimetus LIMIT 100
>>
>> runs 1 minute in first time for small table size.
>>
>> Toode field type is CHAR(20)
>
> 1) why are you using CHAR and not VARCHAR or TEXT? CHAR will give you
> problems using an index, period.
1. I haven't seen any example where VARCHAR is better that CHAR for indexing
2. I have a lot of existing code. Changing CHAR to VARCHAR requires probably
re-writing a lot of code, a huge work.
> 2) You can't use an index on ILIKE.
I'ts very sad. I expected that lower(toode) index can be used.
> You can, however, use an index on
> lower(field) if your query is properly phrased and if you've created an
> expression index on lower(field).
I tried by Postgres does not use index. Why ?
create index nimib2 on firma1.klient(lower(nimi) bpchar_pattern_ops);
explain analyze select nimi from firma1.klient where lower(nimi) like
'mokter%'
"Seq Scan on klient (cost=0.00..9.79 rows=1 width=74) (actual
time=0.740..0.761 rows=1 loops=1)"
" Filter: (lower((nimi)::text) ~~ 'mokter%'::text)"
"Total runtime: 0.877 ms"
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 using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: eetasoft@online.ee
Subject: Re: How to force Postgres to use index on ILIKE
In-Reply-To: <e63jit$28fk$2@news.hub.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