title: MySQL duplicate key error causes a shared lock set on the duplicate index record?
body: <p>I've read the document of MySQL 14.2.7.6. Locks Set by Different SQL Statements in InnoDB</p>
  
  <p><a href="http://dev.mysql.com/doc/refman/5.0/en/innodb-locks-set.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.0/en/innodb-locks-set.html</a></p>
  
  <p>My questions:</p>
  
  <ol>
  <li><p>I don't understand why documentation states:</p>
  
  <blockquote>
    <p>If a duplicate-key error occurs, a shared lock on the duplicate index
    record is set. This use of a shared lock can result in deadlock should
    there be multiple sessions trying to insert the same row if another
    session already has an exclusive lock. This can occur if another
    session deletes the row.</p>
  </blockquote>
  
  <p>Why does it set a lock on the row since the INSERT operation has
  failed. It acquires the lock for what?</p></li>
  <li><p>Is an Intention shared (IS) lock set when "SELECT ... LOCK IN SHARE MODE" is executing? Is an Intention exclusive (IX) Lock set
  when "UPDATE, INSERT, DELETE" or "SELECT ... FOR UPDATE" are
  executing?</p></li>
  </ol>