<?xml version="1.0" encoding="utf-8"?>
<launchpad-bug id="1008334">
  <date_last_updated>2012-06-27 00:36:14.818654+00:00</date_last_updated>
  <api_links>
    <bug_api_link>https://api.launchpad.net/1.0/bugs/1008334</bug_api_link>
    <bug_owner_link>https://api.launchpad.net/1.0/~brian2k1</bug_owner_link>
    <milestone_link>https://api.launchpad.net/1.0/maria/+milestone/5.3</milestone_link>
    <linked_branches_collection_link>https://api.launchpad.net/1.0/bugs/1008334/linked_branches</linked_branches_collection_link>
    <activity_link>https://api.launchpad.net/1.0/bugs/1008334/activity</activity_link>
  </api_links>
  <bug_web_link>https://bugs.launchpad.net/bugs/1008334</bug_web_link>
  <owner>Brian Boatright</owner>
  <assignee>Vladislav Vaintroub</assignee>
  <milestone_title>Maria 5.3</milestone_title>
  <duplicate_link></duplicate_link>
  <duplicate_bug_id></duplicate_bug_id>
  <title>Benchmark Query 4x Faster on MySQL 5.5</title>
  <status>Fix Released</status>
  <importance>Undecided</importance>
  <created>2012-06-04 05:51:48.408243+00:00</created>
  <description>
<![CDATA[Running this query is almost four times faster on MySQL than the same version of MariaDB.

SELECT BENCHMARK(10000000,DATE_SUB(FROM_UNIXTIME(RAND() * 2147483648), INTERVAL (FLOOR(1 + RAND() * 365)) DAY));

Results on Workstation Win7 x64 16gb i7 3ghz
- MariaDB 5.3.3 - 17.05 secs
- MySQL 5.5.17 - 4.09 secs

Results on Server Win2k8 R2 x64 8gb Xeon 1270 3.4ghz
- MariaDB 5.5.24 - 22.09 secs
- MySQL 5.5.24 - 5.90 secs

Results on older server running Win2k3 x32 4gb Xeon 5050 3ghz
- MySQL 5.0.27 - 22.00 secs

Is there any reason this query would be running so much slower on MariaDB vs MySQL?]]>  </description>
  <activities>
    <activity datechanged="2012-06-04T05:51:48.408243+00:00">
      <oldvalue>
<![CDATA[]]>      </oldvalue>
      <newvalue>
<![CDATA[]]>      </newvalue>
      <whatchanged>bug</whatchanged>
      <person>Brian Boatright</person>
      <message>added bug</message>
    </activity>
    <activity datechanged="2012-06-06T21:48:30.512255+00:00">
      <oldvalue>
<![CDATA[]]>      </oldvalue>
      <newvalue>
<![CDATA[performance]]>      </newvalue>
      <whatchanged>tags</whatchanged>
      <person>Elena Stepanova</person>
      <message></message>
    </activity>
    <activity datechanged="2012-06-06T21:48:45.464870+00:00">
      <oldvalue>
<![CDATA[]]>      </oldvalue>
      <newvalue>
<![CDATA[5.3]]>      </newvalue>
      <whatchanged>maria: milestone</whatchanged>
      <person>Elena Stepanova</person>
      <message></message>
    </activity>
    <activity datechanged="2012-06-06T21:51:49.489929+00:00">
      <oldvalue>
<![CDATA[]]>      </oldvalue>
      <newvalue>
<![CDATA[Vladislav Vaintroub (wlad-montyprogram)]]>      </newvalue>
      <whatchanged>maria: assignee</whatchanged>
      <person>Elena Stepanova</person>
      <message></message>
    </activity>
    <activity datechanged="2012-06-07T06:01:32.355068+00:00">
      <oldvalue>
<![CDATA[]]>      </oldvalue>
      <newvalue>
