开发者

SQL Read/Write efficiency

开发者 https://www.devze.com 2023-03-26 19:24 出处:网络
Is there any diffrenece in the performance of read and write operations in SQL? Using Linq to SQL in an ASP.NET MVC application, I often update many values in one of my tables in single posts (during

Is there any diffrenece in the performance of read and write operations in SQL? Using Linq to SQL in an ASP.NET MVC application, I often update many values in one of my tables in single posts (during this process, many posts of this type will come in rapidly from the user, although the user is unable to submit new data until the previous update is complete). My current implementation is to loop through the input (a list of the current values for each row), and write them to the field (nullable int). I wonder if there would be any performance difference if instead I read the current db value, and only wrote if it has changed. Most of these operations change the values for roughly 1/4 to 2/3 of the rows, some change fewer, and few change more than 2/3 of the rows.

I don't know much about the comparative speeds of these operations (or if there is even any difference). Is there any benefit to be gained from doing this? If so, what t开发者_如何学Pythonable sizes would benefit the most/not benefit at all, and would there be any percentage of the rows changing that would be a threshold for this improvement?


It's always faster to read.

A write is actually always a read followed by a write.

SQL needs to know which row to write to, which involves reading either an index or the table itself in a seek or scan operation, then writing to the appropriate row.

Writing also needs to update any applicable indexes. Depending on the circumstance, the index may get "updated" even when the data doesn't change.

As a very general rule, it's a good idea only to modify the data that needs to be changed.

0

精彩评论

暂无评论...
验证码 换一张
取 消