Using dynamic-update or dynamic-insert has positive, though generally slight only on performance, as also mentioned by http://www.mkyong.com/hibernate/hibernate-dynamic-update-attribute-example/
使用动态更新或动态插入具有积极的作用,但通常仅略微提高性能,如http://www.mkyong.com/hibernate/hibernate-dynamic-update-attribute-example/所述。
But the reference documentation mentions that this could have negative performance effects also as mentioned below in http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-declaration-class :
但是参考文档提到这可能会产生负面的性能影响,如http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-declaration-class中所述:
Although these settings can increase performance in some cases, they can actually decrease performance in others.
虽然这些设置可以在某些情况下提高性能,但实际上可能会降低其他设置的性能。
Can anybody please suggest some example/scenario mentioning negative performance impact of the same?
任何人都可以建议一些示例/场景提到相同的负面性能影响吗?
3 个解决方案
#1
44
Hibernate caches the actual INSERT/SELECT/UPDATE SQL strings for each entity and the obvious benefit is that it doesn't have to compute the SQL when you want to persist, find or update an entity.
Hibernate为每个实体缓存实际的INSERT / SELECT / UPDATE SQL字符串,显而易见的好处是,当您想要持久化,查找或更新实体时,它不必计算SQL。
However, when using dynamic-insert or dynamic-update, Hibernate has to generate the corresponding SQL string each time and there is thus a performance cost on the Hibernate side.
但是,当使用动态插入或动态更新时,Hibernate每次都必须生成相应的SQL字符串,因此Hibernate方面会产生性能成本。
In other words, there is a trade-off between overhead on the database side and on the Hibernate side.
换句话说,在数据库端和Hibernate端的开销之间存在权衡。
My point of view is that dynamic insert and dynamic update can be interesting for tables with a fat blob column or tables with a huge number of columns. In other cases, I'm not convinced that dynamic insert or update always means performance boost (I do not use them by default). But as always, you should measure it.
我的观点是动态插入和动态更新对于具有胖blob列的表或具有大量列的表可能是有趣的。在其他情况下,我不相信动态插入或更新总是意味着性能提升(我默认不使用它们)。但一如既往,你应该衡量它。
See also
- Re: Request for dynamic update-SQL for some feedback from the Hibernate developers
- Re:请求动态更新-SQL以获取来自Hibernate开发人员的一些反馈
#2
6
I think many indices also slow down updates and inserts, so, beside large columns, dynamic-update should be good for tables with great width/content per row and many indices. You know, in "real life", databases aren't always with small, normalized tables...
我认为许多索引也会降低更新和插入速度,因此,除了大型列之外,动态更新应该适用于每行具有较大宽度/内容和多个索引的表。你知道,在“现实生活”中,数据库并不总是带有小的,规范化的表格......
Rebuilding indices on large tables may take much longer than the overhead for creating and parsing SQL queries.
重建大型表的索引可能比创建和解析SQL查询的开销要长得多。
#3
1
The other reason is when updating a previously detached object. For that to work the record first needs to be fetched from the db, as a detached object isn't in the session cache. Hence dynamic update in this case requires an extra round trip to perform the initial fetch.
另一个原因是更新以前分离的对象时。为了使其工作,首先需要从db中获取记录,因为分离的对象不在会话高速缓存中。因此,在这种情况下的动态更新需要额外的往返来执行初始提取。
#1
44
Hibernate caches the actual INSERT/SELECT/UPDATE SQL strings for each entity and the obvious benefit is that it doesn't have to compute the SQL when you want to persist, find or update an entity.
Hibernate为每个实体缓存实际的INSERT / SELECT / UPDATE SQL字符串,显而易见的好处是,当您想要持久化,查找或更新实体时,它不必计算SQL。
However, when using dynamic-insert or dynamic-update, Hibernate has to generate the corresponding SQL string each time and there is thus a performance cost on the Hibernate side.
但是,当使用动态插入或动态更新时,Hibernate每次都必须生成相应的SQL字符串,因此Hibernate方面会产生性能成本。
In other words, there is a trade-off between overhead on the database side and on the Hibernate side.
换句话说,在数据库端和Hibernate端的开销之间存在权衡。
My point of view is that dynamic insert and dynamic update can be interesting for tables with a fat blob column or tables with a huge number of columns. In other cases, I'm not convinced that dynamic insert or update always means performance boost (I do not use them by default). But as always, you should measure it.
我的观点是动态插入和动态更新对于具有胖blob列的表或具有大量列的表可能是有趣的。在其他情况下,我不相信动态插入或更新总是意味着性能提升(我默认不使用它们)。但一如既往,你应该衡量它。
See also
- Re: Request for dynamic update-SQL for some feedback from the Hibernate developers
- Re:请求动态更新-SQL以获取来自Hibernate开发人员的一些反馈
#2
6
I think many indices also slow down updates and inserts, so, beside large columns, dynamic-update should be good for tables with great width/content per row and many indices. You know, in "real life", databases aren't always with small, normalized tables...
我认为许多索引也会降低更新和插入速度,因此,除了大型列之外,动态更新应该适用于每行具有较大宽度/内容和多个索引的表。你知道,在“现实生活”中,数据库并不总是带有小的,规范化的表格......
Rebuilding indices on large tables may take much longer than the overhead for creating and parsing SQL queries.
重建大型表的索引可能比创建和解析SQL查询的开销要长得多。
#3
1
The other reason is when updating a previously detached object. For that to work the record first needs to be fetched from the db, as a detached object isn't in the session cache. Hence dynamic update in this case requires an extra round trip to perform the initial fetch.
另一个原因是更新以前分离的对象时。为了使其工作,首先需要从db中获取记录,因为分离的对象不在会话高速缓存中。因此,在这种情况下的动态更新需要额外的往返来执行初始提取。