Commit 7fa67e39 authored by Daniel Black's avatar Daniel Black Committed by Sergey Vojtovich

heap: remove NEW_HASH_FUNCTION

This was added in 29fa7252 (in 2000) and nothing defines
NEW_HASH_FUNCTION. A low collision is the wrong tradeoff,
it should be focused on throughput.

d405bee0 shows the existing function
is pretty cpu intensive and needs to be improved as well.
parent 438811b4
......@@ -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)
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment