Re: Stored procedures - Mailing list pgsql-novice

From David G. Johnston
Subject Re: Stored procedures
Date
Msg-id CAKFQuwa7agwXq=W+eY+52u=4HMYSviQJo=1OVB4HWwxQmmNhxQ@mail.gmail.com
Whole thread Raw
In response to Stored procedures  (Simon Connah <simon.n.connah@protonmail.com>)
List pgsql-novice
On Sunday, August 27, 2023, Simon Connah <simon.n.connah@protonmail.com> wrote:
I'm building a website in Python using the Django framework and am using the ORM at the moment but I can see a few situations where I might need to write raw SQL. My question is do stored procedures execute faster when compared to queries you generate using Python and then send to PostgreSQL? I would assume they would as there is less communication between the two sides and also because PostgreSQL knows the stored procedure ahead of time it should be able to better optimise it.

Is that true? Does PostgreSQL use a JIT for stored procedures which make them faster than one-off queries?

Forget generalities.  Do what makes the most overall sense.  If a specific case seems to need performance optimization then do both and measure.  

If you are using plpgsql as the implementation language, or anything but the atomic SQL format actually, you aren’t avoiding the parsing of the code and are adding overhead that raw SQL doesn’t have.

David J.

pgsql-novice by date:

Previous
From: Simon Connah
Date:
Subject: Stored procedures
Next
From: Gurjeet Singh
Date:
Subject: Re: Stored procedures