From c8683be463c0618e9d42fe964b1c4e8831fec0e4 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 21 Apr 2005 21:06:08 +0500 Subject: [PATCH 1/2] A fix (Bug #9489: Problem with BIT_OR and MySQL 5.0.3) heap/hp_hash.c: A fix (Bug #9489: Problem with BIT_OR and MySQL 5.0.3). Should take into account key pack length. --- heap/hp_hash.c | 11 +++++++++++ mysql-test/r/type_varchar.result | 11 ++++++++++- mysql-test/t/type_varchar.test | 14 +++++++++++++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/heap/hp_hash.c b/heap/hp_hash.c index 3121ef71fb0..52a250bd7af 100644 --- a/heap/hp_hash.c +++ b/heap/hp_hash.c @@ -255,6 +255,9 @@ ulong hp_hashnr(register HP_KEYDEF *keydef, register const byte *key) if (*pos) /* Found null */ { nr^= (nr << 1) | 1; + /* Add key pack length (2) to key for VARCHAR segments */ + if (seg->type == HA_KEYTYPE_VARTEXT1) + key+= 2; continue; } pos++; @@ -390,6 +393,9 @@ ulong hp_hashnr(register HP_KEYDEF *keydef, register const byte *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++; @@ -584,7 +590,12 @@ int hp_key_cmp(HP_KEYDEF *keydef, const byte *rec, const byte *key) if (found_null != (int) *key++) return 1; if (found_null) + { + /* Add key pack length (2) to key for VARCHAR segments */ + if (seg->type == HA_KEYTYPE_VARTEXT1) + key+= 2; continue; + } } if (seg->type == HA_KEYTYPE_TEXT) { diff --git a/mysql-test/r/type_varchar.result b/mysql-test/r/type_varchar.result index d2fe843a68b..3bd7fe6b175 100644 --- a/mysql-test/r/type_varchar.result +++ b/mysql-test/r/type_varchar.result @@ -1,4 +1,4 @@ -drop table if exists t1; +drop table if exists t1, t2; create table t1 (v varchar(30), c char(3), e enum('abc','def','ghi'), t text); truncate table vchar; show create table t1; @@ -383,3 +383,12 @@ select * from t1; pkcol othercol test somethingelse drop table t1; +create table t1 (a int, b varchar(12)); +insert into t1 values (1, 'A'), (22, NULL); +create table t2 (a int); +insert into t2 values (22), (22); +select t1.a, t1.b, min(t1.b) from t1 inner join t2 ON t2.a = t1.a +group by t1.b, t1.a; +a b min(t1.b) +22 NULL NULL +drop table t1, t2; diff --git a/mysql-test/t/type_varchar.test b/mysql-test/t/type_varchar.test index 9867cf4c057..2bffca6b889 100644 --- a/mysql-test/t/type_varchar.test +++ b/mysql-test/t/type_varchar.test @@ -1,5 +1,5 @@ --disable_warnings -drop table if exists t1; +drop table if exists t1, t2; --enable_warnings create table t1 (v varchar(30), c char(3), e enum('abc','def','ghi'), t text); @@ -106,3 +106,15 @@ insert into t1 values ('test', 'something'); update t1 set othercol='somethingelse' where pkcol='test'; select * from t1; drop table t1; + +# +# Bug #9489: problems with key handling +# + +create table t1 (a int, b varchar(12)); +insert into t1 values (1, 'A'), (22, NULL); +create table t2 (a int); +insert into t2 values (22), (22); +select t1.a, t1.b, min(t1.b) from t1 inner join t2 ON t2.a = t1.a + group by t1.b, t1.a; +drop table t1, t2; From 86d285197ab517ccd16a2175881ee51b5e0dde40 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 26 Apr 2005 19:46:52 +0500 Subject: [PATCH 2/2] A fix (bug #10176: problem with varchar keys). myisam/mi_key.c: A fix (bug #10176: problem with varchar keys). Should skip key pack length for 'old' too. --- myisam/mi_key.c | 3 +++ mysql-test/include/varchar.inc | 10 ++++++++++ mysql-test/r/bdb.result | 9 +++++++++ mysql-test/r/innodb.result | 9 +++++++++ mysql-test/r/myisam.result | 9 +++++++++ 5 files changed, 40 insertions(+) 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