You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Checking the result size after retrieving ResultSet isn't efficient.
JDBC provides java.sql.Statement#setMaxRows(), but its efficiency depends on the db/driver implementation.
The best way is to limit the number of returned rows in SQL using FETCH NEXT x ROWS ONLY or LIMIT x.
See this answer: https://stackoverflow.com/a/61140502/1261766
If you expect an exception, for some reason, you may have to get an extra row and check the result size. e.g.
select*from some_table fetch next 10001 rows only
Listresults = yourMapper.select();
if (results.size() > 10000) {
thrownewRuntimeException("query Size has large greate 10000!");
}
问题:
在使用mybatis查询数据时,如果sql编写不得当,会出现全表扫数据,数据很多的话
容易出现内存溢出的问题,能否在 statementid层 对查询的总数做一个可配置的校验
解决思路:
例如:
<select id="query" resultType="java.util.HashMap" maxCountSize="10000"> (也可做成读上下文动态配置,可实时修改)
使用的位置:
org.apache.ibatis.executor.resultset.DefaultResultSetHandler
The text was updated successfully, but these errors were encountered: