Re: strpos() && KMP - Mailing list pgsql-patches

From Tom Lane
Subject Re: strpos() && KMP
Date
Msg-id 22661.1186809312@sss.pgh.pa.us
Whole thread Raw
In response to Re: strpos() && KMP  (Pavel Ajtkulov <ajtkulov@acm.org>)
List pgsql-patches
Pavel Ajtkulov <ajtkulov@acm.org> writes:
> Tom Lane writes:
>> Moreover, you'd lose the guarantee of not-worse-than-linear time,
>> because hash lookup can be pathologically bad if you get a lot of hash
>> collisions.

> compute max_wchar, min_wchar. If (d = max_wchar - min_wchar) < k (for
> example, k = 1000), then we use index table (wchar -> wchar -
> min_wchar). Else we use hash table. Number of collisions would be a
> few (because hash table needs for pattern characters only.

I think you missed my point: there's a significant difference between
"guaranteed good performance" and "probabilistically good performance".
Even when the probably-good algorithm wins for typical cases, there's a
strong argument to be made for guarantees.  The problem you set out to
solve really is that an algorithm that's all right in everyday cases
will suck in certain uncommon cases --- so why do you want to fix it
by just moving around the cases in which it fails to do well?

            regards, tom lane

pgsql-patches by date:

Previous
From: Andrew Dunstan
Date:
Subject: final CSVlog patch
Next
From: Michael Glaesemann
Date:
Subject: Re: final CSVlog patch