Commit fcc43162 authored by Zardosht Kasheff's avatar Zardosht Kasheff Committed by Yoni Fogel

addresses #822


git-svn-id: file:///svn/mysql/tokudb-engine/src@3939 c7de825b-a66e-492c-adef-691d508d4ae1
parent b03051c5
...@@ -3048,69 +3048,72 @@ ha_rows ha_tokudb::records_in_range(uint keynr, key_range* start_key, key_range* ...@@ -3048,69 +3048,72 @@ ha_rows ha_tokudb::records_in_range(uint keynr, key_range* start_key, key_range*
#if 0 // QQQ need key_range #if 0 // QQQ need key_range
DBT key; DBT key;
ha_rows ret_val = HA_TOKUDB_RANGE_COUNT; ha_rows ret_val = HA_TOKUDB_RANGE_COUNT;
DB_KEY_RANGE start_range, end_range;
DB *kfile = key_file[keynr]; DB *kfile = key_file[keynr];
double start_frac, end_frac, rows; u_int64_t less, equal, greater;
u_int64_t start_rows, end_rows, rows;
int is_exact;
int error; int error;
KEY *key_info = &table->key_info[keynr];
// //
// get start_frac and end_frac values so that we can estimate range // get start_rows and end_rows values so that we can estimate range
// //
if (start_key) { if (start_key) {
error = kfile->key_range( error = kfile->key_range64(
kfile, kfile,
transaction, transaction,
pack_key(&key, keynr, key_buff, start_key->key, start_key->length), pack_key(&key, keynr, key_buff, start_key->key, start_key->length),
&start_range, &less,
0 &equal,
&greater,
&is_exact
); );
if (error) { if (error) {
ret_val = HA_TOKUDB_RANGE_COUNT; ret_val = HA_TOKUDB_RANGE_COUNT;
goto cleanup; goto cleanup;
} }
if (start_key->flag == HA_READ_KEY_EXACT) { if (start_key->flag == HA_READ_KEY_EXACT) {
start_frac = start_range.less; start_rows= less;
} }
else { else {
start_frac = start_range.less + start_range.equal; start_rows = less + equal;
} }
} }
else { else {
start_frac = 0.0 start_rows= 0;
} }
if (end_key) { if (end_key) {
error = kfile->key_range( error = kfile->key_range64(
kfile, kfile,
transaction, transaction,
pack_key(&key, keynr, key_buff, end_key->key, end_key->length), pack_key(&key, keynr, key_buff, end_key->key, end_key->length),
&end_range, &less,
0 &equal,
&greater,
&is_exact
); );
if (error) { if (error) {
ret_val = HA_TOKUDB_RANGE_COUNT; ret_val = HA_TOKUDB_RANGE_COUNT;
goto cleanup; goto cleanup;
} }
if (end_key->flag == HA_READ_BEFORE_KEY) { if (end_key->flag == HA_READ_BEFORE_KEY) {
end_frac = end_range.less; end_rows= less;
} }
else { else {
end_frac = end_range.less + end_range.equal; end_rows= less + equal;
} }
} }
else { else {
end_frac = 1.0; end_rows = stats.records;
} }
rows = end_rows - start_rows;
// //
// end_frac and start_frac give fractions of values over stats.records // MySQL thinks a return value of 0 means there are exactly 0 rows
// to return estimate multiply by stats.records // Therefore, always return non-zero so this assumption is not made
// //
rows = (end_frac - start_frac) * stats.records; ret_val = (ha_rows) (rows <= 1 ? 1 : rows);
DBUG_PRINT("exit", ("rows: %g", rows));
ret_val = (ha_rows) (rows <= 1.0 ? 1 : rows);
cleanup: cleanup:
TOKUDB_DBUG_RETURN(ret_val); TOKUDB_DBUG_RETURN(ret_val);
#else #else
......
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