title: Tagging and how to test a tag exists
body: <p>I plan to store tags (like the ones on Stackoverflow) using the <a href="http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html" rel="nofollow noreferrer">Toxi</a> scheme
  Tags are stored in a separate table.</p>
  
  <pre><code>create table tags
  (
     tagSeq int unsigned,
     name varchar(255),
     PRIMARY KEY (tagSeq),
     UNIQUE INDEX (name)
  );
  </code></pre>
  
  <p>In the add a tag usecase, multiple concurrent threads will be attempting to check if a particular tag exists; thus it will be a point of contention. If the tag exists, the threads just pull out the tagSeq and adds a row in the intermediate table that links it with the item being tagged.</p>
  
  <p>How do I design this <strong>if exist use tagSeq, if not create</strong> use case such that I have high concurrency while maintaining data integrity ? What isolation level should I use for example ?</p>
  
  <p>My current solution is for every incoming thread to just perform an INSERT. If I get a UNIQUE KEY constraint violation, I just read back the tagSeq. If not, I create it. Am I on track ?</p>