Skip to content

Commit

Permalink
heap: remove NEW_HASH_FUNCTION
Browse files Browse the repository at this point in the history
This was added in 29fa725 (in 2000) and nothing defines
NEW_HASH_FUNCTION. A low collision is the wrong tradeoff,
it should be focused on throughput.

d405bee shows the existing function
is pretty cpu intensive and needs to be improved as well.
  • Loading branch information
grooverdan authored and Sergey Vojtovich committed Feb 13, 2019
1 parent 438811b commit 7fa67e3
Showing 1 changed file with 0 additions and 132 deletions.
132 changes: 0 additions & 132 deletions storage/heap/hp_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,6 @@ void hp_movelink(HASH_INFO *pos, HASH_INFO *next_link, HASH_INFO *newlink)
return;
}

#ifndef NEW_HASH_FUNCTION

/* Calc hashvalue for a key */

ulong hp_hashnr(register HP_KEYDEF *keydef, register const uchar *key)
Expand Down Expand Up @@ -350,136 +348,6 @@ ulong hp_rec_hashnr(register HP_KEYDEF *keydef, register const uchar *rec)
return(nr);
}

#else

/*
* Fowler/Noll/Vo hash
*
* The basis of the hash algorithm was taken from an idea sent by email to the
* IEEE Posix P1003.2 mailing list from Phong Vo (kpv@research.att.com) and
* Glenn Fowler (gsf@research.att.com). Landon Curt Noll (chongo@toad.com)
* later improved on their algorithm.
*
* The magic is in the interesting relationship between the special prime
* 16777619 (2^24 + 403) and 2^32 and 2^8.
*
* This hash produces the fewest collisions of any function that we've seen so
* far, and works well on both numbers and strings.
*/

ulong hp_hashnr(register HP_KEYDEF *keydef, register const uchar *key)
{
/*
Note, if a key consists of a combination of numeric and
a text columns, it most likely won't work well.
Making text columns work with NEW_HASH_FUNCTION
needs also changes in strings/ctype-xxx.c.
*/
ulong nr= 1, nr2= 4;
HA_KEYSEG *seg,*endseg;

for (seg=keydef->seg,endseg=seg+keydef->keysegs ; seg < endseg ; seg++)
{
uchar *pos=(uchar*) key;
key+=seg->length;
if (seg->null_bit)
{
key++;
if (*pos)
{
nr^= (nr << 1) | 1;
/* Add key pack length (2) to key for VARCHAR segments */
if (seg->type == HA_KEYTYPE_VARTEXT1)
key+= 2;
continue;
}
pos++;
}
if (seg->type == HA_KEYTYPE_TEXT)
{
seg->charset->coll->hash_sort(seg->charset, pos, ((uchar*)key)-pos,
&nr, &nr2);
}
else if (seg->type == HA_KEYTYPE_VARTEXT1) /* Any VARCHAR segments */
{
uint pack_length= 2; /* Key packing is constant */
uint length= uint2korr(pos);
seg->charset->coll->hash_sort(seg->charset, pos+pack_length, length,
&nr, &nr2);
key+= pack_length;
}
else
{
for ( ; pos < (uchar*) key ; pos++)
{
nr *=16777619;
nr ^=(uint) *pos;
}
}
}
#ifdef ONLY_FOR_HASH_DEBUGGING
DBUG_PRINT("exit", ("hash: 0x%lx", nr));
#endif
return(nr);
}

/* Calc hashvalue for a key in a record */

ulong hp_rec_hashnr(register HP_KEYDEF *keydef, register const uchar *rec)
{
ulong nr= 1, nr2= 4;
HA_KEYSEG *seg,*endseg;

for (seg=keydef->seg,endseg=seg+keydef->keysegs ; seg < endseg ; seg++)
{
uchar *pos=(uchar*) rec+seg->start;
if (seg->null_bit)
{
if (rec[seg->null_pos] & seg->null_bit)
{
nr^= (nr << 1) | 1;
continue;
}
}
if (seg->type == HA_KEYTYPE_TEXT)
{
uint char_length= seg->length; /* TODO: fix to use my_charpos() */
seg->charset->coll->hash_sort(seg->charset, pos, char_length,
&nr, &nr2);
}
else if (seg->type == HA_KEYTYPE_VARTEXT1) /* Any VARCHAR segments */
{
uint pack_length= seg->bit_start;
uint length= (pack_length == 1 ? (uint) *(uchar*) pos : uint2korr(pos));
seg->charset->coll->hash_sort(seg->charset, pos+pack_length,
length, &nr, &nr2);
}
else
{
uchar *end= pos+seg->length;
if (seg->type == HA_KEYTYPE_BIT && seg->bit_length)
{
uchar bits= get_rec_bits(rec + seg->bit_pos,
seg->bit_start, seg->bit_length);
nr *=16777619;
nr ^=(uint) bits;
end--;
}
for ( ; pos < end ; pos++)
{
nr *=16777619;
nr ^=(uint) *pos;
}
}
}
#ifdef ONLY_FOR_HASH_DEBUGGING
DBUG_PRINT("exit", ("hash: 0x%lx", nr));
#endif
return(nr);
}

#endif


/*
Compare keys for two records. Returns 0 if they are identical
Expand Down

0 comments on commit 7fa67e3

Please sign in to comment.