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

[t:2433], re-estimate number of rows when doing show table status

git-svn-id: file:///svn/mysql/tokudb-engine/tokudb-engine@18225 c7de825b-a66e-492c-adef-691d508d4ae1
parent 53c53ef8
...@@ -1539,7 +1539,7 @@ int ha_tokudb::initialize_share( ...@@ -1539,7 +1539,7 @@ int ha_tokudb::initialize_share(
goto exit; goto exit;
} }
error = estimate_num_rows(share->file,&num_rows); error = estimate_num_rows(share->file,&num_rows, NULL);
// //
// estimate_num_rows should not fail under normal conditions // estimate_num_rows should not fail under normal conditions
// //
...@@ -1713,7 +1713,7 @@ exit: ...@@ -1713,7 +1713,7 @@ exit:
// 0 on success // 0 on success
// error otherwise // error otherwise
// //
int ha_tokudb::estimate_num_rows(DB* db, u_int64_t* num_rows) { int ha_tokudb::estimate_num_rows(DB* db, u_int64_t* num_rows, DB_TXN* txn) {
DBT key; DBT key;
DBT data; DBT data;
int error = ENOSYS; int error = ENOSYS;
...@@ -1721,17 +1721,21 @@ int ha_tokudb::estimate_num_rows(DB* db, u_int64_t* num_rows) { ...@@ -1721,17 +1721,21 @@ int ha_tokudb::estimate_num_rows(DB* db, u_int64_t* num_rows) {
u_int64_t less, equal, greater; u_int64_t less, equal, greater;
int is_exact; int is_exact;
bool do_commit = false; bool do_commit = false;
DB_TXN* txn_to_use = NULL;
bzero((void *)&key, sizeof(key)); bzero((void *)&key, sizeof(key));
bzero((void *)&data, sizeof(data)); bzero((void *)&data, sizeof(data));
if (transaction == NULL) { if (txn == NULL) {
error = db_env->txn_begin(db_env, 0, &transaction, 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;
do_commit = true; do_commit = true;
} }
else {
txn_to_use = txn;
}
error = db->cursor(db, transaction, &crsr, 0); error = db->cursor(db, txn_to_use, &crsr, 0);
if (error) { goto cleanup; } if (error) { goto cleanup; }
// //
...@@ -1748,7 +1752,7 @@ int ha_tokudb::estimate_num_rows(DB* db, u_int64_t* num_rows) { ...@@ -1748,7 +1752,7 @@ int ha_tokudb::estimate_num_rows(DB* db, u_int64_t* num_rows) {
error = db->key_range64( error = db->key_range64(
db, db,
transaction, txn_to_use,
&key, &key,
&less, &less,
&equal, &equal,
...@@ -1769,8 +1773,8 @@ cleanup: ...@@ -1769,8 +1773,8 @@ cleanup:
crsr = NULL; crsr = NULL;
} }
if (do_commit) { if (do_commit) {
commit_txn(transaction, 0); commit_txn(txn_to_use, 0);
transaction = NULL; txn_to_use = NULL;
} }
return error; return error;
} }
...@@ -4703,9 +4707,19 @@ int ha_tokudb::info(uint flag) { ...@@ -4703,9 +4707,19 @@ int ha_tokudb::info(uint flag) {
stats.records = share->rows + share->rows_from_locked_table; stats.records = share->rows + share->rows_from_locked_table;
stats.deleted = 0; stats.deleted = 0;
if (!(flag & HA_STATUS_NO_LOCK)) { if (!(flag & HA_STATUS_NO_LOCK)) {
u_int64_t num_rows = 0;
error = db_env->txn_begin(db_env, NULL, &txn, DB_READ_UNCOMMITTED); error = db_env->txn_begin(db_env, NULL, &txn, DB_READ_UNCOMMITTED);
if (error) { goto cleanup; } if (error) { goto cleanup; }
error = estimate_num_rows(share->file,&num_rows, txn);
if (error == 0) {
share->rows = num_rows;
stats.records = num_rows;
}
else {
goto cleanup;
}
error = share->file->stat64( error = share->file->stat64(
share->file, share->file,
txn, txn,
......
...@@ -273,7 +273,7 @@ private: ...@@ -273,7 +273,7 @@ private:
int open_secondary_dictionary(DB** ptr, KEY* key_info, const char* name, bool is_read_only, DB_TXN* txn); int open_secondary_dictionary(DB** ptr, KEY* key_info, const char* name, bool is_read_only, DB_TXN* txn);
int open_status_dictionary(DB** ptr, const char* name, DB_TXN* txn); int open_status_dictionary(DB** ptr, const char* name, DB_TXN* txn);
int acquire_table_lock (DB_TXN* trans, TABLE_LOCK_TYPE lt); int acquire_table_lock (DB_TXN* trans, TABLE_LOCK_TYPE lt);
int estimate_num_rows(DB* db, u_int64_t* num_rows); int estimate_num_rows(DB* db, u_int64_t* num_rows, DB_TXN* txn);
bool has_auto_increment_flag(uint* index); bool has_auto_increment_flag(uint* index);
int write_to_status(DB* db, HA_METADATA_KEY curr_key_data, void* data, uint size, DB_TXN* txn ); int write_to_status(DB* db, HA_METADATA_KEY curr_key_data, void* data, uint size, DB_TXN* txn );
int write_metadata(DB* db, void* key, uint key_size, void* data, uint data_size, DB_TXN* txn ); int write_metadata(DB* db, void* key, uint key_size, void* data, uint data_size, DB_TXN* txn );
......
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