Re: Double prepare

From: Vladimir Sitnikov <sitnikov(dot)vladimir(at)gmail(dot)com>
To: Igor Korot <ikorot01(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>, Rob Sargent <robjsargent(at)gmail(dot)com>
Subject: Re: Double prepare
Date: 2026-05-16 14:31:49
Message-ID: CAB=Je-HxpyNNbn7girF6Mouf4gmzNQN=jdkrM49VwEtT_uFf4w@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

>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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Vladimir Sitnikov 2026-05-16 14:37:38 Re: Double prepare
Previous Message Rob Sargent 2026-05-16 14:07:01 Re: Double prepare