<![CDATA[]]>      </newvalue>
      <whatchanged>bug</whatchanged>
      <person>Sergei</person>
      <message>added subscriber Sergei</message>
    </activity>
    <activity datechanged="2012-06-14T11:31:33.749820+00:00">
      <oldvalue>
<![CDATA[New]]>      </oldvalue>
      <newvalue>
<![CDATA[Fix Committed]]>      </newvalue>
      <whatchanged>maria: status</whatchanged>
      <person>Vladislav Vaintroub</person>
      <message></message>
    </activity>
    <activity datechanged="2012-06-27T00:36:13.943696+00:00">
      <oldvalue>
<![CDATA[Fix Committed]]>      </oldvalue>
      <newvalue>
<![CDATA[Fix Released]]>      </newvalue>
      <whatchanged>maria: status</whatchanged>
      <person>Vladislav Vaintroub</person>
      <message></message>
    </activity>
  </activities>
  <comments>
    <comment commentlink="https://api.launchpad.net/1.0/maria/+bug/1008334/comments/1" datecreated="2012-06-06T21:48:15.390123+00:00">
      <person>Elena Stepanova</person>
      <subject>
<![CDATA[Re: Benchmark Query 4x Faster on MySQL 5.5]]>      </subject>
      <content>
<![CDATA[I've got similar difference on my machine on the latest releases (all release tarball packages):

MariaDB 5.5.24: ~25 sec
MariaDB 5.3.7: ~25 sec
MariaDB 5.2.12: ~8 sec
MySQL 5.5.25: ~8 sec
MySQL 5.6.5: ~20 sec
]]>      </content>
    </comment>
    <comment commentlink="https://api.launchpad.net/1.0/maria/+bug/1008334/comments/2" datecreated="2012-06-07T12:52:08.981731+00:00">
      <person>Vladislav Vaintroub</person>
      <subject>
<![CDATA[Re: Benchmark Query 4x Faster on MySQL 5.5]]>      </subject>
      <content>
<![CDATA[Was there a real-life workload that goes much slower with MariaDB 5.5  or was this merely out-of-curiosity type of question?

If this is out-of-curiousity, the explanation is this:

MariaDB implemented microseconds precision for temporal datatypes. In the past, internal representation of temporal datatypes was 64 bit integer. Now, it is decimal. Decimals are slower than integers in many scenarios .

Now, there are still  some optimizations to speed up datetimes and avoid decimals in different scenarios. For example, FROM_UNIXTIME understands that its parameter is integer and does not do decimal arithmetic in this case. In your example, FROM_UNIXTIME gets a double parameter and thus needs to be converted into decimal.

Thus, you can speed up your query by roughly 50%, if you rewrite it as

BENCHMARK(10000000,DATE_SUB(FROM_UNIXTIME(FLOOR(RAND() * 2147483648)), INTERVAL (FLOOR(1 + RAND() * 365)) DAY)) 

Note the FROM_UNIXTIME(FLOOR(...)), FLOOR was not there in original query.

]]>      </content>
    </comment>
    <comment commentlink="https://api.launchpad.net/1.0/maria/+bug/1008334/comments/3" datecreated="2012-06-07T15:15:11.245913+00:00">
      <person>Brian Boatright</person>
      <subject>
<![CDATA[Re: Benchmark Query 4x Faster on MySQL 5.5]]>      </subject>
      <content>
<![CDATA[It wasn't purely out-of-curiosity. It was to confirm the overall performance that MariaDB has vs MySQL. I'm new to MariaDB and not a DB engineer or even a full time DBA.

With your new query forcing a integer result from RAND it is still much slower than MySQL but is faster overall.

Results for new query from my workstation:
- MariaDB 5.3.3 - 15.00 secs
- MySQL  5.5.17 4.04 secs

I would think as a general rule that any query would run at least the same speed if not faster. Even with the FLOOR RAND it it still slower by a significant amount.]]>      </content>
    </comment>
  </comments>
</launchpad-bug>
