On a table with over 10 million rows, which one of these UPDATE statements likely to faster, or are they much of a muchness?
UPDATE table SET col1 = col2 WHERE col1 IS NULL;UPDATE table SET col1 = col2 WHERE col1 IS NULL AND col2 IS NOT NULL;
Neither col1 nor col2 are keys or indexed. They are actually datetime fields, if that changes anything.
Note: I'm fairly sure that the queries achieve the same result:
Query 1. will update col1 every time, including setting it to NULL if col2 is NULL.
Query 2. will update col1 only if col2 has a value, thereby leaving col1 as NULL if col2 is NULL.
They both change the data in the same way. One sets col1 to NULL when col2 is NULL, the other leaves col1 as NULL when col2 is NULL, but in all cases col1 was NULL to begin with.
NULLincol1and lesscol2with values, there are less to update. Meaning,col1andcol1values is inversely proportional with respect to performance.