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: ...@@ -1870,18 +1870,13 @@ exit:
// error otherwise // error otherwise
// //
int ha_tokudb::estimate_num_rows(DB* db, u_int64_t* num_rows, DB_TXN* txn) { int ha_tokudb::estimate_num_rows(DB* db, u_int64_t* num_rows, DB_TXN* txn) {
DBT key;
DBT data;
int error = ENOSYS; int error = ENOSYS;
DBC* crsr = NULL; DBC* crsr = NULL;
u_int64_t less, equal, greater;
int is_exact; int is_exact;
bool do_commit = false; bool do_commit = false;
DB_BTREE_STAT64 dict_stats;
DB_TXN* txn_to_use = NULL; DB_TXN* txn_to_use = NULL;
bzero((void *)&key, sizeof(key));
bzero((void *)&data, sizeof(data));
if (txn == NULL) { if (txn == NULL) {
error = db_env->txn_begin(db_env, 0, &txn_to_use, DB_READ_UNCOMMITTED); error = db_env->txn_begin(db_env, 0, &txn_to_use, DB_READ_UNCOMMITTED);
if (error) goto cleanup; if (error) goto cleanup;
...@@ -1891,36 +1886,14 @@ int ha_tokudb::estimate_num_rows(DB* db, u_int64_t* num_rows, DB_TXN* txn) { ...@@ -1891,36 +1886,14 @@ int ha_tokudb::estimate_num_rows(DB* db, u_int64_t* num_rows, DB_TXN* txn) {
txn_to_use = txn; txn_to_use = txn;
} }
error = db->cursor(db, txn_to_use, &crsr, 0); error = db->stat64(
if (error) { goto cleanup; } share->file,
//
// 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,
txn_to_use, txn_to_use,
&key, &dict_stats
&less,
&equal,
&greater,
&is_exact
); );
if (error) { if (error) { goto cleanup; }
goto cleanup;
}
*num_rows = equal + greater; *num_rows = dict_stats.bt_ndata;
error = 0; error = 0;
cleanup: cleanup:
if (crsr != NULL) { 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