in reply to dbi: prepare vs prepare_cached -- which is best ?

To your questions there is only one answer. "It depends".

  1. The database driver (DBD) is free to contact the server for compilation. For example if the client library is a very thin network layer, it doesn't know about the tables on the server or the query plan. It must then contact the DB server to compile the query and check it for correctness.
  2. If you define the measure by which you want to measure "best", we can possibly help you better.
  3. You will have to make that comparison with your database, your queries and your data. Most likely, prepare_cached will be faster or just as fast as prepare, as the overhead of looking in the cache will be negligible. But if you have lots of queries and don't use placeholders, the situation might be different. Again, with such a general question, it's hard to give specific answers.