title: Implementing inheritance in MySQL: alternatives and a table with only surrogate keys
body: <p>This is a question that has probably been asked before, but I'm having some difficulty to find exactly my case, so I'll explain my situation in search for some feedback:</p>
  
  <p>I have an application that will be registering locations, I have several types of locations, each location type has a different set of attributes, but I need to associate notes to locations regardless of their type and also other types of content (mostly multimedia entries and comments) to said notes. With this in mind, I came up with a couple of solutions:</p>
  
  <ol>
  <li><p>Create a table for each location type, and a "notes" table for every location table with a foreign key, this is pretty troublesome because I would have to create a multimedia and comments table for every comments table, e.g.: </p>
  
  <blockquote>
    <ul>
    <li><p>LocationTypeA</p>
    
    <ul>
    <li>ID</li>
    <li>Attr1</li>
    <li>Attr2</li>
    </ul></li>
    <li><p>LocationTypeA_Notes</p>
    
    <ul>
    <li>ID</li>
    <li>Attr1</li>
    <li>...</li>
    <li>LocationTypeA_fk</li>
    </ul></li>
    <li><p>LocationTypeA_Notes_Multimedia</p>
    
    <ul>
    <li>ID</li>
    <li>Attr1</li>
    <li>...</li>
    <li>LocationTypeA_Notes_fk</li>
    </ul></li>
    </ul>
  </blockquote>
  
  <p>And so on, this would be quite annoying to do, but after it's done, developing on this structure should not be so troublesome.</p></li>
  <li><p>Create a table with a unique identifier for the location and point content there, like so:</p>
  
  <blockquote>
    <ul>
    <li><p>Location</p>
    
    <ul>
    <li>ID</li>
    </ul></li>
    <li><p>LocationTypeA</p>
    
    <ul>
    <li>ID</li>
    <li>Attr1</li>
    <li>Attr2</li>
    <li>Location_fk</li>
    </ul></li>
    <li><p>Notes</p>
    
    <ul>
    <li>ID</li>
    <li>Attr1</li>
    <li>...</li>
    <li>Location_fk</li>
    </ul></li>
    <li><p>Multimedia</p>
    
    <ul>
    <li>ID</li>
    <li>Attr1</li>
    <li>...</li>
    <li>Notes_fk</li>
    </ul></li>
    </ul>
  </blockquote>
  
  <p>As you see, this is far more simple and also easier to develop, but I just don't like the looks of that table with only IDs (yeah, that's truly the only objection I have to this, it's the option I like the most, to be honest).</p></li>
  <li><p>Similar to option 2, but I would have an enormous table of attributes shaped like this:</p>
  
  <blockquote>
    <ul>
    <li><p>Location</p>
    
    <ul>
    <li>ID</li>
    <li>Type</li>
    </ul></li>
    <li><p>Attribute</p>
    
    <ul>
    <li>Name</li>
    <li>Value</li>
    </ul></li>
    </ul>
  </blockquote>
  
  <p>And so on, or a table for each attribute; a la Drupal. This would be a pain to develop because then it would take several insert/update operations to do something on a location and the Attribute table would be several times bigger than the location table (or end up with an enormous amount of attribute tables); it also has the same issue of the surrogate-keys-only table (just it has a "type" now, which I would use to define the behavior of the location programmatically), but it's a pretty solution.</p></li>
  </ol>
  
  <p>So, to the question: which would be a better solution performance and scalability-wise?, which would you go with or which alternatives would you propose? I don't have a problem implementing any of these, options 2 and 3 would be an interesting development, I've never done something like that, but I don't want to go with an option that will collapse on itself when the content grows a bit; you're probably thinking "why not just use Drupal if you know it works like you expect it to?", and I'm thinking "you obviously don't know how difficult it is to use Drupal, either that or you're an expert, which I'm most definitely not".</p>
  
  <p>Also, now that I've written all of this, do you think option 2 is a good idea overall?, do you know of a better way to group entities / simulate inheritance? (please, don't say "just use inheritance!", I'm restricted to using MySQL).</p>
  
  <p>Thanks for your feedback, I'm sorry if I wrote too much and meant too little.</p>