Prepared Statement in Java Client

@daschl I’m completely new to Couchbase and I’m very curious about how this works under the hood (both server and the Java sdk). I have the following questions:

  1. Suppose I have multiple front-end servers that use the same prepared statement via this adhoc(false), will the Couchbase server create duplicated prepared statements that are essentially the same? Can it happen that over time, there are too many prepared statements stored in the server?

  2. Is there anyway to give a name to the prepared statement so that all front-end servers will use the same prepared statement? And if yes, is there a way to delete a prepared statement using its name? Couchbase server also creates random names for the prepared statements. How are these handled at the sdk level?

  3. There’s a mention of caching of query plan of the sdk in the doc. So when a statement with adhoc(false) is created, the sdk would search in cache using the statement for a cached query plan and execute it if possible. Otherwise, it will tell the server to execute the plan saved in the server?

Thanks a lot!