简体   繁体   English

hibernate.jdbc.fetch_size 和 hibernate.jdbc.batch_size 有什么区别?

[英]What is the difference between hibernate.jdbc.fetch_size and hibernate.jdbc.batch_size?

I am trying to tune my application, came across some blogs speaking about the batch fetch and batch select and putting my understanding as follows.我正在尝试调整我的应用程序,遇到了一些关于批量获取和批量选择的博客,并将我的理解如下。

  • hibernate.jdbc.fetch_size - Used to specify number of rows to be fetched in a select query. hibernate.jdbc.fetch_size - 用于指定要在选择查询中提取的行数。
  • hibernate.jdbc.batch_size - Used to specify number of inserts or updates to be carried out in a single database hit. hibernate.jdbc.batch_size - 用于指定要在单个数据库命中中执行的插入或更新的数量。

Please let me know whether my understanding is correct or not?请让我知道我的理解是否正确? Also what are the optimal values for the above parameters..还有上述参数的最佳值是什么..

Both of these options set properties within the JDBC driver.这两个选项都在 JDBC 驱动程序中设置属性。 In the first case, hibernate.jdbc.fetch_size sets the statement's fetch size within the JDBC driver, that is the number of rows fetched when there is more than a one row result on select statements.在第一种情况下, hibernate.jdbc.fetch_size在 JDBC 驱动程序中设置语句的提取大小,即当 select 语句上有多个行结果时提取的行数。

In the second case, hibernate.jdbc.batch_size determines the number of updates (inserts, updates and deletes) that are sent to the database at one time for execution.在第二种情况下, hibernate.jdbc.batch_size决定了一次发送到数据库执行的更新(插入、更新和删除)的次数。 This parameter is necessary to do batch inserts, but must be coupled with the ordered inserts parameter and the JDBC driver's capability to rewrite the inserts into a batch insert statement.此参数是执行批量插入所必需的,但必须与有序插入参数和 JDBC 驱动程序将插入重写为批量插入语句的能力相结合。

See this link这个链接

Your assumptions are correct.你的假设是正确的。

hibernate.jdbc.fetch_size hibernate.jdbc.fetch_size

The hibernate.jdbc.fetch_size Hibernate configuration property is used for setting the JDBC Statement#setFetchSize property for every statement that Hibernate uses during the currently running Persistence Context. hibernate.jdbc.fetch_size Hibernate 配置属性用于为 Hibernate 在当前运行的 Persistence Context 期间使用的每个语句设置 JDBC Statement#setFetchSize属性。

Usually, you don't need to set this property as the default is fine, especially for MySQL and PostgreSQL which fetch the entire ResultSet in a single database roundtrip.通常,您不需要设置此属性,因为默认值就可以了,特别是对于在单个数据库往返中获取整个ResultSet MySQL 和 PostgreSQL。 Because Hibernate traverses the entire ResultSet , you are better off fetching all rows in a single shot instead of using multiple roundtrips.因为 Hibernate 遍历整个ResultSet ,所以最好在一次拍摄中获取所有行,而不是使用多次往返。

Only for Oracle, you might want to set it since the default fetchSize is just 10 .仅对于 Oracle,您可能需要设置它,因为默认fetchSize仅为10

hibernate.jdbc.batch_size hibernate.jdbc.batch_size

The hibernate.jdbc.batch_size property is used to batch multiple INSERT, UPDATE, and DELETE statements together so that they can be set in a single database call. hibernate.jdbc.batch_size属性用于将多个 INSERT、UPDATE 和 DELETE 语句一起批处理,以便可以在单个数据库调用中设置它们。

If you set this property, you are better off setting these two as well:如果你设置了这个属性,你最好也设置这两个:

  • hibernate.order_inserts to true hibernate.order_insertstrue
  • hibernate.order_updates to true hibernate.order_updatestrue

Fetch size does Statement.setFetchSize() while batch size is for Hibernate batching.获取大小执行Statement.setFetchSize()而批量大小用于 Hibernate 批处理。 Both configuration parameters are explained here . 此处解释这两个配置参数。 For hibernate batch refer here对于休眠批处理,请参阅此处

Your understanding seems quite correct.你的理解似乎很正确。 I would refer you to the JBOSS documentation on Hibernate, the following chapter is on Batch processing .我会向您推荐有关 Hibernate 的 JBOSS 文档,以下章节是关于批处理的 And this one on tweaking performance .而这个是关于调整性能的

It's a good, easy to read source.这是一个很好的,易于阅读的源代码。 It gives some suggestions on optimal values, but as CodeChimp mentioned, tuning is best done case by case and is a repeatable process over time.它提供了一些关于最佳值的建议,但正如 CodeChimp 所提到的,调整最好是逐个进行,并且随着时间的推移是一个可重复的过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM