pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Christoph Moench-Tegeder <cmt@burggraben.net>
To: Ron <ronljohnsonjr@gmail.com>
Cc: pgsql-general list <pgsql-general@lists.postgresql.org>
Subject: Re: Example code Re: Singleton SELECT inside cursor loop
Date: Sat, 1 Oct 2022 14:21:15 +0200
Message-ID: <Yzgwu2MHvqlfkdwH@elch.exwg.net> (raw)
In-Reply-To: <d0f2c884-db0f-826f-a4e2-24a5e31130d8@gmail.com>
References: <ee9f6dc7-281d-f2a1-2556-54d36fd96e91@gmail.com>
	<d0f2c884-db0f-826f-a4e2-24a5e31130d8@gmail.com>

## Ron (ronljohnsonjr@gmail.com):

> Note how quickly it runs the first five times, but takes 780x longer the 
> sixth time I run it.  Exiting psql and entering again causes the same 
> slowness the sixth time it's run.

Tanks at the sixth time? That rings a bell: "The current rule for this
is that the first five executions are done with custom plans[...]" from
https://www.postgresql.org/docs/12/sql-prepare.html
And your functions create prepared statements under the hood:
https://www.postgresql.org/docs/12/plpgsql-implementation.html#PLPGSQL-PLAN-CACHING
I guess you should visit
https://www.postgresql.org/docs/12/runtime-config-query.html#GUC-PLAN-CACHE_MODE
and try if plan_cache_mode = force_custom_plan helps here.

Regards,
Christoph

-- 
Spare Space





view thread (8+ messages)  latest in thread

Message-ID: <Yzgwu2MHvqlfkdwH@elch.exwg.net>
Permalink:  ../Yzgwu2MHvqlfkdwH@elch.exwg.net/
Also on:    postgresql.org/message-id/Yzgwu2MHvqlfkdwH@elch.exwg.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: cmt@burggraben.net, ronljohnsonjr@gmail.com
  Subject: Re: Example code Re: Singleton SELECT inside cursor loop
  In-Reply-To: <Yzgwu2MHvqlfkdwH@elch.exwg.net>
  References: <ee9f6dc7-281d-f2a1-2556-54d36fd96e91@gmail.com> <d0f2c884-db0f-826f-a4e2-24a5e31130d8@gmail.com> <Yzgwu2MHvqlfkdwH@elch.exwg.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox