Unsupported command: [COM_SET_OPTION] happened while execute batch delete
Bug Report
Which version of ShardingSphere did you use?
5.0.0-RC1-SNAPSHOT
Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
ShardingSphere-Proxy
Expected behavior
I want execute some batch delete by proxy, but it failed.
private void executeBatchDelete(final Connection connection, final List<DataRecord> dataRecords) throws SQLException {
PreparedStatement ps = connection.prepareStatement(deleteSQL);
ps.setQueryTimeout(30);
for (DataRecord each : dataRecords) {
conditionColumns = RecordUtil.extractConditionColumns(each, importerConfig.getShardingColumnsMap().get(each.getTableName()));
for (int i = 0; i < conditionColumns.size(); i++) {
ps.setObject(i + 1, conditionColumns.get(i).getValue());
}
ps.addBatch();
}
ps.executeBatch(); // throw a SQLException
}
Actual behavior
java.sql.SQLException: 1Unsupported command: [COM_SET_OPTION]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3978)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3914)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2530)
at com.mysql.jdbc.MysqlIO.disableMultiQueries(MysqlIO.java:3670)
at com.mysql.jdbc.PreparedStatement.executePreparedBatchAsMultiStatement(PreparedStatement.java:1492)
at com.mysql.jdbc.PreparedStatement.executeBatchInternal(PreparedStatement.java:1303)
at com.mysql.jdbc.StatementImpl.executeBatch(StatementImpl.java:970)
at com.zaxxer.hikari.pool.ProxyStatement.executeBatch(ProxyStatement.java:131)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeBatch(HikariProxyPreparedStatement.java)
at org.apache.shardingsphere.scaling.core.execute.executor.importer.AbstractJDBCImporter.executeBatchDelete(AbstractJDBCImporter.java:205)
@Lucas-307 Proxy does not support COM_SET_OPTION for now. You can try to add client jdbc parameters rewriteBatchedStatements=true and allowMultiQueries=true to avoid this problem.
@tuohai666 If I add rewriteBatchedStatements=true and allowMultiQueries=true parameters, the sql will concat all delete sql like:
DELETE FROM `t_order_0` WHERE `id` = 196 and `user_id` = 196;DELETE FROM `t_order` WHERE `id` = 190 and `user_id` = 190;
Only the first table name is correct, Which stall fail.
+1 I want execute some batch update by proxy, but it failed.
then, i can think execute every jdbc batch curd SQL,all failed ?
Which version of ShardingSphere did you use? 5.0.0
Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy? ShardingSphere-Proxy
Use proxy encrypt rule !
Expected behavior
[ERROR] 2021-12-02 04:02:00.812 [ShardingSphere-Command-2] o.a.s.p.f.c.CommandExecutorTask - Exception occur:
org.apache.shardingsphere.proxy.frontend.exception.UnsupportedCommandException: null
at org.apache.shardingsphere.proxy.frontend.mysql.command.generic.MySQLUnsupportedCommandExecutor.execute(MySQLUnsupportedCommandExecutor.java:38)
at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.executeCommand(CommandExecutorTask.java:99)
at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.run$original$2rlLGs13(CommandExecutorTask.java:72)
at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.run$original$2rlLGs13$accessor$ljl4ueK8(CommandExecutorTask.java)
at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask$auxiliary$Qcyejbxt.call(Unknown Source)
at org.apache.shardingsphere.agent.core.plugin.interceptor.InstanceMethodAroundInterceptor.intercept(InstanceMethodAroundInterceptor.java:75)
at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.run(CommandExecutorTask.java)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Can you tell me how to reproduce this error? I didn't find this problem after trying
ShardingSphere master batch MySQL 5.7 Zookeeper 3.7
Case 1: Execute batch delete using proxy Result: No issues found
import java.sql.Connection
import java.sql.Driver
import java.sql.PreparedStatement
Class clazz = Class.forName("com.mysql.jdbc.Driver");
Driver driver = clazz.newInstance() as Driver;
String url = "jdbc:mysql://127.0.0.1:3307/sharding_db?rewriteBatchedStatements=false&allowMultiQueries=false";
Properties info = new Properties();
info.setProperty("user", "root");
info.setProperty("password", "root");
Connection conn = driver.connect(url, info);
String delSQL = "delete from t_order where order_id = ?;"
PreparedStatement ps = conn.prepareStatement(delSQL)
for (i in 0..<5) {
ps.setObject(1, i);
ps.addBatch();
}
def batch = ps.executeBatch()
println batch
Case2:Execute batch delete during incremental data import phase of migration Result: No issues found
import java.sql.Connection
import java.sql.Driver
import java.sql.PreparedStatement
Class clazz = Class.forName("com.mysql.jdbc.Driver");
Driver driver = clazz.newInstance() as Driver;
String url = "jdbc:mysql://127.0.0.1:3307/sharding_db?rewriteBatchedStatements=false&allowMultiQueries=false";
Properties info = new Properties();
info.setProperty("user", "root");
info.setProperty("password", "root");
Connection conn = driver.connect(url, info);
String delSQL = "delete from t_order where order_id = ?;"
PreparedStatement ps = conn.prepareStatement(delSQL)
for (i in 0..<5) {
ps.setObject(1, i);
ps.addBatch();
}
def batch = ps.executeBatch()
println batch
Case3:Execute batch delete during incremental data import phase of migration Result: No issues found
mysql> delete from t_order where order_id = 1;
Query OK, 1 row affected (0.18 sec)
mysql> delete from t_order where order_id = 2;
Query OK, 1 row affected (0.02 sec)
mysql> delete from t_order where order_id = 3;
Query OK, 1 row affected (0.02 sec)
No problem was found in any of the above three cases
We have fix this in #16174, #16268.