Re: 'cost' and 'rows' for volitile function

From: Richard Huxton <dev(at)archonet(dot)com>
To: Rob Sargent <robjsargent(at)gmail(dot)com>
Cc: PostgreSQL <pgsql-sql(at)postgresql(dot)org>
Subject: Re: 'cost' and 'rows' for volitile function
Date: 2009-06-08 17:57:47
Message-ID: 4A2D511B.3010905@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

Rob Sargent wrote:
> Richard Huxton wrote:
>> If your functions are all called at the top-level then indeed it
>> doesn't matter. At a low level though, telling the planner function F1
>> costs 1000 times more than F2 is useful.
>>
> What scares me about this is that for function such as the ones I'm
> currently using which return a wide range of result set size depending
> on input values. The planner will be mis-informed by a factor of 10 or
> more quite easily.

Well, like I said - it doesn't matter as long as you are calling the
function at the top level. The only option the planner has is "execute
function".

However, it is a real problem for what you might term "irregularly
shaped" functions where the costs/rows varies widely. I seem to recall a
suggestion at one point that the values could be replaced by cost
functions that get the same parameters as the function itself. However,
that's could be expensive to do for every function-call, and especially
since there's not always an obvious way to estimate # rows without
calling the function first. I daresay someone will get around to
handling both options in a clean way at some point, but the ability to
define function costs at all was only added in 8.2 iirc.

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Boszormenyi Zoltan 2009-06-08 18:00:24 Re: Any way to bring up a PG instance with corrupted data in it?
Previous Message Tom Lane 2009-06-08 17:52:27 Re: Postgres's Performance degrades after heavy db operation

Browse pgsql-sql by date

  From Date Subject
Next Message Peter Eisentraut 2009-06-08 20:53:34 Re: Xml Schemas
Previous Message Richard Huxton 2009-06-08 17:34:03 Re: 'cost' and 'rows' for volitile function