Commit 92c25af2 authored by Zardosht Kasheff's avatar Zardosht Kasheff Committed by Yoni Fogel

[t:2359], make replace into with no secondary indexes not create a child transaction

git-svn-id: file:///svn/mysql/tokudb-engine/tokudb-engine@17717 c7de825b-a66e-492c-adef-691d508d4ae1
parent ee6ed2a0
...@@ -3008,7 +3008,7 @@ cleanup: ...@@ -3008,7 +3008,7 @@ cleanup:
return error; return error;
} }
int ha_tokudb::insert_rows_to_dictionaries(uchar* record, DBT* pk_key, DBT* pk_val, DB_TXN* txn) { int ha_tokudb::insert_row_to_main_dictionary(uchar* record, DBT* pk_key, DBT* pk_val, DB_TXN* txn) {
int error; int error;
DBT row, key; DBT row, key;
u_int32_t put_flags; u_int32_t put_flags;
...@@ -3017,16 +3017,12 @@ int ha_tokudb::insert_rows_to_dictionaries(uchar* record, DBT* pk_key, DBT* pk_v ...@@ -3017,16 +3017,12 @@ int ha_tokudb::insert_rows_to_dictionaries(uchar* record, DBT* pk_key, DBT* pk_v
uint curr_num_DBs = table->s->keys + test(hidden_primary_key); uint curr_num_DBs = table->s->keys + test(hidden_primary_key);
ulonglong wait_lock_time = get_write_lock_wait_time(thd); ulonglong wait_lock_time = get_write_lock_wait_time(thd);
assert(curr_num_DBs == 1);
is_replace_into = (thd_sql_command(thd) == SQLCOM_REPLACE) || is_replace_into = (thd_sql_command(thd) == SQLCOM_REPLACE) ||
(thd_sql_command(thd) == SQLCOM_REPLACE_SELECT); (thd_sql_command(thd) == SQLCOM_REPLACE_SELECT);
//
// first the primary key (because it must be unique, has highest chance of failure)
//
put_flags = hidden_primary_key ? DB_YESOVERWRITE : DB_NOOVERWRITE; put_flags = hidden_primary_key ? DB_YESOVERWRITE : DB_NOOVERWRITE;
if (thd_test_options(thd, OPTION_RELAXED_UNIQUE_CHECKS) && !is_replace_into) {
put_flags = DB_YESOVERWRITE;
}
// //
// optimization for "REPLACE INTO..." command // optimization for "REPLACE INTO..." command
// if the command is "REPLACE INTO" and the only table // if the command is "REPLACE INTO" and the only table
...@@ -3037,10 +3033,9 @@ int ha_tokudb::insert_rows_to_dictionaries(uchar* record, DBT* pk_key, DBT* pk_v ...@@ -3037,10 +3033,9 @@ int ha_tokudb::insert_rows_to_dictionaries(uchar* record, DBT* pk_key, DBT* pk_v
// to do. We cannot do this if curr_num_DBs > 1, because then we lose // to do. We cannot do this if curr_num_DBs > 1, because then we lose
// consistency between indexes // consistency between indexes
// //
if (is_replace_into && (curr_num_DBs == 1)) { if (thd_test_options(thd, OPTION_RELAXED_UNIQUE_CHECKS) || is_replace_into) {
put_flags = DB_YESOVERWRITE; // original put_flags can only be DB_YESOVERWRITE or DB_NOOVERWRITE put_flags = DB_YESOVERWRITE; // original put_flags can only be DB_YESOVERWRITE or DB_NOOVERWRITE
} }
lockretryN(wait_lock_time){ lockretryN(wait_lock_time){
error = share->file->put( error = share->file->put(
...@@ -3058,48 +3053,6 @@ int ha_tokudb::insert_rows_to_dictionaries(uchar* record, DBT* pk_key, DBT* pk_v ...@@ -3058,48 +3053,6 @@ int ha_tokudb::insert_rows_to_dictionaries(uchar* record, DBT* pk_key, DBT* pk_v
goto cleanup; goto cleanup;
} }
//
// now insertion for rest of indexes
//
for (uint keynr = 0; keynr < table_share->keys; keynr++) {
bool has_null;
if (keynr == primary_key) {
continue;
}
create_dbt_key_from_table(&key, keynr, mult_key_buff[keynr], record, &has_null);
put_flags = DB_YESOVERWRITE;
if (table->key_info[keynr].flags & HA_CLUSTERING) {
error = pack_row(&row, (const uchar *) record, keynr);
if (error) { goto cleanup; }
}
else {
bzero((void *) &row, sizeof(row));
}
lockretryN(wait_lock_time){
error = share->key_file[keynr]->put(
share->key_file[keynr],
txn,
&key,
&row,
put_flags
);
lockretry_wait;
}
//
// We break if we hit an error, unless it is a dup key error
// and MySQL told us to ignore duplicate key errors
//
if (error) {
last_dup_key = keynr;
goto cleanup;
}
}
cleanup: cleanup:
return error; return error;
} }
...@@ -3164,6 +3117,9 @@ int ha_tokudb::write_row(uchar * record) { ...@@ -3164,6 +3117,9 @@ int ha_tokudb::write_row(uchar * record) {
DB_TXN* txn = NULL; DB_TXN* txn = NULL;
tokudb_trx_data *trx = NULL; tokudb_trx_data *trx = NULL;
uint curr_num_DBs = table->s->keys + test(hidden_primary_key); uint curr_num_DBs = table->s->keys + test(hidden_primary_key);
bool create_sub_trans = false;
bool is_replace_into = (thd_sql_command(thd) == SQLCOM_REPLACE) ||
(thd_sql_command(thd) == SQLCOM_REPLACE_SELECT);
// //
// some crap that needs to be done because MySQL does not properly abstract // some crap that needs to be done because MySQL does not properly abstract
...@@ -3219,14 +3175,15 @@ int ha_tokudb::write_row(uchar * record) { ...@@ -3219,14 +3175,15 @@ int ha_tokudb::write_row(uchar * record) {
goto cleanup; goto cleanup;
} }
if (using_ignore) { create_sub_trans = (using_ignore && !(is_replace_into && curr_num_DBs == 1));
if (create_sub_trans) {
error = db_env->txn_begin(db_env, transaction, &sub_trans, DB_INHERIT_ISOLATION); error = db_env->txn_begin(db_env, transaction, &sub_trans, DB_INHERIT_ISOLATION);
if (error) { if (error) {
goto cleanup; goto cleanup;
} }
} }
txn = using_ignore ? sub_trans : transaction; txn = create_sub_trans ? sub_trans : transaction;
// //
// make sure the buffers for the rows are big enough // make sure the buffers for the rows are big enough
...@@ -3242,7 +3199,7 @@ int ha_tokudb::write_row(uchar * record) { ...@@ -3242,7 +3199,7 @@ int ha_tokudb::write_row(uchar * record) {
} }
if (curr_num_DBs == 1) { if (curr_num_DBs == 1) {
error = insert_rows_to_dictionaries(record,&prim_key, &row, txn); error = insert_row_to_main_dictionary(record,&prim_key, &row, txn);
if (error) { goto cleanup; } if (error) { goto cleanup; }
} }
else { else {
......
...@@ -298,7 +298,7 @@ private: ...@@ -298,7 +298,7 @@ private:
void trace_create_table_info(const char *name, TABLE * form); void trace_create_table_info(const char *name, TABLE * form);
int is_val_unique(bool* is_unique, uchar* record, KEY* key_info, uint dict_index, DB_TXN* txn); int is_val_unique(bool* is_unique, uchar* record, KEY* key_info, uint dict_index, DB_TXN* txn);
int do_uniqueness_checks(uchar* record, DB_TXN* txn, THD* thd); int do_uniqueness_checks(uchar* record, DB_TXN* txn, THD* thd);
int insert_rows_to_dictionaries(uchar* record, DBT* pk_key, DBT* pk_val, DB_TXN* txn); int insert_row_to_main_dictionary(uchar* record, DBT* pk_key, DBT* pk_val, DB_TXN* txn);
int insert_rows_to_dictionaries_mult(DBT* pk_key, DBT* pk_val, DB_TXN* txn, THD* thd); int insert_rows_to_dictionaries_mult(DBT* pk_key, DBT* pk_val, DB_TXN* txn, THD* thd);
int test_row_packing(uchar* record, DBT* pk_key, DBT* pk_val); int test_row_packing(uchar* record, DBT* pk_key, DBT* pk_val);
......
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