mysql fetchsize原理_MySQL JDBC FetchSize解析

本文探讨了MySQL JDBC驱动的FetchSize特性,指出其作为提示而非强制,并介绍了使用'useCursorFetch=true'参数后的批处理获取行的方式。通过源码分析,确认了MySQL支持批量获取结果集,涉及RowDataCursor类的next方法和Materialized_cursor的fetch方法。
摘要由CSDN通过智能技术生成

首先是看Java JDBC的API查看setFetchSize:

setFetchSize(int rows)

Givesthe JDBC driver a hint as to the number of rows that should be fetched from thedatabase when more rows are needed for this ResultSetobject.

查看的结果给出这里的rows只是一个hint,那么对于MySQL JDBC来说是如何实现的呢?

There is experimental support for fetching rows in batches

When using Connector/J 5.0.1 along with more recent builds of the MySQL server, you can add "useCursorFetch=true" to your JDBC url parameters, and the driver will fetch rows in batches of size setFetchSize() as defined in the JDBC API.

One could also argue that the behavior _does_ follow the JDBC API, quoting from the APIDOCS for Statement.setFetchSize():

"Gives the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed. The number of rows specified affects only result sets created using this statement.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值