Postgres:更新未更改的行 [英] Postgres: updating not-changed rows

查看:51
本文介绍了Postgres:更新未更改的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比如说,我有以下查询:

Say, I have a following query:

UPDATE table_name
SET column_name1 = column_value1, ..., column_nameN = column_valueN
WHERE id = M

问题是, column_value1, ..., column_valueN 没有改变.这个查询会被真正执行吗?在这种情况下,与使用真正更改的数据进行更新相比,性能如何?如果我每页有大约 50 个此类查询且数据未更改,该怎么办?

The thing is, that column_value1, ..., column_valueN have not changed. Will this query be really executed and what about performance in this case comparing to update with really changed data? What if I have about 50 of such queries per page with not-changed data?

推荐答案

您需要通过仅指定更改的列和行来帮助 postgresql.它将继续对您指定的任何内容执行更新,而无需检查数据是否已更改.

You need to help postgresql here by specifying only the changed columns and rows. It will go ahead and perform update on whatever you specify without checking if the data has been changed.

附言这就是 ORM 派上用场的地方.

p.s. This is where ORM comes in handy.

您可能还对如何感兴趣我可以在 PostgreSQL 中加速更新/替换操作吗?,OP 经历了所有的麻烦来加速 UPDATE 性能,当仅通过更新更改的数据可以实现最佳性能时.

You may also be interested in How can I speed up update/replace operations in PostgreSQL?, where the OP went through all the troubles to speed up UPDATE performance, when the best performance can be achieved by updating changed data only.

这篇关于Postgres:更新未更改的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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