Re: SQL optimization - WHERE SomeField STARTING WITH ...

Поиск
Список
Период
Сортировка
От Tino Wildenhain
Тема Re: SQL optimization - WHERE SomeField STARTING WITH ...
Дата
Msg-id 48B710E2.2030000@wildenhain.de
обсуждение исходный текст
Ответ на Re: SQL optimization - WHERE SomeField STARTING WITH ...  (Steve Atkins <steve@blighty.com>)
Список pgsql-general
Steve Atkins wrote:
>
> On Aug 28, 2008, at 12:27 PM, Tino Wildenhain wrote:
>
>> Hi Bill,
>>
>> Bill wrote:
>>> The SQL database servers I have worked with cannot use and index for
>>> a SELECT of the form
>>> SELECT * FROM ATABLE
>>> WHERE AFIELD LIKE ?
>>> because there is no way to know the location of the wild card until
>>> the parameter value is known. InterBase and Firebird allow
>>> SELECT * FROM ATABLE
>>> WHERE AFIELD STARTING WITH ?
>>> which is equivalent to LIKE  'ABC%' and will use an index on AFIELD.
>>> Is there a similar syntax in PostgreSQL?
>>
>> Yes, its actually: LIKE 'ABC%' and it will use an index.
>
> I think Bill's point is that the planner can't take advantage of that at
> the time it's planning the query unless it has the string at that point.
> Something like "STARTING WITH" could be used with prepared statements too.

Ah yes, I now see :-) Seems a general way of hinting statement
preparation on the nature of the expected data would be nice.

Something like special domain types maybe which have resonable
constraints which can be used by the planner. Obviously not
so easy solution.

Regards
Tino

Вложения

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

Предыдущее
От: "Scott Marlowe"
Дата:
Сообщение: Re: MySQL LAST_INSERT_ID() to Postgres
Следующее
От: Bill
Дата:
Сообщение: Re: MySQL LAST_INSERT_ID() to Postgres