休眠@DynamicUpdate(value = true)@SelectBeforeUpdate(value = true)性能 [英] Hibernate @DynamicUpdate(value=true) @SelectBeforeUpdate(value=true) performance

查看:122
本文介绍了休眠@DynamicUpdate(value = true)@SelectBeforeUpdate(value = true)性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始在我的APP中使用这2个休眠注释.

i am start using this 2 hibernate annotations in my APP.

@DynamicUpdate(value=true)
@SelectBeforeUpdate(value=true) 

首先,我将尝试解释我对此的理解,以了解我是否正确.

first i will try to explain what i understand about it to know if i am right about it.

@DynamicUpdate(value=true)

仅更新实体 Hibernate需要跟踪这些更改的修改后的值

updates only the modified values in the entity Hibernate needs to track those changes

@SelectBeforeUpdate(value=true)

update 之前创建 select ,以了解哪些属性已更改,这在实体已在不同会话上加载和更新时很有用.跟踪实体更改

creates a select before update to know which properties has been changed this is useful when the entity has been loaded and updated on different sessions Hibernate is out of tracking entity changes

这两个确认正确吗?

我主要关心的是

更好或更快的 DB性能中的

一次更新实体中的所有字段,或生成选择以了解哪些列仅更新和更新修改过的列?

in DB performance which is better or faster updates all the fields in the entity at once or generate a select to know which columns update and update only the modified columns?

推荐答案

具体情况取决于您的情况.如果您的表非常简单(没有外键约束,只有很少的列,很少的索引),那么更新完整记录将更快.

The situation depends on your circumstance. If your table is very simple (has no foreign key constraints, only few columns, few indexes), then updating the full record is going to be faster.

但是,如果您的表具有许多外键约束和索引,则先选择然后更新差异将更快.这是因为PostgreSQL必须为更新中的每一列执行以下工作:

If, however, your table has many foreign key constraints and indexes, it will be faster to first select and then update the differences. This is because PostgreSQL has to do the following work for each column in the update:

  • 检查外键约束
  • 更新相关索引

此外,所做的更改会使表膨胀,必须通过真空清理.

Furthermore, the changes add bloat to the tables which must be cleaned up by vacuum.

请记住,如果您在具有许多表的数据库上使用dynamicUpdate,并且您的更新看起来非常不同,则将开始逐出缓存的查询计划.这些计划会花费资源来计算最新数据.不过,无论如何,缓存的计划可能仅对同一会话中的后续查询有用.

Keep in mind that if you use dynamicUpdate on a database with many tables, and your updates look very different, you'll start evicting cached query plans. Those plans cost resources to compute fresh. Though, cached plans might only be useful to subsequent queries in the same session anyhow.

这篇关于休眠@DynamicUpdate(value = true)@SelectBeforeUpdate(value = true)性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