When does sql optimization become redundant?

I am updating tables with millions of records and I need to be as efficient as possible. Does it make sense to add more criteria to the where clause rather than help?

For example, if you know, I want to set the column to 3, I could use this query:

update mytable set col = 3

Or I could update the record only if it is different

update mytable set col = 3 where col <> 3

I could also filter it so that it only updates records added since the last start of this process

update mytable set col = 3 where col <> 3 and createDate > @lastRunDate

And maybe I could look for extra things in extra columns.

I think my question is, is there a point where the cost of finding additional columns outweighs the cost of the update itself and if there is a principle that you can use to determine where to draw a line.

Update

, , . , :

  • , , , .

  • , .

  • , , , ... [[ . where?]]

# 2 , .

+3
2

"col", ; , . , , ( , ).

usnig WHERE , . , SQL Server. , ......

: WHERE - , /. ( ), 100% , . , ( SELECT, , , ).

, , , , , , . , , , , , .

, , . , , , WHERE - . SQL (, , ).

+6

. , - .

where , , .

- , , , , , , . , .

+2

Source: https://habr.com/ru/post/1728682/


All Articles