-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[错误报告]: 流式查询失效问题 #6485
Comments
mybatis-plus:
configuration:
default-fetch-size: 10 |
配置完重新测试是可以的,感谢回复 |
你好,我在yml中添加了 default-fetch-size: 10
使用流式查询,该处org.apache.ibatis.executor.resultset.DefaultResultSetHandler#getRowValue(org.apache.ibatis.executor.resultset.ResultSetWrapper, org.apache.ibatis.mapping.ResultMap, java.lang.String) 还是返回了全部结果 |
我是配置的 mybatis-plus:
configuration:
default-fetch-size: -2147483648 mysql只能这个值才能生效,一开始我是没发现有这个可以指定fetchSize的配置 |
这个主要问题是 mysql 与客户端的约定,写死的 Integer.MIN_VALUE 游标才生效, /**
* We only stream result sets when they are forward-only, read-only, and the
* fetch size has been set to Integer.MIN_VALUE
*
* @return true if this result set should be streamed row at-a-time, rather
* than read all at once.
*/
protected boolean createStreamingResultSet() {
return this.query.getResultType() == Type.FORWARD_ONLY && this.resultSetConcurrency == java.sql.ResultSet.CONCUR_READ_ONLY
&& this.query.getResultFetchSize() == Integer.MIN_VALUE;
} 即对应 mapper xml select 标签的 这些属性 resultOrdered="true" fetchSize="-2147483648" resultSetType="FORWARD_ONLY" 但其实 Oracle/db2 是支持 fetchSize 自定义设置的...,感觉 非 mysql 可以加点个注解,按需 配置? |
确认
当前程序版本
3.5.7
问题描述
描述:
流式查询使用com.baomidou.mybatisplus.core.mapper.BaseMapper#selectList(com.baomidou.mybatisplus.core.conditions.Wrapper<T>, org.apache.ibatis.session.ResultHandler<T>)方法未开启流式查询,而是一次性查询出所有匹配数据
重现步骤:
1.MySQL建表
2.插入10w条测试数据
3.定义mapper(省略项目搭建过程)
4.测试代码
5.设置debug断点,断点打在org.apache.ibatis.executor.resultset.DefaultResultSetHandler#getRowValue(org.apache.ibatis.executor.resultset.ResultSetWrapper, org.apache.ibatis.mapping.ResultMap, java.lang.String)方法第一行,查看rsw最里层的resultSet的rowData字段
通过rowData字段看出直接查询了10w数据出来,如果数据量过大易产生OOM
修复建议:
提供全局的fetchSize配置设置的地方,或者提供方法级别设置fetchSize
演示正确开启流式查询
1.在重现步骤基础上,关注源码DefaultSqlInjector注入SelectList步骤,找出com.baomidou.mybatisplus.core.injector.methods.SelectList#injectMappedStatement方法中用到fetchSize的地方,打上断点,当前mp版本没有设置fetchSize也就是null,debug时需要手动指定为-2147483648(mysql只有这个值才能开启流式查询,像神通数据库之类指定大于0的值)
2.查看复现步骤5的断点,当rowData等于ResultsetRowStreaming类型时为开启流式查询成功
详细堆栈日志
No response
The text was updated successfully, but these errors were encountered: