diff --git a/myisam/mi_key.c b/myisam/mi_key.c index ab5ddd3a378..d7d10e116aa 100644 --- a/myisam/mi_key.c +++ b/myisam/mi_key.c @@ -242,7 +242,10 @@ uint _mi_pack_key(register MI_INFO *info, uint keynr, uchar *key, uchar *old, { k_length-=length; if (keyseg->flag & (HA_VAR_LENGTH_PART | HA_BLOB_PART)) + { k_length-=2; /* Skip length */ + old+= 2; + } continue; /* Found NULL */ } } diff --git a/mysql-test/include/varchar.inc b/mysql-test/include/varchar.inc index 3ec9d00d05d..13b4315f2b8 100644 --- a/mysql-test/include/varchar.inc +++ b/mysql-test/include/varchar.inc @@ -226,3 +226,13 @@ create table t1 (v varchar(65530), key(v(10))); insert into t1 values(repeat('a',65530)); select length(v) from t1 where v=repeat('a',65530); drop table t1; + +# +# Bug #9489: problem with hash indexes +# + +create table t1(a int, b varchar(12), key ba(b, a)); +insert into t1 values (1, 'A'), (20, NULL); +explain select * from t1 where a=20 and b is null; +select * from t1 where a=20 and b is null; +drop table t1; diff --git a/mysql-test/r/bdb.result b/mysql-test/r/bdb.result index d743bc03675..876da3cb964 100644 --- a/mysql-test/r/bdb.result +++ b/mysql-test/r/bdb.result @@ -1858,6 +1858,15 @@ select length(v) from t1 where v=repeat('a',65530); length(v) 65530 drop table t1; +create table t1(a int, b varchar(12), key ba(b, a)); +insert into t1 values (1, 'A'), (20, NULL); +explain select * from t1 where a=20 and b is null; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref ba ba 20 const,const 1 Using where +select * from t1 where a=20 and b is null; +a b +20 NULL +drop table t1; create table t1 (v varchar(65530), key(v)); Warnings: Warning 1071 Specified key was too long; max key length is 255 bytes diff --git a/mysql-test/r/innodb.result b/mysql-test/r/innodb.result index ccd8601ace0..d6cfefff9e6 100644 --- a/mysql-test/r/innodb.result +++ b/mysql-test/r/innodb.result @@ -2359,6 +2359,15 @@ select length(v) from t1 where v=repeat('a',65530); length(v) 65530 drop table t1; +create table t1(a int, b varchar(12), key ba(b, a)); +insert into t1 values (1, 'A'), (20, NULL); +explain select * from t1 where a=20 and b is null; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref ba ba 20 const,const 1 Using where; Using index +select * from t1 where a=20 and b is null; +a b +20 NULL +drop table t1; create table t1 (v varchar(65530), key(v)); ERROR HY000: Can't create table './test/t1' (errno: 139) create table t1 (v varchar(65536)); diff --git a/mysql-test/r/myisam.result b/mysql-test/r/myisam.result index 539df03e6f9..1a8ace98d05 100644 --- a/mysql-test/r/myisam.result +++ b/mysql-test/r/myisam.result @@ -1157,6 +1157,15 @@ select length(v) from t1 where v=repeat('a',65530); length(v) 65530 drop table t1; +create table t1(a int, b varchar(12), key ba(b, a)); +insert into t1 values (1, 'A'), (20, NULL); +explain select * from t1 where a=20 and b is null; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref ba ba 20 const,const 1 Using where; Using index +select * from t1 where a=20 and b is null; +a b +20 NULL +drop table t1; create table t1 (v varchar(65530), key(v)); Warnings: Warning 1071 Specified key was too long; max key length is 1000 bytes