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

addresses #1068

for function optimize tables, does a full table scan on each key to flatten DB

git-svn-id: file:///svn/mysql/tokudb-engine/src@5611 c7de825b-a66e-492c-adef-691d508d4ae1
parent f9850e0f
...@@ -973,6 +973,17 @@ static void smart_dbt_ai_callback (DBT const *key, DBT const *row, void *contex ...@@ -973,6 +973,17 @@ static void smart_dbt_ai_callback (DBT const *key, DBT const *row, void *contex
memcpy(info->prim_key->data, key->data, key->size); memcpy(info->prim_key->data, key->data, key->size);
} }
//
// smart DBT callback function for optimize
// in optimize, we want to flatten DB by doing
// a full table scan. Therefore, we don't
// want to actually do anything with the data, hence
// callback does nothing
//
static void smart_dbt_opt_callback (DBT const *key, DBT const *row, void *context) {
}
// //
// Smart DBT callback function in case where we have a covering index // Smart DBT callback function in case where we have a covering index
// //
...@@ -4441,19 +4452,52 @@ int ha_tokudb::analyze(THD * thd, HA_CHECK_OPT * check_opt) { ...@@ -4441,19 +4452,52 @@ int ha_tokudb::analyze(THD * thd, HA_CHECK_OPT * check_opt) {
} }
#endif #endif
#if 0 // QQQ use default //
// flatten all DB's in this table, to do so, just do a full scan on every DB
//
int ha_tokudb::optimize(THD * thd, HA_CHECK_OPT * check_opt) { int ha_tokudb::optimize(THD * thd, HA_CHECK_OPT * check_opt) {
return ha_tokudb::analyze(thd, check_opt); int error;
} DB_TXN* txn = NULL;
#endif DBC* tmp_cursor = NULL;
uint curr_num_DBs = table->s->keys + test(hidden_primary_key);
error = db_env->txn_begin(db_env, 0, &txn, 0);
if (error) {
goto cleanup;
}
#if 0 // QQQ use default //
int ha_tokudb::check(THD * thd, HA_CHECK_OPT * check_opt) { // prelock so each scan goes faster
TOKUDB_DBUG_ENTER("ha_tokudb::check"); //
TOKUDB_DBUG_RETURN(HA_ADMIN_NOT_IMPLEMENTED); error = acquire_table_lock(txn,lock_read);
// look in old_ha_tokudb.cc for a start of an implementation if (error) {
goto cleanup;
}
//
// for each DB, scan through entire table and do nothing
//
for (uint i = 0; i < curr_num_DBs; i++) {
error = 0;
if ((error = share->file->cursor(share->file, txn, &tmp_cursor, 0))) {
tmp_cursor = NULL;
goto cleanup;
}
while (error != DB_NOTFOUND) {
error = tmp_cursor->c_getf_next(tmp_cursor, DB_PRELOCKED, smart_dbt_opt_callback, NULL);
if (error && error != DB_NOTFOUND) {
goto cleanup;
}
}
tmp_cursor->c_close(tmp_cursor);
}
error = 0;
cleanup:
if (txn) {
txn->commit(txn, 0);
}
return error;
} }
#endif
ulong ha_tokudb::field_offset(Field *field) { ulong ha_tokudb::field_offset(Field *field) {
if (table->record[0] <= field->ptr && field->ptr < table->record[1]) if (table->record[0] <= field->ptr && field->ptr < table->record[1])
......
...@@ -233,10 +233,9 @@ public: ...@@ -233,10 +233,9 @@ public:
int create(const char *name, TABLE * form, HA_CREATE_INFO * create_info); int create(const char *name, TABLE * form, HA_CREATE_INFO * create_info);
int delete_table(const char *name); int delete_table(const char *name);
int rename_table(const char *from, const char *to); int rename_table(const char *from, const char *to);
int optimize(THD * thd, HA_CHECK_OPT * check_opt);
#if 0 #if 0
int analyze(THD * thd, HA_CHECK_OPT * check_opt); int analyze(THD * thd, HA_CHECK_OPT * check_opt);
int optimize(THD * thd, HA_CHECK_OPT * check_opt);
int check(THD * thd, HA_CHECK_OPT * check_opt);
#endif #endif
int write_row(uchar * buf); int write_row(uchar * buf);
int update_row(const uchar * old_data, uchar * new_data); int update_row(const uchar * old_data, uchar * new_data);
......
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