Commit 2a518937 authored by Rich Prohaska's avatar Rich Prohaska

#209 add variable to control table empty algorithm

parent 37fd531d
...@@ -1732,7 +1732,7 @@ int ha_tokudb::initialize_share( ...@@ -1732,7 +1732,7 @@ int ha_tokudb::initialize_share(
init_auto_increment(); init_auto_increment();
} }
if (THDVAR(thd, open_table_check_empty) && may_table_be_empty(txn)) { if (may_table_be_empty(txn)) {
share->try_table_lock = true; share->try_table_lock = true;
} }
else { else {
...@@ -3215,6 +3215,10 @@ bool ha_tokudb::may_table_be_empty(DB_TXN *txn) { ...@@ -3215,6 +3215,10 @@ bool ha_tokudb::may_table_be_empty(DB_TXN *txn) {
DBC* tmp_cursor = NULL; DBC* tmp_cursor = NULL;
DB_TXN* tmp_txn = NULL; DB_TXN* tmp_txn = NULL;
const int empty_scan = THDVAR(ha_thd(), empty_scan);
if (empty_scan == TOKUDB_EMPTY_SCAN_DISABLED)
goto cleanup;
if (txn == NULL) { if (txn == NULL) {
error = txn_begin(db_env, 0, &tmp_txn, 0, ha_thd()); error = txn_begin(db_env, 0, &tmp_txn, 0, ha_thd());
if (error) { if (error) {
...@@ -3224,21 +3228,23 @@ bool ha_tokudb::may_table_be_empty(DB_TXN *txn) { ...@@ -3224,21 +3228,23 @@ bool ha_tokudb::may_table_be_empty(DB_TXN *txn) {
} }
error = share->file->cursor(share->file, txn, &tmp_cursor, 0); error = share->file->cursor(share->file, txn, &tmp_cursor, 0);
if (error) { if (error)
goto cleanup; goto cleanup;
}
error = tmp_cursor->c_getf_next(tmp_cursor, 0, smart_dbt_do_nothing, NULL); if (empty_scan == TOKUDB_EMPTY_SCAN_LR)
if (error == DB_NOTFOUND) { error = tmp_cursor->c_getf_next(tmp_cursor, 0, smart_dbt_do_nothing, NULL);
else
error = tmp_cursor->c_getf_prev(tmp_cursor, 0, smart_dbt_do_nothing, NULL);
if (error == DB_NOTFOUND)
ret_val = true; ret_val = true;
} else
else {
ret_val = false; ret_val = false;
}
error = 0; error = 0;
cleanup: cleanup:
if (tmp_cursor) { if (tmp_cursor) {
int r = tmp_cursor->c_close(tmp_cursor); int r = tmp_cursor->c_close(tmp_cursor);
assert(r==0); assert(r == 0);
tmp_cursor = NULL; tmp_cursor = NULL;
} }
if (tmp_txn) { if (tmp_txn) {
......
...@@ -1390,7 +1390,7 @@ static struct st_mysql_sys_var *tokudb_system_variables[] = { ...@@ -1390,7 +1390,7 @@ static struct st_mysql_sys_var *tokudb_system_variables[] = {
MYSQL_SYSVAR(loader_memory_size), MYSQL_SYSVAR(loader_memory_size),
MYSQL_SYSVAR(hide_default_row_format), MYSQL_SYSVAR(hide_default_row_format),
MYSQL_SYSVAR(killed_time), MYSQL_SYSVAR(killed_time),
MYSQL_SYSVAR(open_table_check_empty), MYSQL_SYSVAR(empty_scan),
NULL NULL
}; };
......
...@@ -484,7 +484,31 @@ static int tokudb_killed_callback(void) { ...@@ -484,7 +484,31 @@ static int tokudb_killed_callback(void) {
return thd->killed; return thd->killed;
} }
static MYSQL_THDVAR_BOOL(open_table_check_empty, 0, "Check if table is empty at first open", NULL /*check*/, NULL /*update*/, true /*default*/); enum {
TOKUDB_EMPTY_SCAN_DISABLED = 0,
TOKUDB_EMPTY_SCAN_LR = 1,
TOKUDB_EMPTY_SCAN_RL = 2,
};
static const char *tokudb_empty_scan_names[] = {
"disabled",
"lr",
"rl",
NullS
};
static TYPELIB tokudb_empty_scan_typelib = {
array_elements(tokudb_empty_scan_names) - 1,
"tokudb_empty_scan_typelib",
tokudb_empty_scan_names,
NULL
};
static MYSQL_THDVAR_ENUM(empty_scan,
PLUGIN_VAR_OPCMDARG,
"TokuDB algorithm to check if the table is empty when opened. ",
NULL, NULL, TOKUDB_EMPTY_SCAN_RL, &tokudb_empty_scan_typelib
);
extern HASH tokudb_open_tables; extern HASH tokudb_open_tables;
extern pthread_mutex_t tokudb_mutex; extern pthread_mutex_t tokudb_mutex;
......
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