strpos() && KMP

Поиск
Список
Период
Сортировка
От Pavel Ajtkulov
Тема strpos() && KMP
Дата
Msg-id 1167412014.20070802011822@acm.org
обсуждение исходный текст
Ответы Re: strpos() && KMP  (Andrew Dunstan <andrew@dunslane.net>)
Re: strpos() && KMP  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: strpos() && KMP  (Decibel! <decibel@decibel.org>)
Re: strpos() && KMP  (Bruce Momjian <bruce@momjian.us>)
Список pgsql-patches
Hello,

this patch allow to use Knuth-Morrison-Pratt algorithm for strpos() function
(see Cormen et al. Introduction to Algorithms, MIT Press, 2001).

It also works with multibyte wchar.

In worst case current brute force strpos() takes O(n * m) (n && m is length of strings)
time (example: 'aaa...aaab' search in 'aaa...aaa').
KMP algo always takes O(n + m) time.
To check this someone need to create a table with one text attribute, and insert several thousands
record 'aa..aa'(for example, with lenght = 1000) . After execute "select count(*) from test where
strpos(a, 'aaa....aab') > 0;" on current and modified version.

Also, I advise to use "select .. where strpos(att, 'word') > 0;" instead "select .. where attr like '%word%'"
(strpos must be faster than regex).

In general, this belongs to artificial expressions. In natural language KMP is equal (execution time)
current strpos() nearly.


----
Ajtkulov Pavel
ajtkulov@acm.org

P. S. Sorry for prime English.

Вложения

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

Предыдущее
От: Heikki Linnakangas
Дата:
Сообщение: Re: HOT patch - version 11
Следующее
От: Andrew Dunstan
Дата:
Сообщение: Re: strpos() && KMP