Commit 70107a43 authored by Yoni Fogel's avatar Yoni Fogel

fixes #6086 Merge 6086 to main. We now read in basement nodes if a full...

fixes #6086 Merge 6086 to main.  We now read in basement nodes if a full keyrange resides in it so that we can answer more accurately.


git-svn-id: file:///svn/mysql/tokudb-engine/tokudb-engine@54342 c7de825b-a66e-492c-adef-691d508d4ae1
parent 295d6879
...@@ -7336,13 +7336,13 @@ double ha_tokudb::index_only_read_time(uint keynr, double records) { ...@@ -7336,13 +7336,13 @@ double ha_tokudb::index_only_read_time(uint keynr, double records) {
// //
ha_rows ha_tokudb::records_in_range(uint keynr, key_range* start_key, key_range* end_key) { ha_rows ha_tokudb::records_in_range(uint keynr, key_range* start_key, key_range* end_key) {
TOKUDB_DBUG_ENTER("ha_tokudb::records_in_range"); TOKUDB_DBUG_ENTER("ha_tokudb::records_in_range");
DBT key; DBT *pleft_key = NULL, *pright_key = NULL;
DBT left_key, right_key;
ha_rows ret_val = HA_TOKUDB_RANGE_COUNT; ha_rows ret_val = HA_TOKUDB_RANGE_COUNT;
DB *kfile = share->key_file[keynr]; DB *kfile = share->key_file[keynr];
uint64_t less, equal, greater; uint64_t less, equal1, middle, equal2, greater;
uint64_t total_rows_estimate = HA_TOKUDB_RANGE_COUNT; uint64_t rows;
uint64_t start_rows, end_rows, rows; bool is_exact;
int is_exact;
int error; int error;
uchar inf_byte; uchar inf_byte;
...@@ -7354,80 +7354,57 @@ ha_rows ha_tokudb::records_in_range(uint keynr, key_range* start_key, key_range* ...@@ -7354,80 +7354,57 @@ ha_rows ha_tokudb::records_in_range(uint keynr, key_range* start_key, key_range*
// So, we call key_range64 on the key, and the key that is after it. // So, we call key_range64 on the key, and the key that is after it.
// //
if (!start_key && !end_key) { if (!start_key && !end_key) {
error = estimate_num_rows(kfile, &end_rows, transaction); error = estimate_num_rows(kfile, &rows, transaction);
if (error) { if (error) {
ret_val = HA_TOKUDB_RANGE_COUNT; ret_val = HA_TOKUDB_RANGE_COUNT;
goto cleanup; goto cleanup;
} }
ret_val = (end_rows <= 1) ? 1 : end_rows; ret_val = (rows <= 1) ? 1 : rows;
goto cleanup; goto cleanup;
} }
if (start_key) { if (start_key) {
inf_byte = (start_key->flag == HA_READ_KEY_EXACT) ? inf_byte = (start_key->flag == HA_READ_KEY_EXACT) ?
COL_NEG_INF : COL_POS_INF; COL_NEG_INF : COL_POS_INF;
pack_key( pack_key(
&key, &left_key,
keynr, keynr,
key_buff, key_buff,
start_key->key, start_key->key,
start_key->length, start_key->length,
inf_byte inf_byte
);
error = kfile->key_range64(
kfile,
transaction,
&key,
&less,
&equal,
&greater,
&is_exact
); );
if (error) { pleft_key = &left_key;
ret_val = HA_TOKUDB_RANGE_COUNT;
goto cleanup;
}
start_rows= less;
total_rows_estimate = less + equal + greater;
}
else {
start_rows= 0;
} }
if (end_key) { if (end_key) {
inf_byte = (end_key->flag == HA_READ_BEFORE_KEY) ? inf_byte = (end_key->flag == HA_READ_BEFORE_KEY) ?
COL_NEG_INF : COL_POS_INF; COL_NEG_INF : COL_POS_INF;
pack_key( pack_key(
&key, &right_key,
keynr, keynr,
key_buff, key_buff2,
end_key->key, end_key->key,
end_key->length, end_key->length,
inf_byte inf_byte
); );
error = kfile->key_range64( pright_key = &right_key;
kfile,
transaction,
&key,
&less,
&equal,
&greater,
&is_exact
);
if (error) {
ret_val = HA_TOKUDB_RANGE_COUNT;
goto cleanup;
}
end_rows= less;
} }
else { error = kfile->keys_range64(
// kfile,
// first if-clause ensures that start_key is non-NULL transaction,
// pleft_key,
assert(start_key); pright_key,
end_rows = total_rows_estimate; &less,
&equal1,
&middle,
&equal2,
&greater,
&is_exact
);
if (error) {
ret_val = HA_TOKUDB_RANGE_COUNT;
goto cleanup;
} }
rows = middle;
rows = (end_rows > start_rows) ? end_rows - start_rows : 1;
// //
// MySQL thinks a return value of 0 means there are exactly 0 rows // MySQL thinks a return value of 0 means there are exactly 0 rows
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment