开发者

Optimizing sybase SQL Query

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..

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