pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general list <pgsql-general@lists.postgresql.org>
Subject: Example code Re: Singleton SELECT inside cursor loop
Date: Sat, 1 Oct 2022 02:22:22 -0500
Message-ID: <d0f2c884-db0f-826f-a4e2-24a5e31130d8@gmail.com> (raw)
In-Reply-To: <ee9f6dc7-281d-f2a1-2556-54d36fd96e91@gmail.com>
References: <ee9f6dc7-281d-f2a1-2556-54d36fd96e91@gmail.com>

I extracted the singleton into a function, and that helped me isolate the 
problem.

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.

sides=> select strans.TASK001785639(1, 507650, '2022-08-01', '2022-08-31');
task001785639
---------------
            498
(1 row)

sides=> select strans.TASK001785639(1, 507650, '2022-08-01', '2022-08-31');
task001785639
---------------
            498
(1 row)

sides=> \timing
Timing is on.

sides=> select strans.TASK001785639(1, 507650, '2022-08-01', '2022-08-31');
task001785639
---------------
            498
(1 row)

Time: 457.325 ms

sides=> select strans.TASK001785639(1, 507650, '2022-08-01', '2022-08-31');
task001785639
---------------
            498
(1 row)

Time: 459.724 ms

sides=> select strans.TASK001785639(1, 507650, '2022-08-01', '2022-08-31');
task001785639
---------------
            498
(1 row)

Time: 461.155 ms

sides=> select strans.TASK001785639(1, 507650, '2022-08-01', '2022-08-31');
task001785639
---------------
            498
(1 row)

Time: 358426.159 ms (05:58.426)


On 10/1/22 01:29, Ron wrote:
> AWS RDS Postgresql 12.11
>
> It runs quickly, no matter what the fetched cursor values are, as long as 
> the cursor returns less than 8 rows.  After that, the singleton SELECT's 
> performance tanks.
>
> We've got plenty of other procedures which have a similar "Singleton 
> SELECT inside a cursor" design (many even query the same table that the 
> problematic query does), but only this procedure's singleton SELECT tanks 
> if the cursor returns more than 8 rows.
>
> It only runs once a month, so we've only just noticed the problem.
>
> Why would that be?  (We recently updated from 12.10 to 12.11, if that's 
> relevant.)
>

-- 
Angular momentum makes the world go 'round.

Attachments:

  TASK001785639_function.sql (application/sql, 2.3K) download

view thread (8+ messages)  latest in thread

Message-ID: <d0f2c884-db0f-826f-a4e2-24a5e31130d8@gmail.com>
Permalink:  ../d0f2c884-db0f-826f-a4e2-24a5e31130d8@gmail.com/
Also on:    postgresql.org/message-id/d0f2c884-db0f-826f-a4e2-24a5e31130d8@gmail.com

 · 

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: ronljohnsonjr@gmail.com
  Subject: Re: Example code Re: Singleton SELECT inside cursor loop
  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>

* 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