mybatis/callablestatement调用存储过程mysql connector产生不必要的元数据查询
INFO | jvm 1 | 2016/08/25 15:17:01 | 16-08-25 15:17:01 DEBUG pool-1-thread-371dao.ITaskDao.callProcedure: ==> Preparing: call sp_one( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? );
INFO | jvm 1 | 2016/08/25 15:17:01 | 16-08-25 15:17:01 DEBUG pool-1-thread-371 dao.ITaskDao.callProcedure: ==> Parameters: 9999(Integer), 9901(Integer),=(String), task(String), T(String), 1000(Integer), sysL.1.19(String), 13(Integer), 469047(Integer), 20160825(Integer), 151700(Integer)
INFO | jvm 1 | 2016/08/25 15:17:01 | 16-08-25 15:17:01 DEBUG pool-1-thread-371.dao.ITaskDao.callProcedure: <== Total: 1
INFO | jvm 1 | 2016/08/25 15:17:01 | 16-08-25 15:17:01 DEBUG pool-1-thread-371dao.ITaskDao.callProcedure: <== Updates: 0
mysql general_log中可以发现如下元数据查询语句:
SELECT name, type, comment FROM mysql.proc WHERE name like...
SHOW FUNCTION STATUS LIKE 'sp_one'
SHOW PROCEDURE STATUS LIKE 'sp_one'
SHOW CREATE PROCEDURE `db-name`.`sp_one`
CALL sp_one()
因为我们使用了大量的存储过程,而且很多过程执行非常快,因此导致查询这些元数据本身成了响应时间中很大的一部分,如下所示:

