Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hYXwm-0000v9-Sx for pgsql-general@arkaria.postgresql.org; Wed, 05 Jun 2019 15:35:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hYXwk-0007Qg-14 for pgsql-general@arkaria.postgresql.org; Wed, 05 Jun 2019 15:35:26 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hYXc2-0004Ut-Bd for pgsql-general@lists.postgresql.org; Wed, 05 Jun 2019 15:14:02 +0000 Received: from black.elm.relay.mailchannels.net ([23.83.212.19]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hYXbv-0000FE-64 for pgsql-general@postgresql.org; Wed, 05 Jun 2019 15:14:00 +0000 X-Sender-Id: techassets|x-authuser|guyren@relevantlogic.com Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 794265E1C6E for ; Wed, 5 Jun 2019 15:13:53 +0000 (UTC) Received: from cp39.myhostcenter.com (100-96-89-88.trex.outbound.svc.cluster.local [100.96.89.88]) (Authenticated sender: techassets) by relay.mailchannels.net (Postfix) with ESMTPA id 42C995E11E2 for ; Wed, 5 Jun 2019 15:13:52 +0000 (UTC) X-Sender-Id: techassets|x-authuser|guyren@relevantlogic.com Received: from cp39.myhostcenter.com ([TEMPUNAVAIL]. [66.84.0.139]) (using TLSv1 with cipher DHE-RSA-AES256-SHA) by 0.0.0.0:2500 (trex/5.17.2); Wed, 05 Jun 2019 15:13:53 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: techassets|x-authuser|guyren@relevantlogic.com X-MailChannels-Auth-Id: techassets X-Spicy-Absorbed: 042409dd43dec34c_1559747633103_3449065150 X-MC-Loop-Signature: 1559747633103:802656883 X-MC-Ingress-Time: 1559747633102 Received: from ip68-107-18-54.sd.sd.cox.net ([68.107.18.54]:54829 helo=[192.168.1.13]) by cp39.myhostcenter.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.87) (envelope-from ) id 1hYXbm-000785-8B for pgsql-general@postgresql.org; Wed, 05 Jun 2019 11:13:46 -0400 Date: Wed, 5 Jun 2019 08:08:04 -0700 From: guyren@relevantlogic.com To: PG-General Mailing List Message-ID: <27621de6-c05b-493c-bf53-49539cb04577@Spark> References: <73351881-0cd6-4331-817b-2c67747940f5@Spark> Subject: Advice on setting cost for function X-Readdle-Message-ID: 27621de6-c05b-493c-bf53-49539cb04577@Spark MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="5cf7dc26_7545e146_f72" X-AuthUser: guyren@relevantlogic.com List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --5cf7dc26_7545e146_f72 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline The documentation in CREATE =46UNCTION is fine as far is it goes regardin= g the COST setting, but that isn=E2=80=99t very far, and I haven=E2=80=99= t had any luck finding good advice. How do I determine what value to set as the COST of a function=3F I under= stand that it=E2=80=99s a relative, abstract, per-row sort of thing, but = that=E2=80=99s 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 t= hat be lower than 100=3F 20, say=3F If I have a function that calls multiple other functions, each of which d= oes 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=3F I can imagine that a SQL function which is just inlined might ignore the = COST estimate. Is that so=3F Are there other such considerations=3F In general, a section in the CREATE =46UNCTION documentation of two or th= ree paragraphs with a few examples and general guidelines would be very h= elpful. I would be happy to write it if someone will explain it to me. --5cf7dc26_7545e146_f72 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
The documentation in CREATE =46UNCTION is fine as f= ar is it goes regarding the COST setting, but that isn=E2=80=99t very far= , and I haven=E2=80=99t had any luck finding good advice.

How do I determine what value to set as the COST of= a function=3F I understand that it=E2=80=99s a relative, abstract, per-r= ow sort of thing, but that=E2=80=99s not quite enough to go on to do it w= ell.

If I have a function that looks up a single value f= rom an index, should that be lower than 100=3F 20, say=3F

If I have a function that calls multiple other func= tions, each of which does a reasonable amount of work, should I set the c= aller to a higher COST, or will Postgres use the costs of the functions i= t calls=3F

I can imagine that a SQL function which is just inl= ined might ignore the COST estimate. Is that so=3F Are there other such c= onsiderations=3F

In general, a section in the CREATE =46UNCTION docu= mentation of two or three paragraphs with a few examples and general guid= elines would be very helpful. I would be happy to write it if someone wil= l explain it to me.
--5cf7dc26_7545e146_f72--