3

In this answer Erwin breaks down IMMUTABLE functions into those that can be inlined, and those that can't. He has an example with to_char() that shows an IMMUTABLE function over to_char() will actually be slower.

That's interesting though because I didn't even know to_char() wasn't IMMUTABLE. Moreover, I didn't know that IMMUTABLE would ever make anything slower. My question is now, how do I find out if a function marked as IMMUTABLE is being inlined, or not?

  • @ErwinBrandstetter fixed! =) – Evan Carroll Aug 8 '18 at 7:02
5

Since it changes the actual execution plan, you can tell from the output of EXPLAIN (ANALYZE, VERBOSE) (among others): Example:

EXPLAIN (ANALYZE, VERBOSE) SELECT my_func(col) FROM tbl;

I simplified and adapted the fiddle from my answer you are referring to:

db<>fiddle here

The first function is inlined, hence you see the inlined expression in the output:

Output: (to_char((d)::timestamp with time zone, 'MMDD'::text))::integer

The second function is not inlined, hence you see the function call in the output:

Output: f_mmdd_tc_i(d)

To be precise: this shows whether the function has been inlined in the tested query. If it has not, that does not necessarily prove it can't be (under different circumstances).
And the test is not bound to just IMMUTABLE functions in any way.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.