不支持引用外部变量
不执行接收多个结果集,只返回第一个结果集,从第二个结果集开始丢弃
1.21-2021-12-21存储过程支持多结果集返回
支持接收affectRow

由于客户端对存储过程的实现不同,也与mysql版本有关系,注意设置mycat模拟的mysql版本
需要支持更多情况请咨询mycat2作者

1.通过路由控制注释调用存储过程

透传SQL下发(不经过SQL优化器处理)

  1. /*+ MYCAT:TARGET(c0) */ {call xxxxx}
  2. /*+ MYCAT:TARGET(c1,c2) */ {call xxxxx}

参数为集群名字或数据源名字,该注释不会修改sql,而是直接把sql直接发送到多个集群或者数据源,它不支持返回结果集的存储过程,仅支持无结果集的存储过程

2.通过配置普通存储过程,实现存储过程映射

  1. {
  2. "customTables":{},
  3. "globalTables":{},
  4. "normalProcedures":{
  5. "delete_matches":{
  6. "createProcedureSQL":"CREATE PROCEDURE mysql.`delete_matches` (\n\tIN p_id INTEGER\n)\nBEGIN\n\tDELETE FROM db1.`travelrecord`\n\tWHERE id = p_id;\nEND",
  7. "locality":{
  8. "procedureName":"delete_matches",
  9. "schemaName":"mysql",
  10. "targetName":"prototype"
  11. }
  12. }
  13. },
  14. "schemaName":"mysql",
  15. "shardingTables":{},
  16. "targetName":"prototype"
  17. }

该配置可以实现把逻辑库mysql的delete_matches存储过程映射到集群prototype的物理库mysql的delete_matches
它支持暂时返回一个结果集的存储过程,也支持无结果集的存储过程,后面会完善多结果集等情况.

3.直接使用存储过程创建,在客户端执行创建存储过程,即可自动进行上述2的配置,但是集群默认是prototype

  1. execute(mycatConnection,"DROP PROCEDURE IF EXISTS mysql.`select_matches`");
  2. String s = " CREATE PROCEDURE mysql.`select_matches`(\n" +
  3. "\tIN p_id INTEGER\n" +
  4. ")\n" +
  5. "BEGIN\n" +
  6. "select * FROM db1.`travelrecord` WHERE id = p_id;\n" +
  7. "END";
  8. execute(mycatConnection, s);
  9. deleteData(mycatConnection,"db1","travelrecord");
  10. execute(mycatConnection, "INSERT INTO `db1`.`travelrecord` (`id`) VALUES ('1');");
  11. CallableStatement callableStatement = mycatConnection.prepareCall(" CALL mysql.select_matches(1)");
  12. boolean execute = callableStatement.execute();
  13. Assert.assertTrue(execute);
  14. ResultSet resultSet = callableStatement.getResultSet();
  15. boolean next = resultSet.next();
  16. Assert.assertTrue(next);

4.支持全局,分片存储过程(后续)