Suboptimal code in my_strnxfrm_simple()

Bug #1132350 reported by Alexey Kopytov on 2013-02-24
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
MySQL Server
Unknown
Unknown
Percona Server moved to https://jira.percona.com/projects/PS
Fix Released
Medium
Laurynas Biveinis
5.1
Won't Fix
Undecided
Unassigned
5.5
Fix Released
Medium
Alexey Kopytov
5.6
Fix Released
Medium
Laurynas Biveinis

Bug Description

This ancient code in my_strnxfrm_simple() is suboptimal:

  if (dest != src)
  {
    const uchar *end;
    for ( end=src+len; src < end ; )
      *dest++= map[*src++];
  }
  else
  {
    const uchar *end;
    for ( end=dest+len; dest < end ; dest++)
      *dest= (char) map[(uchar) *dest];
  }

I can't see any difference between these branches. It's probably
remnants from _bin collations, where we don't have to do table
translation and thus the "dest == src" case is degenerate, e.g.:

static size_t my_strnxfrm_bin(CHARSET_INFO *cs __attribute__((unused)),
                              uchar *dest, size_t dstlen,
                              const uchar *src, size_t srclen)
{
  if (dest != src)
    memcpy(dest, src, min(dstlen,srclen));
  if (dstlen > srclen)
    bfill(dest + srclen, dstlen - srclen, 0);
  return dstlen;
}

But the "if()" statement in my_strnxfrm_simple() is redundant. It is
executed for each row processed by filesort and shows high branch
misprediction numbers in sysbench RO runs.

Related branches

Percona now uses JIRA for bug reports so this bug report is migrated to: https://jira.percona.com/browse/PS-1320

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.