博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
oracle setFetchsize() 优化查询速度
阅读量:6375 次
发布时间:2019-06-23

本文共 3293 字,大约阅读时间需要 10 分钟。

hot3.png

 实践分析:

最开始在statement 上面设置fetchsize的原因是想增加查询结果返回的速度,因为这样一下子就可以返回更多的数据,但是实际上当我们加上这个条件的时候,没有起到效果,反而慢了下来,原因不知道。对于fetchsize的用法参考官方说明:

Fetch Size

By default, when Oracle JDBC executes a query, it receives the result set 10 rows at a time from the database cursor. This is the default Oracle row-prefetch value. You can change the number of rows retrieved with each trip to the database cursor by changing the row-prefetch value (see  for more information).

JDBC 2.0 also allows you to specify the number of rows fetched with each database round trip for a query, and this number is referred to as the fetch size. In Oracle JDBC, the row-prefetch value is used as the default fetch size in a statement object. Setting the fetch size overrides the row-prefetch setting and affects subsequent queries executed through that statement object.

Fetch size is also used in a result set. When the statement object executes a query, the fetch size of the statement object is passed to the result set object produced by the query. However, you can also set the fetch size in the result set object to override the statement fetch size that was passed to it. (Also note that changes made to a statement object's fetch size after a result set is produced will have no affect on that result set.)

The result set fetch size, either set explicitly, or by default equal to the statement fetch size that was passed to it, determines the number of rows that are retrieved in any subsequent trips to the database for that result set. This includes any trips that are still required to complete the original query, as well as any refetching of data into the result set. (Data can be refetched, either explicitly or implicitly, to update a scroll-sensitive or scroll-insensitive/updatable result set. See .)

Setting the Fetch Size

The following methods are available in all StatementPreparedStatementCallableStatement, and ResultSet objects for setting and getting the fetch size:

  • void setFetchSize(int rows) throws SQLException
  • int getFetchSize() throws SQLException

To set the fetch size for a query, call setFetchSize() on the statement object prior to executing the query. If you set the fetch size to N, then N rows are fetched with each trip to the database.

After you have executed the query, you can call setFetchSize() on the result set object to override the statement object fetch size that was passed to it. This will affect any subsequent trips to the database to get more rows for the original query, as well as affecting any later refetching of rows. (See .)

Use of Standard Fetch Size versus Oracle Row-Prefetch Setting

Using the JDBC 2.0 fetch size is fundamentally similar to using the Oracle row-prefetch value, except that with the row-prefetch value you do not have the flexibility of distinct values in the statement object and result set object. The row prefetch value would be used everywhere.

Furthermore, JDBC 2.0 fetch size usage is portable and can be used with other JDBC drivers. Oracle row-prefetch usage is vendor-specific.

See  for a general discussion of this Oracle feature.

 

Note:

Do not mix the JDBC 2.0 fetch size API and the Oracle row prefetching API in your application. You can use one or the other, but not both.  

参考博文:

参考博文:

参考博文:

转载于:https://my.oschina.net/u/2308739/blog/806239

你可能感兴趣的文章
面对区块链这项全新的技术,传统投资产生了焦虑
查看>>
1024城市峰会 | 当A.I.邂逅古都西安
查看>>
好看的卡片阴影
查看>>
理解 Mach O 并提高程序启动速度
查看>>
Vue实战篇(PC端商城项目)
查看>>
每周记录(二)
查看>>
你要做的是产品经理,不是作图经理!
查看>>
编码、摘要和加密(一)——字节编码
查看>>
JavaEE 项目常见错误汇总
查看>>
快速掌握Python基础语法(下)
查看>>
java虚拟机——运行时数据区域
查看>>
【Android自定义View】绘图之文字篇(三)
查看>>
适配iOS 11和iPhoneX屏幕适配遇到的一些坑
查看>>
Fetch API 简单封装
查看>>
给媳妇做一个记录心情的小程序
查看>>
iOS App无需跳转系统设置自动连接Wi-Fi
查看>>
一道柯里化面试题
查看>>
本科studying abroad 无法毕业申请硕士转学转校处理一切studying abroad 问题
查看>>
RxJava(RxAndroid)的简单学习
查看>>
Java8 函数式编程之函数接口(下)
查看>>