#At file:///home/igor/dev-bzr/mysql-6.0-opt-bug42593/ based on revid:igor@stripped
2697 Igor Babaev 2009-02-12
Fixed bug #42593.
The method JOIN_CACHE_BKA_UNIQUE::join_matching_record
calls JOIN_CACHE_BKA::init_join_matching_records that
calls the handler function multi_range_read_init.
The code before the fix erroneously always passed numbers
of records in the join buffer as the third parameter for
the call of multi_range_read_init. Yet this parameter
must specify the number of ranges passed to the MRR
interface for processing. If a join cache of the type
JOIN_CACHE_BKA_UNIQUE is employed the number of distinct
keys occurred in the records from the join buffer must
be passed as the required number of ranges to the function
multi_range_read_init.
Currently only the NDB implementation of the
multi_range_read_init handler function really uses
the expected number of ranges.
modified:
mysql-test/suite/ndb/r/ndb_read_multi_range.result
mysql-test/suite/ndb/t/ndb_read_multi_range.test
sql/sql_join_cache.cc
sql/sql_select.h
per-file messages:
mysql-test/suite/ndb/r/ndb_read_multi_range.result
Added a test case for bug #42593.
mysql-test/suite/ndb/t/ndb_read_multi_range.test
Added a test case for bug #42593.
sql/sql_join_cache.cc
Fixed bug #42593.
Now the number of distinct keys occurred in the records
from the join buffer of the JOIN_CACHE_BKA_UNIQUE type is
calculated. This number is passed as a parameter in the
call of the multi_range_read_init function invoked in
JOIN_CACHE_BKA::init_join_matching_records. The latter
has been modified to accept this number as a parameter.
sql/sql_select.h
Fixed bug #42593.
In the class JOIN_CACHE_BKA_UNIQUE a member to store the
number of key entries in the hash table - the number of distinct keys occurred in the records from the join buffer
-has been added.
=== modified file 'mysql-test/suite/ndb/r/ndb_read_multi_range.result'
--- a/mysql-test/suite/ndb/r/ndb_read_multi_range.result 2009-02-02 15:58:48 +0000
+++ b/mysql-test/suite/ndb/r/ndb_read_multi_range.result 2009-02-13 05:56:16 +0000
@@ -692,3 +692,34 @@ i i 9
m m 13
v v 22
drop table t1, t2;
+create table t1 (
+uid int, fid int, index(uid)
+) engine=ndb;
+insert into t1 values
+(1,1), (1,2), (1,3), (1,4),
+(2,5), (2,6), (2,7), (2,8),
+(3,1), (3,2), (3,9);
+create table t2 (
+uid int primary key, name varchar(128), index(name)
+) engine=ndb;
+insert into t2 values
+(1, "A"), (2, "B"), (3, "C"), (4, "D"), (5, "E"),
+(6, "F"), (7, "G"), (8, "H"), (9, "I");
+set join_cache_level=7;
+select name from t2, t1
+where t1.uid in (select t2.uid from t2, t1 where t1.uid=1 and t2.uid=t1.fid)
+and t2.uid=t1.fid;
+name
+A
+A
+B
+B
+C
+D
+E
+F
+G
+H
+I
+set join_cache_level=default;
+drop table t1,t2;
=== modified file 'mysql-test/suite/ndb/t/ndb_read_multi_range.test'
--- a/mysql-test/suite/ndb/t/ndb_read_multi_range.test 2009-02-02 15:58:48 +0000
+++ b/mysql-test/suite/ndb/t/ndb_read_multi_range.test 2009-02-13 05:56:16 +0000
@@ -535,3 +535,35 @@ select * from t1
or (a = 'v')
order by a asc, b asc;
drop table t1, t2;
+
+
+
+#
+# bug#42593: batched key access join employing a hash table
+#
+
+create table t1 (
+ uid int, fid int, index(uid)
+) engine=ndb;
+insert into t1 values
+ (1,1), (1,2), (1,3), (1,4),
+ (2,5), (2,6), (2,7), (2,8),
+ (3,1), (3,2), (3,9);
+
+create table t2 (
+ uid int primary key, name varchar(128), index(name)
+) engine=ndb;
+insert into t2 values
+ (1, "A"), (2, "B"), (3, "C"), (4, "D"), (5, "E"),
+ (6, "F"), (7, "G"), (8, "H"), (9, "I");
+
+set join_cache_level=7;
+
+--sorted_result
+select name from t2, t1
+ where t1.uid in (select t2.uid from t2, t1 where t1.uid=1 and t2.uid=t1.fid)
+ and t2.uid=t1.fid;
+
+set join_cache_level=default;
+
+drop table t1,t2;
=== modified file 'sql/sql_join_cache.cc'
--- a/sql/sql_join_cache.cc 2009-02-12 18:27:05 +0000
+++ b/sql/sql_join_cache.cc 2009-02-13 05:56:16 +0000
@@ -2242,7 +2242,7 @@ enum_nested_loop_state JOIN_CACHE_BKA::j
if (!records)
return NESTED_LOOP_OK;
- rc= init_join_matching_records(&seq_funcs);
+ rc= init_join_matching_records(&seq_funcs, records);
if (rc != NESTED_LOOP_OK)
goto finish;
@@ -2286,6 +2286,7 @@ finish:
SYNOPSIS
init_join_matching_records()
seq_funcs structure of range sequence interface
+ ranges number of keys/ranges in the sequence
DESCRIPTION
This function calls the multi_range_read_init function to set up
@@ -2298,14 +2299,16 @@ finish:
intended invocation of the join_matching_records method. The
multi_range_read_init function also receives the parameters for
MRR buffer to be used and flags specifying the mode in which
- this buffer will be functioning.
+ this buffer will be functioning.
+ The number of keys in the sequence expected by multi_range_read_init
+ is passed through the parameter ranges.
RETURN
return one of enum_nested_loop_state
*/
enum_nested_loop_state
-JOIN_CACHE_BKA::init_join_matching_records(RANGE_SEQ_IF *seq_funcs)
+JOIN_CACHE_BKA::init_join_matching_records(RANGE_SEQ_IF *seq_funcs, uint ranges)
{
int error;
handler *file= join_tab->table->file;
@@ -2331,7 +2334,7 @@ JOIN_CACHE_BKA::init_join_matching_recor
*/
if (!file->inited)
file->ha_index_init(join_tab->ref.key, 1);
- if ((error= file->multi_range_read_init(seq_funcs, (void*) this, records,
+ if ((error= file->multi_range_read_init(seq_funcs, (void*) this, ranges,
mrr_mode, &mrr_buff)))
rc= error < 0 ? NESTED_LOOP_NO_MORE_ROWS: NESTED_LOOP_ERROR;
@@ -2525,6 +2528,7 @@ int JOIN_CACHE_BKA_UNIQUE::init()
DBUG_ENTER("JOIN_CACHE_BKA_UNIQUE::init");
hash_table= 0;
+ key_entries= 0;
if ((rc= JOIN_CACHE_BKA::init()))
DBUG_RETURN (rc);
@@ -2704,6 +2708,8 @@ bool JOIN_CACHE_BKA_UNIQUE::put_record()
memcpy(cp, key, key_len);
}
last_key_entry= cp;
+ /* Increment the counter of key_entries in the hash table */
+ key_entries++;
}
return is_full;
}
@@ -2861,6 +2867,7 @@ void JOIN_CACHE_BKA_UNIQUE:: cleanup_has
{
last_key_entry= hash_table;
bzero(hash_table, (buff+buff_size)-hash_table);
+ key_entries= 0;
}
@@ -3109,7 +3116,7 @@ JOIN_CACHE_BKA_UNIQUE::join_matching_rec
if (!records)
return NESTED_LOOP_OK;
- rc= init_join_matching_records(&seq_funcs);
+ rc= init_join_matching_records(&seq_funcs, key_entries);
if (rc != NESTED_LOOP_OK)
goto finish;
=== modified file 'sql/sql_select.h'
--- a/sql/sql_select.h 2009-01-26 15:07:22 +0000
+++ b/sql/sql_select.h 2009-02-13 05:56:16 +0000
@@ -819,7 +819,8 @@ protected:
enum_nested_loop_state join_matching_records(bool skip_last);
/* Prepare to search for records that match records from the join buffer */
- enum_nested_loop_state init_join_matching_records(RANGE_SEQ_IF *seq_funcs);
+ enum_nested_loop_state init_join_matching_records(RANGE_SEQ_IF *seq_funcs,
+ uint ranges);
/* Finish searching for records that match records from the join buffer */
enum_nested_loop_state end_join_matching_records(enum_nested_loop_state rc);
@@ -974,6 +975,9 @@ private:
/* Number of hash entries in the hash table */
uint hash_entries;
+ /* Number of key entries in the hash table (number of distinct keys) */
+ uint key_entries;
+
/* The position of the last key entry in the hash table */
uchar *last_key_entry;
| Thread |
|---|
| • bzr commit into mysql-6.0-opt branch (igor:2697) Bug#42593 | Igor Babaev | 13 Feb |