SQLite Forum

Shortcut to change a non changing update or upsert in a noop
Login
This too was discussed previously, but I can't find the post in question, or even remember whether. it was on the old mailing list.  What I remember is …

If SQLite already has the value to be overwritten in memory, because it was covered by the index used to find the row, it will check the new value against the one in memory to make sure that a change needs to be made.

If SQLite has already needed to read the old value from the table, in order to fetch enough of the row to figure out which rows satisfy the WHERE clause, it will check the new value against the one in memory to make sure that a change needs to be made.

It seems that a good way to optimise your code seems to be to make sure that the column you're updating is included in the index used to satisfy the WHERE clause.  In other words, don't write extra code, just craft your indexes carefully.  And, of course, test out the change to make sure there's a worthwhile difference.  Because if you save just a millisecond an hour, it's not worth the extra storage cost.