title: MySQL update CASE WHEN/THEN/ELSE
body: <p>I am trying to update a LARGE MyISAM table (25 million records) using a CLI script. The table is not being locked/used by anything else.</p>
  
  <p>I figured instead of doing single UPDATE queries for each record, I might as well utilize the CASE feature.</p>
  
  <p>The <code>id</code> field is PRIMARY. I suspect the following query should take milliseconds.</p>
  
  <pre><code>UPDATE `table` SET `uid` = CASE
      WHEN id = 1 THEN 2952
      WHEN id = 2 THEN 4925
      WHEN id = 3 THEN 1592
      END
  </code></pre>
  
  <p>Lo and behold, the query hogs the CPU and doesn't finish in forever.</p>
  
  <p>Then, to my surprise, I found out that the query is updating all the 25 million rows, placing a NULL on rows that I didn't specify.</p>
  
  <p>What is the purpose of that? Can I just do a MASS update on specific rows without updating 25 million rows every time I execute this query? Or do I have to do individual updates and then commit?</p>