Bug #69057 Wasted work in partition_info::set_up_charset_field_preps()
Submitted: 24 Apr 2013 17:41 Modified: 13 Jun 2013 13:51
Reporter: Po-Chun Chang (OCA) Email Updates:
Status: No Feedback Impact on me:
None 
Category:MySQL Server: Partitions Severity:S5 (Performance)
Version:5.1 OS:Any
Assigned to: CPU Architecture:Any
Tags: patch, performance

[24 Apr 2013 17:41] Po-Chun Chang
Description:
The problem appears in cluster-7.1 revision 4593.  I attached a
one-line patch that fixes it.

In method "partition_info::set_up_charset_field_preps()", the loop
over "part_charset_field_array" (line 1267) should break immediately
after "found" is set to "TRUE".  All the iterations after "found" is
set to "TRUE" do not perform any useful work, at best they just set
"found" again to "TRUE".

Method "partition_info::is_full_part_expr_in_fields(List<Item>&fields)" 
in 5.6 revision 4868 has a similar loop (line 2201), and this loop
breaks immediately after "found" is set to "true", just like in the
proposed patch.

There is also a correctness bug in
"partition_info::set_up_charset_field_preps()" in the same loop over
"part_charset_field_array" (line 1267).  Instead of:

"if (field == part_charset_field_array[i])"

the check should be:

"if (field == part_charset_field_array[j])"

i.e., "part_charset_field_array" should be indexed with "j", not with "i".

How to repeat:
Once partition_info::set_up_charset_field_preps() is being executed.

Suggested fix:
=== modified file 'sql/partition_info.cc'
--- sql/partition_info.cc	2011-06-30 15:55:35 +0000
+++ sql/partition_info.cc	2013-04-22 23:18:19 +0000
@@ -1265,7 +1265,10 @@
       for (j= 0; j < tot_part_fields; j++)
       {
         if (field == part_charset_field_array[i])
+        {
           found= TRUE;
+          break;
+        }
       }
       if (!found)
       {
[24 Apr 2013 17:45] Po-Chun Chang
Suggested patch

Attachment: patch.diff (text/x-patch), 375 bytes.

[8 May 2013 18:57] Po-Chun Chang
Change the severity.
[13 May 2013 7:11] MySQL Verification Team
Thank you for the bug report and contribution.
[13 May 2013 13:51] Mattias Jonsson
Thank you for noticing this bug. Do you have a testcase where this is hit?

I cannot find that the code is used, since range partitioning is not possible for character fields.

So it exists, but probably is never used in mysql-5.1 and cluster-7.1, but was replaced in mysql 5.5+ and cluster 7.2+, so it is unlikely that we will alter the code in 5.1/7.1.
[14 Jun 2013 1: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".