title: MySql with XPath versus MySql in unison with MongoDB for unusual structure requirements
body: <p>If your database needs to contain <a href="https://stackoverflow.com/questions/8618696/database-design-normalization-structure-needs-to-contain-ands-ors-optional-e">complex relationships/constraints</a> would you rather:</p>
  
  <ul>
  <li><code>Option 1</code>: a simple MySql structure with an XML field in one table, which you'd query using XPath (<a href="https://dev.mysql.com/doc/refman/5.1/en/xml-functions.html#function_extractvalue" rel="nofollow noreferrer">ExtractValue()</a>).</li>
  <li><code>Option 2</code>: the same simple MySql structure plus a separate MongoDB setup containing the MongoDB equivalent of the XML<code>*</code>,</li>
  </ul>
  
  <p>And <strong>why?</strong></p>
  
  <hr>
  
  <p><strong>Assumptions:</strong></p>
  
  <ul>
  <li>If a whole entity needed to be deleted it would be easier with option 1 (just delete the whole tuple).</li>
  <li>The MongoDB query would be quicker than XPath. But this needs to be done after the MySql query, unless the ID was retrieved in an earlier query.</li>
  <li>Minor updates would be quicker/easier with option 2, because with MySql's XML function <a href="https://dev.mysql.com/doc/refman/5.1/en/xml-functions.html#function_updatexml" rel="nofollow noreferrer">UpdateXML()</a> you can only update the <em>whole</em> of the XML.</li>
  <li>Have to be more careful with Option 2; when inserting/updating, I'll have to make sure not to insert/update the MongoDB if the MySql insert/update query failed.</li>
  <li>Ignoring the 'simple MySql structure' part (joins, etc.), there's only so much I can do with <a href="https://dev.mysql.com/doc/refman/5.1/en/xml-functions.html#function_extractvalue" rel="nofollow noreferrer">ExtractValue()</a> (Option 1); I'd need to retrieve a large chunk of the XML and do the rest in my PHP/JS. Whereas MongoDB can handle a lot more.</li>
  </ul>
  
  <hr>
  
  <p><strong>Notes:</strong></p>
  
  <blockquote>
    <ul>
    <li><code>*</code> plus the ID corresponding to the MySql tuple which it belongs.</li>
    <li>Correct me if I am wrong about any of my assumptions.</li>
    </ul>
  </blockquote>
  
  <hr>
  
  <h3>Edit:</h3>
  
  <p>Either way, it'll be PHP or JS via PHP I'll be using to interact with the database(s).</p>