STABLE vs. IMMUTABLE w.r.t. indexes

Поиск
Список
Период
Сортировка
От Moshe Jacobson
Тема STABLE vs. IMMUTABLE w.r.t. indexes
Дата
Msg-id CAJ4CxLmELEAm9yvB6ErjXZ-=0oH1fs4TsSoOrB0W5wRFawNa7A@mail.gmail.com
обсуждение исходный текст
Ответы Re: STABLE vs. IMMUTABLE w.r.t. indexes  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
It seems Postgres 9.3 does not realize that it can collapse the result of a STABLE function when attempting to match against an index for a single query.

I am running into a problem with a full text index, where my filter conditions include a function that returns the user's language code. If the function result were substituted directly, the filter condition would match an index built for that particular language, but the only way I can get the function to collapse down is to call it IMMUTABLE.

The function pulls a GUC value and that's all it does. Is it safe to mark it IMMUTABLE? I noticed that if I updated the GUC variable and ran the query again, it worked as I would hope, with the new value of the function substituted. So it seems it would be safe, but I'd like to verify. 

I'd also like to know why it wouldn't work if the function was STABLE: Since Postgres should know that it's not going to change over the course of the query, couldn't it substitute the value as well?

More details can be provided on request.

Thanks.

Moshe Jacobson
Principal Architect, Nead Werx Inc.
2323 Cumberland Parkway · Suite 201 · Atlanta, GA 30339

"Quality is not an act, it is a habit." -- Aristotle

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

Предыдущее
От: Sven Wegener
Дата:
Сообщение: COPY TO returning empty result with parallel ALTER TABLE
Следующее
От: Georges Racinet
Дата:
Сообщение: Testing on Power 8 systems