根据https://www.percona.com/blog/2006/08/02/mysql-prepared-statements/所述,mysql的Prepare Statements目前好像只能如此,原生mysql jdbc驱动也没支持改进。MariaDB Connector/J倒是进行了优化。
需要使用最古老的
stmt = conn.createStatement();
rs = stmt.executeQuery("call sp_one('a','b')");才能解决该问题。
mybatis的实现中,CALLABLE直接调用了callablestatement,没法直接运行,如下:
CallableStatement cs = (CallableStatement)statement;
cs.execute();
int rows = cs.getUpdateCount();
看来目前只能使用mariadb connector了,就怕这不稳定要么有特定bug存在。。。
我们使用的mysql connector版本是5.1.34。希望后续版本能够优化掉问题。
=============
170222更新
这个最近我们已经解决了,在jdbc.url连接串中增加选项如下:
cachePrepStmts=true
cacheCallableStmts=true
cacheServerConfiguration=true
useLocalSessionState=true
elideSetAutoCommits=false
alwaysSendSetIsolation=false
enableQueryTimeouts=false
useConfigs=maxPerformance有bug https://bugs.mysql.com/bug.php?id=70785等待下一版本发布解决。
如下,大量日志都没有了
2017-02-22T18:47:51.004298+08:00 31744 Query SELECT * FROM `c3potest`
2017-02-22T18:47:51.004677+08:00 31753 Query SELECT * FROM `c3potest`
2017-02-22T18:47:51.840092+08:00 30929 Query SELECT * FROM `c3potest`
2017-02-22T18:47:51.840828+08:00 30929 Query call prl_QueryUniteQuitiesPosition(
7777,77770002,'YWQzYzM3ZTlkOTNjYzFlNzJjNWEzNzUzNDc2OGUyYTI=','101.69.255.190:41723>=ld-web','7',806003,'actL.2.7',7777,0,' ',0,'',0,'',0,0,@com_mysql_jdbc_outparam_p_error_code,@com_mysql_jdbc_outparam_p_error_info
)
2017-02-22T18:47:51.846647+08:00 30929 Query SELECT @com_mysql_jdbc_outparam_p_error_code,@com_mysql_jdbc_outparam_p_error_info
2017-02-22T18:47:51.847462+08:00 30929 Query SELECT * FROM `c3potest`
2017-02-22T18:47:52.001402+08:00 31753 Query select * from tb_sys_task
2017-02-22T18:47:52.003294+08:00 31744 Query select unix_timestamp()
最新版本的5.1.41已经发布,意味着可以使用useConfigs=maxPerformance了,同时,elideSetAutoCommits因为bug被弃用。
mybatis/callablestatement调用存储过程mysql connector产生不必要的元数据查询的更多相关文章
- mysql jdbc性能优化之mybatis/callablestatement调用存储过程mysql jdbc产生不必要的元数据查询(已解决,cpu负载减少20%)
INFO | jvm 1 | 2016/08/25 15:17:01 | 16-08-25 15:17:01 DEBUG pool-1-thread-371dao.ITaskDao.callProce ...
- MyBatis中调用存储过程和函数
一.调用存储过程 1.首先在数据库中定义存储过程,定义的存储过程的代码如下: //定义存储过程 create or replace procedure pag_add(p1 varchar2,p2 v ...
- java调用存储过程mysql
在java中调用带返回值的存储过程的实现 直接上代码: DELIMITER $$ CREATE /*[DEFINER = { user | CURRENT_USER }]*/ PROCEDURE `t ...
- SpringMvc+Mybatis开发调用存储过程
<mapper namespace="com.jkw100.ssm.mapper.CustomerMapperCustom" > <!-- statementTy ...
- mybatis注解调用存储过程
mapper @SelectProvider(type = RoleMenuSqlProvider.class,method = "updateRoleMenuRelation") ...
- 在mybatis中调用存储过程的时候,不能加工语句
select count(0) from ({call pkg_business.P_ZZS_LYFPHJSKJQK ('2018-04')}) 这是错误的.
- jdbc中的Statement对象和Preparedstatement对象的区别,以及通过jdbc操作调用存储过程
一. java.sql.* 和 javax.sql.*的包的类结构 |- Driver接口: 表示java驱动程序接口.所有的具体的数据库厂商要来实现此接口. |- connect(url, p ...
- java 通过调用存储过程获取结果集
一般在java中,数据查询是通过Statement, PreparedStatement获取结果集,今天向大家介绍通过CallableStatement调用存储过程,从而获取结果集. 本 ...
- Java代码调用存储过程和存储方法
准备一个oracle 的JDBC jar 包:ojdbc14_11g.jar 首先找到你的 oracle 安装位置,例如: 1.创建一个JDBC数据库连接工具类: package com.test.d ...
随机推荐
- saiku 展示优化
saiku版本:3.7.4 下面是修改步骤,如果觉得麻烦,可以直接下载源代码:https://github.com/lihehuo/saiku 1.关闭自动执行 修改文件:saiku-ui/js/sa ...
- CSS 会被继承的属性
文本 color(颜色,a元素除外) direction(方向) font(字体) font-family(字体系列) font-size(字体大小) font-style(用于设置斜体) font- ...
- java之对象转型2
public class TestCasting2{ public static void main(String args[]){ TestCasting2 test2= new TestCasti ...
- Android对话框之dismiss和cancel和hide区别
在我们看来两者效果都是一样的,其实看下源码就知道cancel肯定会去调dismiss的,如果调用的cancel的话就可以监听DialogInterface.OnCancelListener. /** ...
- 一种高效的 vector 四则运算处理方法
实现 vector 的四则运算 这里假设 vector 的运算定义为对操作数 vector 中相同位置的元素进行运算,最后得到一个新的 vector.具体来说就是,假如 vector<int&g ...
- 《Programming with Objective-C》第三章 Working with Objects
Object和普通变量的区别 If you’re used to using terms like the stack and the heap, a local variable is alloca ...
- JavaScript面试库
1.将一段字符串转成驼峰命名法. var str = "web-kit-index"; function to(str){ var j = str.split("-&qu ...
- STL中priority_queue小结
(1)为了运用priority_queue,你必须包含头文件<queue>:#include<queue> (2)在头文件中priority_queue定义如下: namesp ...
- sqlserver -- 学习笔记(四)将一个数据库的表复制到另外一个数据库(备忘)
--复制结构+数据 select * into 数据库名.dbo.新表名 from 数据库名.dbo.原表名 select * into Stockholder.dbo.SHInfo from dsp ...
- DDD:建模原语 之 四象图(转载的神文)
“模型.状态和行为特征.场景”和“四象图”,建模观的命名与立象. 建模原语:四象图 作者:achieveidea@gmail.com 命名:模型.结构特征.行为特征.场景(及其规约). 释义:模型,描 ...