title: MySQL PRIMARY KEYs: UUID / GUID vs BIGINT (timestamp+random)
body: <p><strong>tl;dr:  Is assigning rows IDs of {unixtimestamp}{randomdigits} (such as 1308022796123456) as a BIGINT a good idea if I don't want to deal with UUIDs?</strong> </p>
  
  <p>Just wondering if anyone has some insight into any performance or other technical considerations / limitations in regards to IDs / PRIMARY KEYs assigned to database records across multiple servers. </p>
  
  <p>My PHP+MySQL application runs on multiple servers, and the data needs to be able to be merged.  So I've outgrown the standard sequential / auto_increment integer method of identifying rows.</p>
  
  <p>My research into a solution brought me to the concept of using UUIDs / GUIDs.  However the need to alter my code to deal with converting UUID strings to binary values in MySQL seems like a bit of a pain/work.  I don't want to store the UUIDs as VARCHAR for storage and performance reasons.   </p>
  
  <p>Another possible annoyance of UUIDs stored in a binary column is the fact that rows IDs aren't obvious when looking at the data in PhpMyAdmin - I could be wrong about this though - but straight numbers seem a lot simpler overall anyway and are universal across any kind of database system with no conversion required.</p>
  
  <p>As a middle ground I came up with the idea of making my ID columns a BIGINT, and assigning IDs using the current unix timestamp followed by 6 random digits.  So lets say my random number came about to be 123456, my generated ID today would come out as: <strong>1308022796123456</strong> </p>
  
  <p>A one in 10 million chance of a conflict for rows created within the same second is fine with me.  I'm not doing any sort of mass row creation quickly. </p>
  
  <p>One issue I've read about with randomly generated UUIDs is that they're bad for indexes, as the values are not sequential (they're spread out all over the place).  The UUID() function in MySQL addresses this by generating the first part of the UUID from the current timestamp.  Therefore I've copied that idea of having the unix timestamp at the start of my BIGINT.  Will my indexes be slow?  </p>
  
  <p><strong>Pros of my BIGINT idea:</strong> </p>
  
  <ul>
  <li>Gives me the multi-server/merging advantages of UUIDs </li>
  <li>Requires very little change to my application code (everything is already programmed to handle integers for IDs) </li>
  <li>Half the storage of a UUID (8 bytes vs 16 bytes) </li>
  </ul>
  
  <p><strong>Cons:</strong> </p>
  
  <ul>
  <li>???  - Please let me know if you can think of any. </li>
  </ul>
  
  <p><em>Some follow up questions to go along with this:</em> </p>
  
  <ol>
  <li><p>Should I use more or less than 6 random digits at the end?  Will it make a difference to index performance? </p></li>
  <li><p>Is one of these methods any "randomer" ?:  Getting PHP to generate 6 digits and concatenating them together -VS- getting PHP to generate a number in the 1 - 999999 range and then zerofilling to ensure 6 digits. </p></li>
  </ol>
  
  <p>Thanks for any tips.  Sorry about the wall of text.</p>