Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres: updating not-changed rows

Say, I have a following query:

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

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?

like image 245
Vadim Samokhin Avatar asked Oct 10 '22 07:10

Vadim Samokhin


1 Answers

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.

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

EDIT: 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.

like image 86
sayap Avatar answered Oct 18 '22 15:10

sayap