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, ...@@ -224,7 +224,7 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
if (uniques) if (uniques)
{ {
max_key_block_length= MI_KEY_BLOCK_LENGTH; 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++) 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, ...@@ -24,7 +24,7 @@ my_bool mi_check_unique(MI_INFO *info, MI_UNIQUEDEF *def, byte *record,
{ {
my_off_t lastpos=info->lastpos; my_off_t lastpos=info->lastpos;
MI_KEYDEF *key= &info->s->keyinfo[def->key]; 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"); DBUG_ENTER("mi_check_unique");
mi_unique_store(record+key->seg->start, unique_hash); mi_unique_store(record+key->seg->start, unique_hash);
...@@ -80,8 +80,17 @@ ha_checksum mi_unique_hash(MI_UNIQUEDEF *def, const byte *record) ...@@ -80,8 +80,17 @@ ha_checksum mi_unique_hash(MI_UNIQUEDEF *def, const byte *record)
if (keyseg->null_bit) if (keyseg->null_bit)
{ {
if (record[keyseg->null_pos] & 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; continue;
} }
}
pos= record+keyseg->start; pos= record+keyseg->start;
if (keyseg->flag & HA_VAR_LENGTH) if (keyseg->flag & HA_VAR_LENGTH)
{ {
......
...@@ -102,3 +102,11 @@ pid c1id c2id value id active id active ...@@ -102,3 +102,11 @@ pid c1id c2id value id active id active
1 4 NULL 4 4 Yes NULL NULL 1 4 NULL 4 4 Yes NULL NULL
max(value) max(value)
4 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 = ...@@ -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 c2.id AND c2.active = 'Yes' WHERE m.pid=1 AND (c1.id IS NOT NULL OR c2.id IS
NOT NULL); NOT NULL);
drop table t1,t2,t3; 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