diff options
author | unknown <ingo@mysql.com> | 2004-06-22 17:27:57 +0200 |
---|---|---|
committer | unknown <ingo@mysql.com> | 2004-06-22 17:27:57 +0200 |
commit | 8f3b8de2727a8200e0780e6aa8c78760c8eaa1d1 (patch) | |
tree | 1b7296aae4148b71f0a0197d64a51b5728af6d7e | |
parent | 4d39221a0f012c10cb0d59f754eaa61c276b573e (diff) | |
download | mariadb-git-8f3b8de2727a8200e0780e6aa8c78760c8eaa1d1.tar.gz |
bug#2688 - Wrong index_merge query results for BDB table with variable length primary key.
dded code to clear the tail of the reference buffer if the actual key length
is less than the maximum key length.
mysql-test/r/bdb.result:
bug#2688 - Wrong index_merge query results for BDB table with variable length primary key.
Added the test case results.
mysql-test/t/bdb.test:
bug#2688 - Wrong index_merge query results for BDB table with variable length primary key.
Added the test case.
sql/ha_berkeley.cc:
bug#2688 - Wrong index_merge query results for BDB table with variable length primary key.
Added code to clear the tail of the reference buffer if the actual key length
is less than the maximum key length.
-rw-r--r-- | mysql-test/r/bdb.result | 18 | ||||
-rw-r--r-- | mysql-test/t/bdb.test | 18 | ||||
-rw-r--r-- | sql/ha_berkeley.cc | 31 |
3 files changed, 67 insertions, 0 deletions
diff --git a/mysql-test/r/bdb.result b/mysql-test/r/bdb.result index 2ccb5148d58..7d4b42e6a8c 100644 --- a/mysql-test/r/bdb.result +++ b/mysql-test/r/bdb.result @@ -1190,3 +1190,21 @@ a A a drop table t1; +create table t1 ( +pk1 varchar(8) not null default '', +pk2 varchar(4) not null default '', +key1 int(11) default null, +key2 int(11) default null, +primary key (pk1,pk2), +key key1 (key1), +key key2 (key2)) engine=bdb; +insert into t1 values ('','empt',2,2), ('a','a--a',2,2), +('bb','b--b',2,2), ('ccc','c--c',2,2), ('dddd','d--d',2,2); +select * from t1 force index(key1, key2) where key1 < 3 or key2 < 3; +pk1 pk2 key1 key2 + empt 2 2 +a a--a 2 2 +bb b--b 2 2 +ccc c--c 2 2 +dddd d--d 2 2 +drop table t1; diff --git a/mysql-test/t/bdb.test b/mysql-test/t/bdb.test index 4b490052535..bed0cbe269d 100644 --- a/mysql-test/t/bdb.test +++ b/mysql-test/t/bdb.test @@ -829,3 +829,21 @@ alter table t1 modify a char(10) binary; explain select a from t1; select a from t1; drop table t1; + +# +# bug#2688 - Wrong index_merge query results for BDB table with variable length primary key +# + +create table t1 ( + pk1 varchar(8) not null default '', + pk2 varchar(4) not null default '', + key1 int(11) default null, + key2 int(11) default null, + primary key (pk1,pk2), + key key1 (key1), + key key2 (key2)) engine=bdb; +insert into t1 values ('','empt',2,2), ('a','a--a',2,2), + ('bb','b--b',2,2), ('ccc','c--c',2,2), ('dddd','d--d',2,2); +select * from t1 force index(key1, key2) where key1 < 3 or key2 < 3; +drop table t1; + diff --git a/sql/ha_berkeley.cc b/sql/ha_berkeley.cc index 3522aadf349..18af688d07c 100644 --- a/sql/ha_berkeley.cc +++ b/sql/ha_berkeley.cc @@ -1611,13 +1611,44 @@ int ha_berkeley::rnd_pos(byte * buf, byte *pos) (char*) buf, primary_key, ¤t_row, (DBT*) 0, 0)); } +/* + Set a reference to the current record in (ref,ref_length). + + SYNOPSIS + ha_berkeley::position() + record The current record buffer + + DESCRIPTION + The BDB handler stores the primary key in (ref,ref_length). + There is either an explicit primary key, or an implicit (hidden) + primary key. + During open(), 'ref_length' is calculated as the maximum primary + key length. When an actual key is shorter than that, the rest of + the buffer must be cleared out. The row cannot be identified, if + garbage follows behind the end of the key. There is no length + field for the current key, so that the whole ref_length is used + for comparison. + + RETURN + nothing +*/ + void ha_berkeley::position(const byte *record) { DBT key; + DBUG_ENTER("ha_berkeley::position"); if (hidden_primary_key) + { + DBUG_ASSERT(ref_length == BDB_HIDDEN_PRIMARY_KEY_LENGTH); memcpy_fixed(ref, (char*) current_ident, BDB_HIDDEN_PRIMARY_KEY_LENGTH); + } else + { create_key(&key, primary_key, (char*) ref, record); + if (key.size < ref_length) + bzero(ref + key.size, ref_length - key.size); + } + DBUG_VOID_RETURN; } |