Trigger function cost

Started by Glyn Astillabout 17 years ago3 messagesgeneral
Jump to latest
#1Glyn Astill
glynastill@yahoo.co.uk

Hi Chaps,

Can anyone point me to docs for trigger function estimated cost?

I see that when I create a volatile plpgsql trigger function it gets given a cost of 100 and a c function gets given a cost of 1.

Is there any reason to mess with this?

Thanks
Glyn

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Glyn Astill (#1)
Re: Trigger function cost

Glyn Astill <glynastill@yahoo.co.uk> writes:

I see that when I create a volatile plpgsql trigger function it gets given a cost of 100 and a c function gets given a cost of 1.

Is there any reason to mess with this?

No. The planner doesn't actually bother to figure the cost of triggers
anyway, since presumably every correct plan will fire the same set of
triggers. So even if you had a more accurate cost estimate than that
one, it wouldn't get used for anything.

Now, for ordinary non-trigger functions, it might be worth paying
some attention to the cost estimate. "1" is intended to denote the
cost of a reasonably simple C function, so PL functions should pretty
much always have costs that are large multiples of that. 100 is a
reasonable default, but if you know better you can put something else.

regards, tom lane

#3Glyn Astill
glynastill@yahoo.co.uk
In reply to: Tom Lane (#2)
Re: Trigger function cost

From: Tom Lane <tgl@sss.pgh.pa.us>

Is there any reason to mess with this?

No. The planner doesn't actually bother to figure the
cost of triggers
anyway, since presumably every correct plan will fire the
same set of
triggers. So even if you had a more accurate cost estimate
than that
one, it wouldn't get used for anything.

Excellent, that's good with me.

Now, for ordinary non-trigger functions, it might be worth
paying
some attention to the cost estimate. "1" is
intended to denote the
cost of a reasonably simple C function, so PL functions
should pretty
much always have costs that are large multiples of that.
100 is a
reasonable default, but if you know better you can put
something else.

Cool, I'll leave it alone for now then, interesting stuff, thanks Tom.