Re: Best way to use indexes for partial match at beginning

Поиск
Список
Период
Сортировка
От Andrus
Тема Re: Best way to use indexes for partial match at beginning
Дата
Msg-id dktnpk$2jrl$1@news.hub.org
обсуждение исходный текст
Ответ на Best way to use indexes for partial match at beginning  ("Andrus Moor" <eetasoft@online.ee>)
Ответы Re: Best way to use indexes for partial match at beginning  (Martijn van Oosterhout <kleptog@svana.org>)
Список pgsql-general
>> CREATE INDEX i1 ON foo(col1);
>>
>> cannot be used to optimize queries of type "get all rows where first n
>> charaters of col1 are known" in Postgres.
>
> Of course it will! Any btree based index will let you do that. Re-read the
> previous answers and make sure you pay attention to the bit about
> text_pattern_ops and LIKE in non-C locales.

Richard,

thank you. I try to formulate my problem more presicely.
I have table

CREATE TABLE foo ( bar CHAR(10)  PRIMARY KEY);

Cluster locale is non-C. Database encoding is UTF-8. Postgres vers is 8.1

PRIMARY KEY clause creates btree based index so the index exists on bar.

I want to run fast queries by knowing first characters of bar like :

1. Select records from foo where first character of bar is A
2. Select records from foo where first character of bar is B
3. Select records from foo where first  two characters of bar are BC
4. Select records from foo where first  three characters of bar are ABC
etc.

Can you write sample WHERE clause which can use existing primary key index
for those queries ?

Andrus.



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

Предыдущее
От: Devrim GUNDUZ
Дата:
Сообщение: Re: libpq version in rpm packages
Следующее
От: "Andrus"
Дата:
Сообщение: Re: Best way to use indexes for partial match at beginning