Re: slow performance with cursor - Mailing list pgsql-performance

From Tomas Vondra
Subject Re: slow performance with cursor
Date
Msg-id 7a75ebb8-b5bc-81aa-ba9a-7c17abdeb706@enterprisedb.com
Whole thread Raw
In response to Re: slow performance with cursor  (Ayub Khan <ayub.hp@gmail.com>)
List pgsql-performance
On 7/1/21 10:25 PM, Ayub Khan wrote:
> Justin,
> 
> Below is the stored procedure, is there any scope for improvement?
> 

Hard to say, based on just the stored procedure source code. The queries
are not too complex, but we don't know which of them gets selected for
each cursor, and which of them is the slow one.

I suggest you identify which of the cursors is the most problematic one,
and focus on investigating it alone. Show us the explain analyze for
that query with different cursor_tuple_fraction values and without the
cursort, and so on.

As Tom said, for a cursor the optimizer may be picking a plan with low
startup cost, on the basis that that's good for a cursor. But if you're
always consuming all the tuples, that may be inefficient. It's often an
issue for queries with LIMIT, but none of the queries you include that
clause, so who knows ...

Try identifying which of the cursors is causing the issues, show us the
explain analyze for that query (with and without the cursor), and that
should tell us more.


regards

-- 
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



pgsql-performance by date:

Previous
From: David Rowley
Date:
Subject: Re: Planning performance problem (67626.278ms)
Next
From: Merlin Moncure
Date:
Subject: Re: hint in determining effective_io_concurrency