yugabyte / jdbc-yugabytedb

JDBC Driver for Yugabyte SQL (YSQL)
BSD 2-Clause "Simplified" License
17 stars 7 forks source link

Executing a prepared statement creates prepared statement after 5 executions #9

Open fritshoogland-yugabyte opened 3 years ago

fritshoogland-yugabyte commented 3 years ago

When a statement explicitly created as preparedStatement is executed, it will be executed as non-prepared statement for 5 times. After the fifth time, JDBC will create a server-side prepared statement. This behavior is controlled by the property prepareThreshold, which is set to 5 by default.

This is illogical behavior, if a statement is declared as prepared statement, it should result in a server-side prepared statement as well. Therefore my suggestion is to change the default threshold value to 1, so a server-side prepared statement is created together with the client-side prepared statement object.

By changing the default the behavior becomes more logical, and more efficient because when the java programmer intended to prepare a statement and bind and execute it multiple times, it will actually do that server side too. And the old behavior if needed can always be changed back by explicitly setting it.