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
Status tracked in 5.6
5.1
Undecided
Unassigned
5.5
Medium
Alexey Kopytov
5.6
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

lp:~akopytov/percona-server/bug1132350
Merged into lp:percona-server/5.5 at revision 458
Sergei Glushchenko: Approve (g2) on 2013-02-25
lp:~laurynas-biveinis/percona-server/5.6-merge-1
Merged into lp:percona-server at revision 349
Alexey Kopytov: Approve on 2013-05-21
Percona core: Pending requested 2013-05-20
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.