Re: possibility to define only local cursors - Mailing list pgsql-hackers

From Pavel Stehule
Subject Re: possibility to define only local cursors
Date
Msg-id CAFj8pRDXr8Q9anAFgcoEu_9cDK8ehWZcCk=VZcvKpfC16hT_gg@mail.gmail.com
Whole thread Raw
In response to possibility to define only local cursors  (Pavel Stehule <pavel.stehule@gmail.com>)
List pgsql-hackers


čt 30. 11. 2023 v 6:45 odesílatel Pavel Stehule <pavel.stehule@gmail.com> napsal:
Hi

one my customer migrated a pretty large application from Oracle, and when did performance tests, he found very high memory usage related probably to unclosed cursors. The overhead is significantly bigger than on Oracle (probably Oracle closes cursors after leaving cursor's variable scope, I don't know. Maybe it just uses a different pattern with shorter transactions on Oracle). He cannot use FOR cycle, because he needs to hold code in form that allows automatic translation from PL/SQL to PL/pgSQL for some years (some years he will support both platforms).

DECLARE qNAJUPOSPL refcursor;
BEGIN
  OPEN qNAJUPOSPL FOR EXECUTE mSqNAJUPOSPL;
  LOOP
    FETCH qNAJUPOSPL INTO mID_NAJVUPOSPL , mID_NAJDATSPLT , mID_PREDPIS;
    EXIT WHEN NOT FOUND; /* apply on qNAJUPOSPL */
  END LOOP;
END;

Because plpgsql and postgres can be referenced just by name then it is not possible to use some reference counters and close cursors when the reference number is zero. Can we introduce some modifier that forces closing the unclosed cursor before the related scope is left?

Some like `DECLATE curvar refcursor LOCAL`

Another way to solve this issue is just warning when the number of opened cursors crosses some limit. Later this warning can be disabled, increased or solved. But investigation of related memory issues can be easy then.

it can be implemented like extra warning for OPEN statement.

 

Comments, notes?

Regards

Pavel




pgsql-hackers by date:

Previous
From: Pavel Stehule
Date:
Subject: possibility to define only local cursors
Next
From: Michael Paquier
Date:
Subject: Re: GUC names in messages