public inbox for pgsql-general@postgresql.org  
help / color / mirror / Atom feed
From: Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
To: Igor Korot <ikorot01@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Cc: Rob Sargent <robjsargent@gmail.com>
Subject: Re: Double prepare
Date: Sat, 16 May 2026 17:31:49 +0300
Message-ID: <CAB=Je-HxpyNNbn7girF6Mouf4gmzNQN=jdkrM49VwEtT_uFf4w@mail.gmail.com> (raw)
In-Reply-To: <02D2D7C5-7932-4030-B65A-4BECB645E9F0@gmail.com>
References: <1495292.1778939187@sss.pgh.pa.us>
	<02D2D7C5-7932-4030-B65A-4BECB645E9F0@gmail.com>

>Might there be value in calling PQprepare as late as possible against most
up-to-dare data?
> Or is it better to run PQprepare for all known parameterized queries
> in the very beginning of the program and just execute them when needed?

In pgjdbc we maintain a client-side cache, so we don't have to prepare
everything in advance.
Frankly, I find it was a very helpful tool from the library perspective, as
it automatically optimized applications without
requiring application rebuild. The added prepared statement cache cut the
app server's response times from 1s to 0.5s (think of a generic enterprise
webpage).

Note that sql text is not a sufficient caching key: the same sql text might
have completely different
execution plans depending on the parameter types.

Note that statements prepare per-connection, so if you prepare everything
in advance, there might be noticeable overhead (cpu and memory)
if the specific connection uses only a few queries.

Vladimir


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 using the --to and --cc options:
  reply via email

  To: pgsql-general@postgresql.org
  Cc: sitnikov.vladimir@gmail.com, ikorot01@gmail.com, tgl@sss.pgh.pa.us, pgsql-general@lists.postgresql.org, robjsargent@gmail.com
  Subject: Re: Double prepare
  In-Reply-To: <CAB=Je-HxpyNNbn7girF6Mouf4gmzNQN=jdkrM49VwEtT_uFf4w@mail.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 agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox