While looking at several examples of pl/python and pl/pgsql, I have seen many - but not all - using volatile cost.
ie:
CREATE OR REPLACE FUNCTION my_function()
RETURNS setof record AS
$BODY$
-- code
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
Searching for more information about volatile cost I have discovered (at first sight) that roughly at least 90% of web examples are using volatile cost 100, and sometimes somethimes volatile cost 1. (for rows it's 1000).
As I have understood, this indication helps the query plan optimizer to decide how to set priorities in short-circuit boolean operations.
Is it premature optimization if I start to give an estimate cost or rows for each of my stored procedures ? Should I only do it when I want to optimize certain query ? Is it an art for choosing the good value of cost ?
I know about the command explain, which I have have not learnt yet. Is this command helpful for estimating cost ?
ROW 1yes.COST 1almost certainly wrong, that's about the cost for a trivial C-language function. – Erwin Brandstetter Apr 02 '21 at 02:30