0 0

mybatis执行效率慢。15

订单

//Controller层.
void  testAction(){
 int count1 = mapper.queryGoodsByShopIdAndFirstTypeIdCount(map1);//语句1
 service1();
}

//Service层
void service1(){
 int count1 = mapper.queryGoodsByShopIdAndFirstTypeIdCount(map2);//语句2

 int count1 = mapper.queryGoodsByShopIdAndFirstTypeIdCount(map3);//语句3

}


其中语句1,语句2,语句3都是model层的mybatis接口.执行的是相同的sql语句.语句1和语句3耗时都是30ms,语句2耗时达到2000ms多.请问这是怎么回事??、




为方便,日志文件如下所示:

2014-08-14 18:06:32,062 DEBUG [com.blin360.interceptor.LogInterceptor] - <调用接口ServletPath=/blBusinessShop/queryShopDetailByShopIdAndFirstTypeId.do,输入的参数是:page=1,shopId=1216,firstTypeId=2,>
2014-08-14 18:06:32,062 DEBUG [com.blin360.interceptor.LogInterceptor] - <调用接口ServletPath=/blBusinessShop/queryShopDetailByShopIdAndFirstTypeId.do,输入的参数是:page=1,shopId=1216,firstTypeId=2,>
2014-08-14 18:06:32,062 DEBUG [org.mybatis.spring.SqlSessionUtils] - <Creating a new SqlSession>
2014-08-14 18:06:32,062 DEBUG [org.mybatis.spring.SqlSessionUtils] - <Creating a new SqlSession>
2014-08-14 18:06:32,062 DEBUG [org.mybatis.spring.SqlSessionUtils] - <SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@8b49e4] was not registered for synchronization because synchronization is not active>
2014-08-14 18:06:32,062 DEBUG [org.mybatis.spring.SqlSessionUtils] - <SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@8b49e4] was not registered for synchronization because synchronization is not active>
2014-08-14 18:06:32,093 DEBUG [org.mybatis.spring.transaction.SpringManagedTransaction] - <JDBC Connection [jdbc:mysql://192.168.1.222:3306/blin360?useUnicode=true&charaterEncoding=utf-8, UserName=root@192.168.1.210, MySQL-AB JDBC Driver] will not be managed by Spring>
2014-08-14 18:06:32,093 DEBUG [org.mybatis.spring.transaction.SpringManagedTransaction] - <JDBC Connection [jdbc:mysql://192.168.1.222:3306/blin360?useUnicode=true&charaterEncoding=utf-8, UserName=root@192.168.1.210, MySQL-AB JDBC Driver] will not be managed by Spring>
2014-08-14 18:06:32,093 DEBUG [com.blin360.mapper.BlGoodsMapper.queryGoodsByShopIdAndFirstTypeIdCount] - <ooo Using Connection [jdbc:mysql://192.168.1.222:3306/blin360?useUnicode=true&charaterEncoding=utf-8, UserName=root@192.168.1.210, MySQL-AB JDBC Driver]>
2014-08-14 18:06:32,093 DEBUG [com.blin360.mapper.BlGoodsMapper.queryGoodsByShopIdAndFirstTypeIdCount] - <ooo Using Connection [jdbc:mysql://192.168.1.222:3306/blin360?useUnicode=true&charaterEncoding=utf-8, UserName=root@192.168.1.210, MySQL-AB JDBC Driver]>
2014-08-14 18:06:32,093 DEBUG [com.blin360.mapper.BlGoodsMapper.queryGoodsByShopIdAndFirstTypeIdCount] - <==>  Preparing: select count('id') from bl_business_goods blbusgoods,bl_goods goods,bl_img where blbusgoods.goodId=goods.id AND goods.typeId in(select id from bl_goods_type where type=?) AND blbusgoods.state='0' AND bl_img.goodId=goods.id AND bl_img.type='0' AND blbusgoods.shopId=? >
2014-08-14 18:06:32,093 DEBUG [com.blin360.mapper.BlGoodsMapper.queryGoodsByShopIdAndFirstTypeIdCount] - <==>  Preparing: select count('id') from bl_business_goods blbusgoods,bl_goods goods,bl_img where blbusgoods.goodId=goods.id AND goods.typeId in(select id from bl_goods_type where type=?) AND blbusgoods.state='0' AND bl_img.goodId=goods.id AND bl_img.type='0' AND blbusgoods.shopId=? >
2014-08-14 18:06:32,093 DEBUG [com.blin360.mapper.BlGoodsMapper.queryGoodsByShopIdAndFirstTypeIdCount] - <==> Parameters: 5(Integer), 1216(Integer)>
2014-08-14 18:06:32,093 DEBUG [com.blin360.mapper.BlGoodsMapper.queryGoodsByShopIdAndFirstTypeIdCount] - <==> Parameters: 5(Integer), 1216(Integer)>
2014-08-14 18:06:32,093 DEBUG [org.mybatis.spring.SqlSessionUtils] - <Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@8b49e4]>
2014-08-14 18:06:32,093 DEBUG [org.mybatis.spring.SqlSessionUtils] - <Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@8b49e4]>
2014-08-14 18:06:32,093 DEBUG [com.blin360.action.BlBusinessShopAction] - <第一次测试  查询shopId=1216 一级目录Id=5 下面所有的商品数量=189,耗时31ms>
2014-08-14 18:06:32,093 DEBUG [com.blin360.action.BlBusinessShopAction] - <第一次测试  查询shopId=1216 一级目录Id=5 下面所有的商品数量=189,耗时31ms>
2014-08-14 18:06:32,093 DEBUG [org.mybatis.spring.SqlSessionUtils] - <Creating a new SqlSession>
2014-08-14 18:06:32,093 DEBUG [org.mybatis.spring.SqlSessionUtils] - <Creating a new SqlSession>
2014-08-14 18:06:32,093 DEBUG [org.mybatis.spring.SqlSessionUtils] - <Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@121cef5]>
2014-08-14 18:06:32,093 DEBUG [org.mybatis.spring.SqlSessionUtils] - <Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@121cef5]>
2014-08-14 18:06:32,093 DEBUG [org.mybatis.spring.transaction.SpringManagedTransaction] - <JDBC Connection [jdbc:mysql://192.168.1.222:3306/blin360?useUnicode=true&charaterEncoding=utf-8, UserName=root@192.168.1.210, MySQL-AB JDBC Driver] will be managed by Spring>
2014-08-14 18:06:32,093 DEBUG [org.mybatis.spring.transaction.SpringManagedTransaction] - <JDBC Connection [jdbc:mysql://192.168.1.222:3306/blin360?useUnicode=true&charaterEncoding=utf-8, UserName=root@192.168.1.210, MySQL-AB JDBC Driver] will be managed by Spring>
2014-08-14 18:06:32,093 DEBUG [com.blin360.mapper.BlGoodsMapper.queryGoodsByShopIdAndFirstTypeIdCount] - <ooo Using Connection [jdbc:mysql://192.168.1.222:3306/blin360?useUnicode=true&charaterEncoding=utf-8, UserName=root@192.168.1.210, MySQL-AB JDBC Driver]>
2014-08-14 18:06:32,093 DEBUG [com.blin360.mapper.BlGoodsMapper.queryGoodsByShopIdAndFirstTypeIdCount] - <ooo Using Connection [jdbc:mysql://192.168.1.222:3306/blin360?useUnicode=true&charaterEncoding=utf-8, UserName=root@192.168.1.210, MySQL-AB JDBC Driver]>
2014-08-14 18:06:32,093 DEBUG [com.blin360.mapper.BlGoodsMapper.queryGoodsByShopIdAndFirstTypeIdCount] - <==>  Preparing: select count('id') from bl_business_goods blbusgoods,bl_goods goods,bl_img where blbusgoods.goodId=goods.id AND goods.typeId in(select id from bl_goods_type where type=?) AND blbusgoods.state='0' AND bl_img.goodId=goods.id AND bl_img.type='0' AND blbusgoods.shopId=? >
2014-08-14 18:06:32,093 DEBUG [com.blin360.mapper.BlGoodsMapper.queryGoodsByShopIdAndFirstTypeIdCount] - <==>  Preparing: select count('id') from bl_business_goods blbusgoods,bl_goods goods,bl_img where blbusgoods.goodId=goods.id AND goods.typeId in(select id from bl_goods_type where type=?) AND blbusgoods.state='0' AND bl_img.goodId=goods.id AND bl_img.type='0' AND blbusgoods.shopId=? >
2014-08-14 18:06:32,093 DEBUG [com.blin360.mapper.BlGoodsMapper.queryGoodsByShopIdAndFirstTypeIdCount] - <==> Parameters: 5(Integer), 1216(Integer)>
2014-08-14 18:06:32,093 DEBUG [com.blin360.mapper.BlGoodsMapper.queryGoodsByShopIdAndFirstTypeIdCount] - <==> Parameters: 5(Integer), 1216(Integer)>
2014-08-14 18:06:34,796 DEBUG [org.mybatis.spring.SqlSessionUtils] - <Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@121cef5]>
2014-08-14 18:06:34,796 DEBUG [org.mybatis.spring.SqlSessionUtils] - <Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@121cef5]>
2014-08-14 18:06:34,796 DEBUG [com.blin360.service.BlGoodsService] - <测试  查询shopId=1216 一级目录Id=2 下面所有的商品数量=189,耗时2703ms>
2014-08-14 18:06:34,796 DEBUG [com.blin360.service.BlGoodsService] - <测试  查询shopId=1216 一级目录Id=2 下面所有的商品数量=189,耗时2703ms>
2014-08-14 18:06:34,796 DEBUG [org.mybatis.spring.SqlSessionUtils] - <Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@121cef5] from current transaction>
2014-08-14 18:06:34,796 DEBUG [org.mybatis.spring.SqlSessionUtils] - <Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@121cef5] from current transaction>
2014-08-14 18:06:34,828 DEBUG [com.blin360.mapper.BlGoodsMapper.queryGoodsByShopIdAndFirstTypeIdCount] - <ooo Using Connection [jdbc:mysql://192.168.1.222:3306/blin360?useUnicode=true&charaterEncoding=utf-8, UserName=root@192.168.1.210, MySQL-AB JDBC Driver]>
2014-08-14 18:06:34,828 DEBUG [com.blin360.mapper.BlGoodsMapper.queryGoodsByShopIdAndFirstTypeIdCount] - <ooo Using Connection [jdbc:mysql://192.168.1.222:3306/blin360?useUnicode=true&charaterEncoding=utf-8, UserName=root@192.168.1.210, MySQL-AB JDBC Driver]>
2014-08-14 18:06:34,828 DEBUG [com.blin360.mapper.BlGoodsMapper.queryGoodsByShopIdAndFirstTypeIdCount] - <==>  Preparing: select count('id') from bl_business_goods blbusgoods,bl_goods goods,bl_img where blbusgoods.goodId=goods.id AND goods.typeId in(select id from bl_goods_type where type=?) AND blbusgoods.state='0' AND bl_img.goodId=goods.id AND bl_img.type='0' AND blbusgoods.shopId=? >
2014-08-14 18:06:34,828 DEBUG [com.blin360.mapper.BlGoodsMapper.queryGoodsByShopIdAndFirstTypeIdCount] - <==>  Preparing: select count('id') from bl_business_goods blbusgoods,bl_goods goods,bl_img where blbusgoods.goodId=goods.id AND goods.typeId in(select id from bl_goods_type where type=?) AND blbusgoods.state='0' AND bl_img.goodId=goods.id AND bl_img.type='0' AND blbusgoods.shopId=? >
2014-08-14 18:06:34,828 DEBUG [com.blin360.mapper.BlGoodsMapper.queryGoodsByShopIdAndFirstTypeIdCount] - <==> Parameters: 2(Integer), 1216(Integer)>
2014-08-14 18:06:34,828 DEBUG [com.blin360.mapper.BlGoodsMapper.queryGoodsByShopIdAndFirstTypeIdCount] - <==> Parameters: 2(Integer), 1216(Integer)>
2014-08-14 18:06:34,828 DEBUG [org.mybatis.spring.SqlSessionUtils] - <Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@121cef5]>
2014-08-14 18:06:34,828 DEBUG [org.mybatis.spring.SqlSessionUtils] - <Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@121cef5]>
2014-08-14 18:06:34,828 DEBUG [com.blin360.service.BlGoodsService] - <手工耗时32 ms>
2014-08-14 18:06:34,828 DEBUG [com.blin360.service.BlGoodsService] - <手工耗时32 ms>
2014-08-14 18:06:34,828 DEBUG [com.blin360.service.BlGoodsService] - <查询shopId=1216 一级目录Id=2 下面所有的商品数量=561,耗时32ms>
2014-08-14 18:06:34,828 DEBUG [com.blin360.service.BlGoodsService] - <查询shopId=1216 一级目录Id=2 下面所有的商品数量=561,耗时32ms>






