"David G. Johnston" <david.g.johns...@gmail.com> writes: > On Wed, Apr 9, 2025 at 1:50 PM Laurenz Albe <laurenz.a...@cybertec.at> > wrote: >> The IMMUTABLE function cannot be inlined because to_char() is not >> IMMUTABLE.
> So, the punishment for lying about the volatility of one's function is to > prohibit it from being inlined even in a case where had you been truthful > about the volatility it would have been inlined. Yeah. The assumption is that you had a reason for marking the function IMMUTABLE and you want the planner to treat it that way even if it isn't really. (There are valid use-cases for that, for instance if you want calls to the function to be constant-folded.) So we don't inline the function --- if we did, the merely-stable contained expression would be exposed and then treated as STABLE. But that comes at a pretty substantial cost, since the SQL-language-function executor isn't exactly free. If you err in the other direction, you don't get slapped on the wrist that way. We're willing to inline VOLATILE functions, for instance, whether or not the contained expression is volatile. Similarly for STRICT, and I think parallel safety as well. So my own habit when writing a SQL function that I wish to be inlined is to leave off all those markings. They won't matter if the function is successfully inlined, and they might get in the way of that happening. regards, tom lane