Commit f22fde21 authored by monty@mashka.mysql.fi's avatar monty@mashka.mysql.fi

Fixed max_key_length when using UNIQUE keys.

This fixed a bug in GROUP BY on a BLOB column with NULL values.
parent fc8a7895
......@@ -224,7 +224,7 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
if (uniques)
{
max_key_block_length= MI_KEY_BLOCK_LENGTH;
max_key_length= MI_UNIQUE_HASH_LENGTH;
max_key_length= MI_UNIQUE_HASH_LENGTH + pointer;
}
for (i=0, keydef=keydefs ; i < keys ; i++ , keydef++)
......
......@@ -24,7 +24,7 @@ my_bool mi_check_unique(MI_INFO *info, MI_UNIQUEDEF *def, byte *record,
{
my_off_t lastpos=info->lastpos;
MI_KEYDEF *key= &info->s->keyinfo[def->key];
uchar *key_buff=info->lastkey+info->s->base.max_key_length;
uchar *key_buff=info->lastkey2;
DBUG_ENTER("mi_check_unique");
mi_unique_store(record+key->seg->start, unique_hash);
......@@ -80,7 +80,16 @@ ha_checksum mi_unique_hash(MI_UNIQUEDEF *def, const byte *record)
if (keyseg->null_bit)
{
if (record[keyseg->null_pos] & keyseg->null_bit)
{
/*
Change crc in a way different from an empty string or 0.
(This is an optimisation; The code will work even if this isn't
done)
*/
crc=((crc << 8) + 511+
(crc >> (8*sizeof(ha_checksum)-8)));
continue;
}
}
pos= record+keyseg->start;
if (keyseg->flag & HA_VAR_LENGTH)
......
......@@ -102,3 +102,11 @@ pid c1id c2id value id active id active
1 4 NULL 4 4 Yes NULL NULL
max(value)
4
a count(*)
NULL 9
3
b 1
a count(*)
NULL 9
3
b 1
......@@ -312,3 +312,14 @@ m.c1id = c1.id AND c1.active = 'Yes' LEFT JOIN t3 AS c2 ON m.c2id =
c2.id AND c2.active = 'Yes' WHERE m.pid=1 AND (c1.id IS NOT NULL OR c2.id IS
NOT NULL);
drop table t1,t2,t3;
#
# Test bug in GROUP BY on BLOB that is NULL or empty
#
create table t1 (a blob null);
insert into t1 values (NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(""),(""),(""),("b");
select a,count(*) from t1 group by a;
set option sql_big_tables=1;
select a,count(*) from t1 group by a;
drop table t1;
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