Re: The first function call

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Diego Silva e Silva <diegogrv(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: The first function call
Date: 2018-01-11 15:59:52
Message-ID: 14298.1515686392@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Diego Silva e Silva <diegogrv(at)gmail(dot)com> writes:
> The first function call is 10 times slower than the other calls in the same
> session. Is it possible to shorten this long time on the first call?
> For example. Call my function for once, this call returns at 70ms on the
> next call, the return is at 7ms.

The first few operations in a new session are necessarily going to be
slower than later ones, because of the need to populate internal caches
etc. If your function is written in a PL you might be able to shave
some time off by preloading the PL's shared library (see
shared_preload_libraries), but that will only go so far. The real
solution to this class of complaints is generally "use a connection
pooler".

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message David G. Johnston 2018-01-11 16:01:43 Re: The first function call
Previous Message Jeremy Finzel 2018-01-11 15:56:32 Identifying ALTER TABLE "sub-command"