The update
on all columns shows the same pattern we have already observed in the previous sections: the response time grows with each additional index. The response time of the update
statement that affects only one index does not increase so much because it leaves most indexes unchanged.
To optimize update
performance, you must take care to only update those columns that were changed. This is obvious if you write the update
statement manually. ORM tools, however, might generate update
statements that set all columns every time. Hibernate, for example, does this when disabling the dynamic-update mode. Since version 4.0, this mode is enabled by default.
When using ORM tools, it is a good practice to occasionally enable query logging in a development environment to verify the generated SQL statements. The tip entitled “Enabling SQL Logging” has a short overview of how to enable SQL logging in some widely used ORM tools.
Can you think of a case where insert
or delete
statements do not affect all indexes of a table?
You can’t learn everything in one day. Subscribe the newsletter via E-Mail, Bluesky or RSS to gradually catch up. Have a look at modern-sql.com as well.
The essence of SQL tuning in 200 pages
Buy now!
(paperback and/or PDF)
Paperback also available at Amazon.com.
Markus offers SQL training and consulting for developers working at companies of all sizes.
Learn more »