The documentation in CREATE FUNCTION is fine as far is it goes regarding the 
COST setting, but that isn’t very far, and I haven’t had any luck finding good 
advice.

How do I determine what value to set as the COST of a function? I understand 
that it’s a relative, abstract, per-row sort of thing, but that’s not quite 
enough to go on to do it well.

If I have a function that looks up a single value from an index, should that be 
lower than 100? 20, say?

If I have a function that calls multiple other functions, each of which does a 
reasonable amount of work, should I set the caller to a higher COST, or will 
Postgres use the costs of the functions it calls?

I can imagine that a SQL function which is just inlined might ignore the COST 
estimate. Is that so? Are there other such considerations?

In general, a section in the CREATE FUNCTION documentation of two or three 
paragraphs with a few examples and general guidelines would be very helpful. I 
would be happy to write it if someone will explain it to me.

Reply via email to