Bug #69553 Wasted work in method mi_test_if_sort_rep()
Submitted: 23 Jun 2013 13:56 Modified: 1 Jul 2013 16:36
Reporter: Po-Chun Chang (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: MyISAM storage engine Severity:S5 (Performance)
Version:5.6, 5.7 OS:Any
Assigned to:
Tags: patch, performance

[23 Jun 2013 13:56] Po-Chun Chang
Description:
The problem appears in version 5.6 and in the revision 5216 in
version 5.7.  I attached a one-line patch that fixes it.

In method "mi_test_if_sort_rep" in mi_check.c, the loop on
line 4706 should not be executed when "force" is TRUE.  
When "force" is TRUE, all the iterations do not perform any useful work.

How to repeat:
Once mi_test_if_sort_rep() is executed.

Suggested fix:
=== modified file 'storage/myisam/mi_check.c'
--- storage/myisam/mi_check.c	2013-02-27 15:33:55 +0000
+++ storage/myisam/mi_check.c	2013-06-23 13:54:44 +0000
@@ -4703,10 +4703,13 @@
   */
   if (! mi_is_any_key_active(key_map))
     return FALSE;				/* Can't use sort */
-  for (i=0 ; i < share->base.keys ; i++,key++)
+  if (!force)
   {
-    if (!force && mi_too_big_key_for_sort(key,rows))
-      return FALSE;
+    for (i=0 ; i < share->base.keys ; i++,key++)
+    {
+      if (mi_too_big_key_for_sort(key,rows))
+        return FALSE;
+    }
   }
   return TRUE;
 }
[23 Jun 2013 13:57] Po-Chun Chang
Suggested patch

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: patch.diff (text/plain), 572 bytes.

[24 Jun 2013 6:57] Umesh Shastry
Hello Chang,

Thank you for the report and contribution.

Regards,
Umesh
[27 Jun 2013 13:41] Ståle Deraas
Thank you for your contribution. We will include it in a coming release.
[1 Jul 2013 16:36] Paul Dubois
Noted in 5.7.2 changelog.

Several inefficiencies were corrected:

A loop in Item_in_subselect::single_value_transformer() could execute
too many times. 

The myisamchk(), my_test_if_sort_rep(), and recreate_table()
functions in MyISAM code could execute too many times.

Thanks to Po-Chun Chang for the patches to correct these issues.