Bug #69117 Wasted work in method myisamchk
Submitted: 2 May 2013 2:07 Modified: 1 Jul 2013 16:38
Reporter: Po-Chun Chang (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S5 (Performance)
Version:5.6, 5.7 OS:Any
Assigned to: CPU Architecture:Any
Tags: patch, performance

[2 May 2013 2:07] Po-Chun Chang
Description:
The problem appears in version 5.6 and in the latest revision 5216 in
version 5.7.  I attached a one-line patch that fixes it.

In method "myisamchk" in myisamchk.c, the loop on "share->keyinfo"
(line 1032) should break immediately after "update_index" is set to 0.
All the iterations after "update_index" is set to 0 do not perform any
useful work, at best they just set "update_index" again to 0.

How to repeat:
As long as myisamchk() is executed.

Suggested fix:
=== modified file 'storage/myisam/myisamchk.c'
--- storage/myisam/myisamchk.c	2013-02-26 06:21:48 +0000
+++ storage/myisam/myisamchk.c	2013-05-01 22:55:40 +0000
@@ -1029,8 +1029,10 @@
 	  */
 	  my_bool update_index=1;
 	  for (key=0 ; key < share->base.keys; key++)
-	    if (share->keyinfo[key].flag & (HA_BINARY_PACK_KEY|HA_FULLTEXT))
+	    if (share->keyinfo[key].flag & (HA_BINARY_PACK_KEY|HA_FULLTEXT)) {
 	      update_index=0;
+	      break;
+	    }
 
 	  error=mi_sort_records(param,info,filename,param->opt_sort_key,
                              /* what is the following parameter for ? */
[2 May 2013 2:07] Po-Chun Chang
Suggested patch

Attachment: patch.diff (text/plain), 602 bytes.

[26 Jun 2013 3:00] 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), 602 bytes.

[27 Jun 2013 13:40] Ståle Deraas
Thank you for your contribution. We will include it in a coming release.
[1 Jul 2013 16:38] 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.