From: | Sferacarta Software <sferac(at)bo(dot)nettuno(dot)it> |
---|---|
To: | <pgsql-general(at)postgresql(dot)org>, "jerome doucerain" <jerome(dot)doucerain(at)chu-nimes(dot)fr> |
Subject: | Re: [GENERAL] Generic search |
Date: | 1998-12-04 13:48:59 |
Message-ID: | 19617.981204@bo.nettuno.it |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hello Jerome,
venerdì, 4 dicembre 98, you wrote:
jd> Hi,
jd> As it seems
jd> Postgres doesn't use index when the where clause contains "like" operator.
jd> It only uses it in case of "=" operator.
jd> for example :
test=>> create table essai (nom varchar(50));
jd> CREATE
test=>> create index essai_nom on essai (nom);
jd> CREATE
test=>> \d essai
jd> Table = essai
jd> +----------------------------------+----------------------------------+-----
jd> --+
jd> | Field | Type |
jd> Length|
jd> +----------------------------------+----------------------------------+-----
jd> --+
jd> | nom | varchar() |
jd> 50 |
jd> +----------------------------------+----------------------------------+-----
jd> --+
test=>> \d essai_nom
jd> Table = essai_nom
jd> +----------------------------------+----------------------------------+-----
jd> --+
jd> | Field | Type |
jd> Length|
jd> +----------------------------------+----------------------------------+-----
jd> --+
jd> | nom | varchar() |
jd> -4 |
jd> +----------------------------------+----------------------------------+-----
jd> --+
test=>> explain select * from essai where nom='abc';
jd> NOTICE: QUERY PLAN:
jd> Index Scan using essai_nom on essai (cost=0.00 size=0 width=12)
jd> EXPLAIN
test=>> explain select * from essai where nom like 'a%';
jd> NOTICE: QUERY PLAN:
jd> Seq Scan on essai (cost=0.00 size=0 width=12)
jd> EXPLAIN
jd> Postgres 6.4 Linux 2.0.34.
jd> So I'm looking for a way to get quite good performances with generic
jd> search.
jd> Thank you for advices.
jd> Jerome.
How many records do you have in this table ?
If you have only few records PostgreSQL doesn't use index because it
is faster to read in sequential mode.
Try to insert a lot of records. It works, look:
hygea=> explain select * from comuni where nome = 'A%';
NOTICE: QUERY PLAN:
Index Scan using nome_comune_idx on comuni (cost=2.05 size=2 width=84)
^^^^^
EXPLAIN
hygea=> explain select * from comuni where nome > 'A%';
NOTICE: QUERY PLAN:
Index Scan using nome_comune_idx on comuni (cost=215.03 size=2781 width=84)
^^^^^
EXPLAIN
hygea=> explain select * from comuni where nome <> 'A%';
NOTICE: QUERY PLAN:
Seq Scan on comuni (cost=427.29 size=8342 width=84)
EXPLAIN
hygea=> explain select * from comuni where nome < 'A%';
NOTICE: QUERY PLAN:
Index Scan using nome_comune_idx on comuni (cost=215.03 size=2781 width=84)
^^^^^
EXPLAIN
hygea=> explain select * from comuni where nome like '%A%';
NOTICE: QUERY PLAN:
Seq Scan on comuni (cost=427.29 size=2 width=84)
^^^
Pg uses index with LIKE only if the first char is not a special char.
-Jose'-
From | Date | Subject | |
---|---|---|---|
Next Message | Dmitry Iv Popov | 1998-12-04 14:26:21 | Postgres & Java [client/server] |
Previous Message | Alex Oboimov | 1998-12-04 12:55:51 | Re: [GENERAL] Y2K REady? |