Commit 3cf373fa authored by Zardosht Kasheff's avatar Zardosht Kasheff Committed by Yoni Fogel

[t:3495], simplify estimate_num_rows

git-svn-id: file:///svn/mysql/tokudb-engine/tokudb-engine@32762 c7de825b-a66e-492c-adef-691d508d4ae1
parent c91d521f
......@@ -1870,18 +1870,13 @@ exit:
// error otherwise
//
int ha_tokudb::estimate_num_rows(DB* db, u_int64_t* num_rows, DB_TXN* txn) {
DBT key;
DBT data;
int error = ENOSYS;
DBC* crsr = NULL;
u_int64_t less, equal, greater;
int is_exact;
bool do_commit = false;
DB_BTREE_STAT64 dict_stats;
DB_TXN* txn_to_use = NULL;
bzero((void *)&key, sizeof(key));
bzero((void *)&data, sizeof(data));
if (txn == NULL) {
error = db_env->txn_begin(db_env, 0, &txn_to_use, DB_READ_UNCOMMITTED);
if (error) goto cleanup;
......@@ -1890,37 +1885,15 @@ int ha_tokudb::estimate_num_rows(DB* db, u_int64_t* num_rows, DB_TXN* txn) {
else {
txn_to_use = txn;
}
error = db->cursor(db, txn_to_use, &crsr, 0);
if (error) { goto cleanup; }
//
// get the first element, then estimate number of records
// by calling key_range64 on the first element
//
error = crsr->c_get(crsr, &key, &data, DB_FIRST);
if (error == DB_NOTFOUND) {
*num_rows = 0;
error = 0;
goto cleanup;
}
else if (error) { goto cleanup; }
error = db->key_range64(
db,
error = db->stat64(
share->file,
txn_to_use,
&key,
&less,
&equal,
&greater,
&is_exact
&dict_stats
);
if (error) {
goto cleanup;
}
if (error) { goto cleanup; }
*num_rows = equal + greater;
*num_rows = dict_stats.bt_ndata;
error = 0;
cleanup:
if (crsr != NULL) {
......
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