Re: Query optimisation

Поиск
Список
Период
Сортировка
От Richard Huxton
Тема Re: Query optimisation
Дата
Msg-id 008401c0639e$89780260$1001a8c0@archonet.com
обсуждение исходный текст
Ответ на Query optimisation  (Michel Vrand <mvrand@pacwan.fr>)
Список pgsql-sql
From: "Michel Vrand" <mvrand@pacwan.fr>


> $conditions may be
>
> 1/ ...AND groupes.nom = '$something' AND....
> or
> 2/ ...AND groupes.nom ~* '$something' AND....
>
> In the first case, the query is reasonnably fast (0.30 s for 4 items on
> 15000)
> In the second case, the query becomes very slow (more than 31 s for the
same
> result)
>
> to give example, in the first case $something = "Beatles"
>                    in the second case $something = "beatl"
>
> How to optimise speed ? I tried to type EXPLAIN but I do not understand
the
> result :
>
You are right - the index *does* make that much difference. The problem is
that ~* matches *anywhere* in the string so it can't use the index - it has
to read each entry.

If you want to match the start of the entry, I know of one way to make the
index work. Use

groupes.nom>='beatl' AND groupes.nom<='beatlz'

And that should work - although 'z' is a poor character to use - pick the
highest valid character in your character set. You might also want to look
in the archives for the thread on pgsql-general with a subject of 'Simple
Question: Case sensitivity'

- Richard Huxton



В списке pgsql-sql по дате отправления:

Предыдущее
От: Mateusz Mazur
Дата:
Сообщение: Where Can I find JDBC driver.
Следующее
От: Joseph Shraibman
Дата:
Сообщение: Re: FOREIGN KEY errors.