Relative performance of prefix and suffix string matching

Поиск
Список
Период
Сортировка
От Andrew Rose
Тема Relative performance of prefix and suffix string matching
Дата
Msg-id 632BF61B4D0DEC4AAD03109304ADD5761912F6BF@ENFIRHMBX1.datcon.co.uk
обсуждение исходный текст
Ответы Re: Relative performance of prefix and suffix string matching
Re: Relative performance of prefix and suffix string matching
Список pgsql-general
Basic Question: In text fields, is prefix matching significantly faster than suffix matching?

Background:

I'm designing a database schema where a common operation will be "search for substring x either at the beginning or end
ofcolumn 'str'". 

1. I could have the client issue...

SELECT * FROM tbl WHERE str LIKE 'x%' OR str LIKE '%x'

2. Alternatively, I could store column 'rev_str' as a reversed version of column 'str' and have the client produce a
reversedversion of x on each query (call it r).  Then the client would issue... 

SELECT * FROM tbl WHERE str LIKE 'x%' OR rev_str LIKE 'r%'

...which would use prefix matches only instead of requiring suffix matches.  Since I've seen this form used by others,
Iwas wondering if it's necessary - i.e. if databases really do perform prefix matching faster? 

3. Is there a solution I'm unaware of with even better performance?

Thanks,

Andrew

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

Предыдущее
От: hamann.w@t-online.de
Дата:
Сообщение: Re: looking for a faster way to do that
Следующее
От: c k
Дата:
Сообщение: Re: Date time value error in Ms Access using pass through queries