Bug #38878 Strange execution times benchmarking 2 equivalent math operations
Submitted: 19 Aug 2008 1:02 Modified: 19 Sep 2008 5:39
Reporter: Federico Razzoli (OCA) Email Updates:
Status: No Feedback Impact on me:
None 
Category:MySQL Server Severity:S5 (Performance)
Version:5.0.51a OS:Linux (Ubuntu 8.04)
Assigned to: CPU Architecture:Any

[19 Aug 2008 1:02] Federico Razzoli
Description:
As you know, the following math expressions are equivalent:

>> a * b + a * c
>> a * (b + c)

I noticed that MySQL seems to resolve the first expression much slower. Meybe it's not optimized?

How to repeat:
Here my personal (poor) benchmark results on my computer. (No other connections to MySQL, no other apps running)

Query: SELECT BENCHMARK(1000000, a * b + a * c) FROM t1
Execution times reported: 2.43, 2.65, 2.48, 2.54, 2.38

Query: SELECT BENCHMARK(1000000, a * (b + c)) FROM t1
Execution times: 1.03, 1.29, 1.08, 1.16, 1.15

More than twice faster...
[19 Aug 2008 5:39] Valeriy Kravchuk
Results should be the same, but computation will be performed differently. Multiplication on float numbers will be slower than addition. So, 2 multiplications vs. one is the reason, likely.

Please, send SHOW CREATE TABLE for that t1 table.
[19 Sep 2008 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".