Skip to content

Commit

Permalink
[CONJ-1208] ensure not using pipelining prepare + execute for mysql s…
Browse files Browse the repository at this point in the history
…erver
  • Loading branch information
rusher committed Nov 4, 2024
1 parent 4738d1d commit ce9b23c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 33 deletions.
20 changes: 12 additions & 8 deletions src/main/java/org/mariadb/jdbc/ClientPreparedStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ protected boolean executeInternalPreparedBatch() throws SQLException {
parseCommandIfNeeded(sql);
Configuration conf = con.getContext().getConf();

if (!con.getContext().hasServerCapability(STMT_BULK_OPERATIONS)) {
executeBatchStd();
return false;
}

boolean possibleLoadLocal = con.getContext().hasClientCapability(LOCAL_FILES);
if (possibleLoadLocal) {
String sqlUpper = sql.toUpperCase(Locale.ROOT);
Expand All @@ -136,14 +141,13 @@ protected boolean executeInternalPreparedBatch() throws SQLException {
// * if RETURN_GENERATED_KEYS is expressly set, can only be use if server permit returning
// individual result
boolean canUseBulk =
con.getContext().hasServerCapability(STMT_BULK_OPERATIONS)
&& (((clientParser.isInsert()
&& ((conf.useBulkStmts() || conf.useBulkStmtsForInserts())
&& (con.getContext().hasClientCapability(BULK_UNIT_RESULTS)
|| !clientParser.isInsertDuplicate())))
|| (!clientParser.isInsert() && conf.useBulkStmts()))
&& (con.getContext().hasClientCapability(BULK_UNIT_RESULTS)
|| autoGeneratedKeys != Statement.RETURN_GENERATED_KEYS));
((clientParser.isInsert()
&& ((conf.useBulkStmts() || conf.useBulkStmtsForInserts())
&& (con.getContext().hasClientCapability(BULK_UNIT_RESULTS)
|| !clientParser.isInsertDuplicate())))
|| (!clientParser.isInsert() && conf.useBulkStmts()))
&& (con.getContext().hasClientCapability(BULK_UNIT_RESULTS)
|| autoGeneratedKeys != Statement.RETURN_GENERATED_KEYS);
if (canUseBulk && batchParameters.size() > 1 && !clientParser.isMultiQuery()) {
executeBatchBulk(escapeTimeout(sql));
return true;
Expand Down
53 changes: 28 additions & 25 deletions src/main/java/org/mariadb/jdbc/ServerPreparedStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ protected boolean executeInternalPreparedBatch() throws SQLException {
checkNotClosed();
String cmd = escapeTimeout(sql);

if (!con.getContext().hasServerCapability(STMT_BULK_OPERATIONS)) {
executeBatchStandard(cmd);
return false;
}
// ensure pipelining is possible (no LOAD DATA/XML INFILE commands)
boolean possibleLoadLocal = con.getContext().hasClientCapability(LOCAL_FILES);
if (possibleLoadLocal) {
Expand All @@ -173,33 +177,32 @@ protected boolean executeInternalPreparedBatch() throws SQLException {

if (possibleLoadLocal) {
executeBatchStandard(cmd);
} else {
Configuration conf = con.getContext().getConf();
parseCommandIfNeeded(sql);

// a bit complex:
// * bulk on INSERT ON DUPLICATE KEY UPDATE can only be use if server permit returning
// individual result, since affected rows cannot be guessed
// * if RETURN_GENERATED_KEYS is expressly set, can only be use if server permit returning
// individual result
boolean canUseBulk =
con.getContext().hasServerCapability(STMT_BULK_OPERATIONS)
&& (((clientParser.isInsert()
&& ((conf.useBulkStmts() || conf.useBulkStmtsForInserts())
&& (con.getContext().hasClientCapability(BULK_UNIT_RESULTS)
|| !clientParser.isInsertDuplicate())))
|| (!clientParser.isInsert() && conf.useBulkStmts()))
&& (con.getContext().hasClientCapability(BULK_UNIT_RESULTS)
|| autoGeneratedKeys != Statement.RETURN_GENERATED_KEYS));
if (canUseBulk && batchParameters.size() > 1) {
executeBatchBulk(cmd);
return true;
} else {
executeBatchPipeline(cmd);
}
return false;
}

return false;
Configuration conf = con.getContext().getConf();
parseCommandIfNeeded(sql);

// a bit complex:
// * bulk on INSERT ON DUPLICATE KEY UPDATE can only be use if server permit returning
// individual result, since affected rows cannot be guessed
// * if RETURN_GENERATED_KEYS is expressly set, can only be use if server permit returning
// individual result
boolean canUseBulk =
((clientParser.isInsert()
&& ((conf.useBulkStmts() || conf.useBulkStmtsForInserts())
&& (con.getContext().hasClientCapability(BULK_UNIT_RESULTS)
|| !clientParser.isInsertDuplicate())))
|| (!clientParser.isInsert() && conf.useBulkStmts()))
&& (con.getContext().hasClientCapability(BULK_UNIT_RESULTS)
|| autoGeneratedKeys != Statement.RETURN_GENERATED_KEYS);
if (canUseBulk && batchParameters.size() > 1) {
executeBatchBulk(cmd);
return true;
} else {
executeBatchPipeline(cmd);
return false;
}
}

/**
Expand Down

0 comments on commit ce9b23c

Please sign in to comment.