title: rails activerecord, mysql and mysql2 performance degradation?
body: <p>I have only recently upgraded from Rails 2.3.5 to Rails 3.2.7 and noticed some performance degradation in some of my queries. I am aware of Rails 3 ActiveRecord being slower in some cases than Rails 2.3.5, but the benchmarks I have surprised me and I just want to make sure I am not missing anything.</p>
  <p>I ran the following query, which is very popular in my application, as a benchmark</p>
  <pre><code>SELECT SQL_NO_CACHE table_name.* FROM table_name WHERE ((string_col = 'value') AND (int_col1 BETWEEN 5 AND 30)) ORDER BY int_col2 DESC LIMIT 1000
  </code></pre>
  <p>I checked:</p>
  <ul>
  <li>rails 3.2.7 vs. rails 2.3.5</li>
  <li>rails 3.2.7 with mysql adapter vs mysql2</li>
  <li>ActiveRecord.find_by_sql vs ActiveRecord.connection.select_all</li>
  </ul>
  <h1>Results</h1>
  <h3>Rails 3.2.7</h3>
  <p>rails 3.2.7, mysql adapter, &quot;select_all&quot;: avg. 0.0148 seconds<br/>
  rails 3.2.7, mysql adapter, &quot;find_by_sql&quot; avg. 0.0555 seconds</p>
  <p>rails 3.2.7, mysql2 adapter, &quot;select_all&quot;: avg. 0.045 seconds<br/>
  rails 3.2.7, mysql2 adapter, &quot;find_by_sql&quot; avg. 0.088 seconds</p>
  <h3>Rails 2.3.5</h3>
  <p>rails 2.3.5, mysql adapter &quot;select_all&quot;: avg. 0.013 seconds<br/>
  rails 2.3.5, mysql adapter &quot;find_by_sql&quot;: avg. 0.0177 seconds</p>
  <p>Although my original code is using ActiveRecord query api, I used hardcoded sql for the benchmark and also verified that calling mysql directly from the bash command line is stable and the above numbers result from rails/mysql adapter and not the db.</p>
  <h1>Question</h1>
  <p>Are these differences reasonable?<br/>
  The diff between &quot;find_by_sql&quot; and &quot;select_all&quot; is much bigger in Rails 3.2.7 than in Rails 2.3.5.<br/>
  And why is mysql2 slower than mysql?<br/></p>