Re: [SQL] qurey plan and indices

Поиск
Список
Период
Сортировка
От Patrick Giagnocavo
Тема Re: [SQL] qurey plan and indices
Дата
Msg-id 37A99D4F.610E6F7C@redrose.net
обсуждение исходный текст
Ответ на qurey plan and indices  (MESZAROS Attila <tilla@chiara.csoma.elte.hu>)
Ответы Re: [SQL] qurey plan and indices  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: [SQL] qurey plan and indices  (MESZAROS Attila <tilla@chiara.csoma.elte.hu>)
Список pgsql-sql
MESZAROS Attila wrote:
> 
> Hi,
> 
> I've experienced a brutal speedup (order of 2) separateing the following
> subquery and making it manually:
> 
> explain select name,description
> from descriptions
> where in (select name
>                 from descriptions
>                 where description like '%Bankverbindung%');
> 
> Seq Scan on descriptions  (cost=163.98 rows=3575 width=24)
>   SubPlan
>     ->  Seq Scan on descriptions  (cost=163.98 rows=2 width=12)
> [I had no patient to wait the resuls...]
>

Correct me if I am wrong, however if using 

LIKE '%something%'
(which means, the field contains 'something' somewhere in the field)

there is never a chance to use the index you have created - a
sequential table scan MUST be made, thus you have to read all 3575
rows to return the set.

However, if you change your query so that you are looking for 

LIKE 'Bankverbindung%'

then an index can be used becase you know what the first few
characters are known.

Hope this helps,

Cordially

Patrick Giagnocavo
a222@redrose.net


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

Предыдущее
От: rob caSSon
Дата:
Сообщение: primary key view failure
Следующее
От: Tom Lane
Дата:
Сообщение: Re: [SQL] primary key view failure