Is there a way to optimize the following query:
UPDATE myTable
SET Calculation =
(SELECT MAX(Calculation)
开发者_JS百科FROM myTable T
WHERE T.Id = myTable.Id
AND T.Flag='N')
WHERE Calculation='NA'
AND Flag='Y'
where myTable has approx. 4 million rows? Actually the first not NULL will do the job (SYBASE ASE 15.0.2).
Check Query plan, it must be using deferred update which is taking longer time to update. Query suggested by Michael should perform better.
rememeber below points which require deferred update
Updates that use self-joins
Updates to columns used for self-referential integrity
Updates to a table referenced in a correlated subquery
Thanks..
精彩评论