# What SQL Query "Optimisation" Has Done For Me Lately

<p>So I assumed databases would have a pretty good SQL optimisation story
by now, but no&hellip;  Two recent disappointments:</p>

<ol>
<li>MySQL failed to notice that <code>SELECT ... FROM ... WHERE ? IN (foo,
bar)</code> was equivalent to <code>... WHERE foo = ? OR bar = 2</code> and/or that the
latter would be much faster.</li>
<li>Copying a database from one server to another led to a query that
took 20 seconds on the source timing out (after 10 minutes) on the
copy.  Even more bizarrely, the fix was to tell the copy to ignore an
index.  (The master and copy weren&rsquo;t exactly the same version of
MySQL, but they were both varieties of 5.1.x.)</li>
</ol>

<p>The first time it sees a query, MongoDB <a href="http://www.mongodb.org/display/DOCS/Query+Optimizer">runs multiple query plans in
parallel</a>,
remembers which one worked best, and uses that the next time.  Is
there any relational database that does this?  Seems like a good idea,
given recent experiences&hellip;  Are there any web pages showing what
clever things query optimisers get up to, especially optimisations
that aren&rsquo;t immediately obvious to a human being?  (For a <code>gcc</code>
example, see <a href="http://ridiculousfish.com/blog/posts/will-it-optimize.html">Will it
Optimize?</a>)</p>