2014年8月14日 18:21

1个答案 按时间排序 按投票排序

0 0

这个和Ibatis没关系,我猜应该是输入参数不一样,影响了数据库的查询性能.

你可以通过如下方式来验证:不通过Java来运行SQL,直接把SQL+参数写到数据库客户端去运行,看看性能是不是和Java调用一样.如果这样验证完了,就是SQL问题了.

如果是SQL问题,比如跨分区,或者是需要扫描的数据块多少差别大,那就要根据情况进行SQL优化了.

你也可以把SQL发出来看看.

2014年8月16日 23:20

相关推荐

    mybatis-plus优缺点

    13. **性能分析插件**:可以输出SQL语句及其执行时间,帮助开发人员优化慢查询。 14. **全局拦截插件**:提供全表DELETE/UPDATE操作的智能分析阻断,防止误操作导致的数据丢失。 ##### 缺点: 尽管Mybatis-Plus...

    Mybatis分页拦截器

    在Mybatis中,拦截器扮演着插件的角色,可以监听并修改Mybatis执行过程中的某些行为。本话题将深入探讨Mybatis分页拦截器的工作原理、实现方式以及在不同版本(如mybatis-3.1.1和mybatis-3.0.4)下的兼容性。 首先...

    mybatis-plus-3.0

    7. **SQL执行效率分析**:MyBatis-Plus能够记录SQL执行的耗时,帮助开发者定位慢查询,优化数据库性能。 8. **表结构同步**:提供数据库表结构同步工具,可以快速将数据库表结构同步到实体类,提高开发效率。 9. *...

    mybatis_log_plugin_2020idea.jar

    - 使用插件:运行项目后,当MyBatis执行SQL时,对应的SQL信息会自动在控制台或者指定的日志文件中输出,无需额外的代码修改。 3. **功能特性** - **实时查看SQL**:在程序运行时,插件会即时打印出执行的SQL语句...

    IDEA日志插件,mybatis-log

    该插件适用于IntelliJ IDEA 2020版本,它能实时地在IDEA的控制台中显示Mybatis执行的SQL语句,帮助开发者快速定位问题、优化性能。安装方式非常便捷,用户只需将下载的插件文件进行离线安装,即可在IDEA中启用。这种...

    Spring Boot集成Mybatis附加自动生成工具,异常信息处理等工具类,拦截器,最全框架

    在IT行业中,Spring Boot和Mybatis是两个非常重要的框架,它们在开发Web应用程序时起着核心作用。Spring Boot简化了Spring应用的初始设置和配置,而Mybatis则是一个轻量级的持久层框架,提供了灵活的SQL映射功能。本...

    mybatis-log-plugin.zip

    1. **SQL打印**:当开启此插件时,每次MyBatis执行的SQL语句都会被详细地记录下来,包括原始的SQL语句、绑定的参数以及动态SQL生成的最终版本。 2. **执行时间**:插件不仅可以打印SQL,还能显示SQL执行所需的时间...

    SpringBoot集成MyBatis-Plus实现国产数据库适配.docx

    * 内置性能分析插件:可输出 Sql 语句以及其执行时间,建议开发测试时启用该功能,能快速揪出慢查询 * 内置全局拦截插件:提供全表 delete 、update 操作智能分析阻断,也可自定义拦截规则,预防误操作 MyBatis-...

    mybatis plus.pdf

    内置性能分析插件可以输出SQL语句以及其执行时间,建议在开发和测试时启用该功能以快速揪出慢查询。内置全局拦截插件提供全表delete、update操作的智能分析阻断,也可自定义拦截规则来预防误操作。框架结构快速开始...

    mybatis自定义分页标签

    而自定义分页标签是提高开发效率、增强代码可读性和复用性的一种常见手段。本篇将详细介绍如何在MyBatis中实现自定义的JSTL标签来完成分页查询。 首先,我们要理解分页的基本概念。分页是当数据量较大时,为了提高...

    官网 mybatis-3.2.7jar包 下载

    2. **映射器**:MyBatis的映射器负责处理SQL的执行和结果的映射。通过XML配置文件或注解,开发者可以定义SQL语句、参数类型和返回结果的映射。 3. **参数映射**:MyBatis自动处理Java对象到SQL参数的转换,无需手动...

    mybatis-3.4.1.zip 官网JAR包

    “mybatisjar包”标签明确了这是关于MyBatis的JAR文件,它是Java应用程序执行时的二进制格式,包含MyBatis框架的类和依赖。 “官网下载”标签表示这个JAR包来源于MyBatis的官方渠道,确保了版本的正确性和安全性,...

    mybatis_plus.docx

    13. **性能分析插件**:能够输出SQL语句及其执行时间,便于在开发和测试阶段发现慢查询。 14. **全局拦截插件**:智能分析并阻止全表的delete和update操作,防止误操作,同时也支持自定义拦截规则。 15. **SQL注入...

    MyBatis-Plus v3.3.2 使用教程1

    8. 性能分析插件:可输出 Sql 语句以及其执行时间,建议开发测试时启用该功能,能快速揪出慢查询。 9. 全局拦截插件:提供全表 delete、update 操作智能分析阻断,也可自定义拦截规则,预防误操作。 MyBatis-Plus ...

    springboot+mybatis+druid

    Druid作为连接池,提供了强大的监控功能,包括SQL解析、执行效率统计、慢SQL记录等。它还支持数据源健康检查,可以有效防止因数据库连接异常导致的应用问题。此外,Druid还有Web监控界面,方便开发者实时查看数据源...

    mybatis_log_20_3.7z

    1. **实时日志查看**:插件可能提供了实时更新的视图,展示MyBatis执行的SQL语句及其结果。 2. **格式化输出**:日志可能会被格式化,使SQL语句和参数更容易阅读。 3. **搜索和过滤**:用户可能可以通过关键字搜索...

    MyBatis(三)

    3. **调试与性能监控**:利用log4j记录SQL执行时间,可以定位慢查询并进行优化。例如,如果观察到某个SQL查询耗时较长,可以通过调整SQL语句、添加索引等方式提升性能。 4. **日志分类**:可以为不同的模块或类定义...

    mybatis_log_plugin_2020idea.zip

    这个插件可能能够显示MyBatis执行的每个SQL查询,包括其动态生成的部分,同时可能还支持查看查询结果,这对于调试和性能优化非常有用。 在2020年,IDEA作为Java开发的主流IDE,提供了丰富的插件支持来提升开发效率...

    Mybatis plus 基于 springBoot 源码

    Mybatis-Plus(简称MP)是一个 Mybatis... 内置性能分析插件:可输出Sql语句以及其执行时间,建议开发测试时启用该功能,能有效解决慢查询 内置全局拦截插件:提供全表 delete 、 update 操作智能分析阻断,预防误操作

    MyBatis-Plus入门.pdf

    MyBatis-Plus还内置了性能分析插件,它能够输出SQL语句及其执行时间,对于开发和测试阶段,这是一个非常有用的功能,因为它可以帮助开发人员快速找出慢查询,提升数据库操作的性能。同时,内置的全局拦截插件提供了...

Global site tag (gtag.js) - Google Analytics