title: Numeric Range Optimization
body: <p>I have an set numeric ranges that I would like to optimize.</p>
  
  <p>Here's a simple example of initial values:</p>
  
  <pre><code>Start    End
  9        12
  1        2
  60       88
  10       11
  79       80
  </code></pre>
  
  <p>What I'd expect as output after optimization:</p>
  
  <pre><code>Start    End
  1        2
  9        12
  60       88
  </code></pre>
  
  <p>These are the <code>left</code> and <code>right</code> values from Modified Preorder Tree Traversal (Nested Set) data stored in a MySQL database.  I use them to exclude inactive branches from the result, and am not currently optimizing the ranges at all. I thought I might get a performance gain from optimizing the ranges before use.</p>
  
  <hr>
  
  <p><strong>MORE INFO</strong></p>
  
  <p>The values are passed into a query for exclusion of the inactive branches in the tree using a <code>NOT BETWEEN</code> clause.  I thought that I could optimize the performance of that query by using a minimal set of ranges.</p>