>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
