Re: boolean function return values

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: boolean function return values
Дата
Msg-id 28587.1092595196@sss.pgh.pa.us
обсуждение исходный текст
Ответ на boolean function return values  (Eugene Barlow <barlow@tripadvisor.com>)
Список pgsql-general
Eugene Barlow <barlow@tripadvisor.com> writes:
> Can someone explain why I would get different results when using "WHERE
> x()"  v.s. using "WHERE x() = true" for functions that return a
> boolean?  We have also seen the query optimizer behave differently
> between the two uses when using functional indices.

Well, x()=true will match a functional index on x(), whereas the other
will not.

> user1=# select count(*) from t_content where
> validlivesitecontent(publisher, contenttype, status);
>  count
> --------
>  770403
> (1 row)

> user1=# select count(*) from t_content where
> validlivesitecontent(publisher, contenttype, status) = true;
>   count
> ---------
>  1258365
> (1 row)

Is there anything you haven't told us here?  Like, say, whether there is
a functional index on validlivesitecontent(publisher, contenttype, status)?
I'm suspicious that there is one, the second query is using it (you
could verify that with EXPLAIN) and the index is broken for some reason.

One fairly likely way for such an index to get broken is that you
redefine the function's behavior without REINDEXing the index afterward.

            regards, tom lane

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Returning a varchar from a functions
Следующее
От: Chris Travers
Дата:
Сообщение: Re: PHP Postgre-MySql call redirector