summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--myisam/mi_create.c2
-rw-r--r--myisam/mi_unique.c11
-rw-r--r--mysql-test/r/group_by.result8
-rw-r--r--mysql-test/t/group_by.test11
4 files changed, 30 insertions, 2 deletions
diff --git a/myisam/mi_create.c b/myisam/mi_create.c
index 6941db158e1..5a5a49533da 100644
--- a/myisam/mi_create.c
+++ b/myisam/mi_create.c
@@ -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++)
diff --git a/myisam/mi_unique.c b/myisam/mi_unique.c
index e598fbeedb4..7f1e6b83a12 100644
--- a/myisam/mi_unique.c
+++ b/myisam/mi_unique.c
@@ -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)
diff --git a/mysql-test/r/group_by.result b/mysql-test/r/group_by.result
index 0b720bc3d97..3bd3eeb5efd 100644
--- a/mysql-test/r/group_by.result
+++ b/mysql-test/r/group_by.result
@@ -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
diff --git a/mysql-test/t/group_by.test b/mysql-test/t/group_by.test
index db6baec4b9f..b21ae88007b 100644
--- a/mysql-test/t/group_by.test
+++ b/mysql-test/t/group_by.test
@@ -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;