7

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?

1

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

2 Comments

By the way, YII framework's ORM doesn't check that and performs UPDATE query anyway.
I see. In SQLAlchemy, the ORM layer does the dirty work and only issues UPDATE when necessary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.