Re: non-static LIKE patterns

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: non-static LIKE patterns
Дата
Msg-id 1397.1334238958@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: non-static LIKE patterns  (hamann.w@t-online.de)
Ответы Re: non-static LIKE patterns
Список pgsql-general
hamann.w@t-online.de writes:
> Tom Lane wrote:
> If you want it to be bulletproof, what I'd think about is something like
>     WHERE second.path LIKE quote_like(first.path)||'%'

> Just out of curiosity: wouldn't that (as well as using non-static like)
> be an enormous performance problem?

Well, it won't be free, but I think you've already doomed yourself to
a not-very-bright plan by using LIKE in this way at all.

In any case, as a wise man once said, you can make it run arbitrarily
fast if it doesn't have to give the right answer.  Correctness trumps
any micro-optimization questions, so if you have to have prefix matching
of this sort, it's gonna cost ya somehow.

Actually, if the only case you're worried about is prefix match, you
could do it in substring style:

    WHERE second.path = substring(first.path, 1, length(second.path))

(better double-check the substring syntax, I'm too lazy to).  This is
still going to completely suck on a macro level: there's still no way to
perform the join except by tediously iterating through every combination
of rows.  But it'll likely outrun any LIKE-based solution by some
percentage.

            regards, tom lane

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

Предыдущее
От: Merlin Moncure
Дата:
Сообщение: Re: Searchable chess positions in a Postgress DB
Следующее
От: Ivan Evtuhovich
Дата:
Сообщение: Two entries with the same primary key