Bug #69561 Wasted work in method recreate_table()
Submitted: 25 Jun 2013 2:33 Modified: 1 Jul 2013 16:37
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: CPU Architecture:Any
Tags: patch, performance

[25 Jun 2013 2:33] Po-Chun Chang
Description:
The problem appears in version 5.6 and in the revision 5216 in
version 5.7.  I attached a patch that fixes it.

In method "recreate_table" in mi_check.c, the loop on
line 4273 should not be executed when "pack" is FALSE.  
When "pack" is FALSE, all the iterations do not perform any useful work.

How to repeat:
Once recreate_table() 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-25 02:31:36 +0000
@@ -4270,13 +4270,15 @@
   /* Copy the column definitions */
   memcpy((uchar*) recdef,(uchar*) share.rec,
 	 (size_t) (sizeof(MI_COLUMNDEF)*(share.base.fields+1)));
-  for (rec=recdef,end=recdef+share.base.fields; rec != end ; rec++)
+  if (unpack && !(share.options & HA_OPTION_PACK_RECORD))
   {
-    if (unpack && !(share.options & HA_OPTION_PACK_RECORD) &&
-	rec->type != FIELD_BLOB &&
-	rec->type != FIELD_VARCHAR &&
-	rec->type != FIELD_CHECK)
-      rec->type=(int) FIELD_NORMAL;
+    for (rec=recdef,end=recdef+share.base.fields; rec != end ; rec++)
+    {
+      if (rec->type != FIELD_BLOB &&
+  	rec->type != FIELD_VARCHAR &&
+  	rec->type != FIELD_CHECK)
+        rec->type=(int) FIELD_NORMAL;
+    }
   }
 
   /* Change the new key to point at the saved key segments */
[25 Jun 2013 2:36] 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), 943 bytes.

[25 Jun 2013 5:42] MySQL Verification Team
Hello Chang,

Thank you for the report and contribution.

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