STABLE vs. IMMUTABLE w.r.t. indexes - Mailing list pgsql-general

From Moshe Jacobson
Subject STABLE vs. IMMUTABLE w.r.t. indexes
Date
Msg-id CAJ4CxLmELEAm9yvB6ErjXZ-=0oH1fs4TsSoOrB0W5wRFawNa7A@mail.gmail.com
Whole thread Raw
Responses Re: STABLE vs. IMMUTABLE w.r.t. indexes  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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 by date:

Previous
From: Sven Wegener
Date:
Subject: COPY TO returning empty result with parallel ALTER TABLE
Next
From: Georges Racinet
Date:
Subject: Testing on Power 8 systems