Commit 4ef48fbf authored by Sergei Golubchik's avatar Sergei Golubchik

cleanup: prepare_for_insert() -> prepare_for_modify()

make handler::prepare_for_insert() to be called to prepare
the handler for writes, INSERT/UPDATE/DELETE.
parent 19b0c089
...@@ -8084,21 +8084,31 @@ bool handler::prepare_for_row_logging() ...@@ -8084,21 +8084,31 @@ bool handler::prepare_for_row_logging()
/* /*
Do all initialization needed for insert Do all initialization needed for writes: INSERT/UPDATE/DELETE
can_set_fields is true if values of individual fields in a record
can be set. That is, INSERT/UPDATE, need uniqueness checks, for example.
can_lookup is true if the operation needs to look up rows in the table,
that is UPDATE/DELETE, and here we need a separate `lookup_handler`
to avoid disrupting the state of `this`
*/ */
int handler::prepare_for_insert(bool do_create) int handler::prepare_for_modify(bool can_set_fields, bool can_lookup)
{ {
if (table->open_hlindexes_for_write()) if (table->open_hlindexes_for_write())
return 1; return 1;
if (can_set_fields)
{
/* Preparation for unique of blob's */ /* Preparation for unique of blob's */
if (table->s->long_unique_table || table->s->period.unique_keys) if (table->s->long_unique_table || table->s->period.unique_keys)
{ {
if (do_create && create_lookup_handler()) if (can_lookup && create_lookup_handler())
return 1; return 1;
alloc_lookup_buffer(); alloc_lookup_buffer();
} }
}
return 0; return 0;
} }
...@@ -8106,8 +8116,8 @@ int handler::prepare_for_insert(bool do_create) ...@@ -8106,8 +8116,8 @@ int handler::prepare_for_insert(bool do_create)
int handler::ha_write_row(const uchar *buf) int handler::ha_write_row(const uchar *buf)
{ {
int error; int error;
DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE || DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE || m_lock_type == F_WRLCK);
m_lock_type == F_WRLCK); DBUG_ASSERT(buf == table->record[0]);
DBUG_ENTER("handler::ha_write_row"); DBUG_ENTER("handler::ha_write_row");
DEBUG_SYNC_C("ha_write_row_start"); DEBUG_SYNC_C("ha_write_row_start");
#ifdef WITH_WSREP #ifdef WITH_WSREP
...@@ -8128,7 +8138,7 @@ int handler::ha_write_row(const uchar *buf) ...@@ -8128,7 +8138,7 @@ int handler::ha_write_row(const uchar *buf)
DBUG_ASSERT(inited == NONE || lookup_handler != this); DBUG_ASSERT(inited == NONE || lookup_handler != this);
if ((error= check_duplicate_long_entries(buf))) if ((error= check_duplicate_long_entries(buf)))
{ {
if (table->next_number_field && buf == table->record[0]) if (table->next_number_field)
if (int err= update_auto_increment()) if (int err= update_auto_increment())
error= err; error= err;
DBUG_RETURN(error); DBUG_RETURN(error);
...@@ -8262,9 +8272,9 @@ int handler::ha_delete_row(const uchar *buf) ...@@ -8262,9 +8272,9 @@ int handler::ha_delete_row(const uchar *buf)
m_lock_type == F_WRLCK); m_lock_type == F_WRLCK);
/* /*
Normally table->record[0] is used, but sometimes table->record[1] is used. Normally table->record[0] is used, but sometimes table->record[1] is used.
(notably, for REPLACE and in sql_acl.cc)
*/ */
DBUG_ASSERT(buf == table->record[0] || DBUG_ASSERT(buf == table->record[0] || buf == table->record[1]);
buf == table->record[1]);
MYSQL_DELETE_ROW_START(table_share->db.str, table_share->table_name.str); MYSQL_DELETE_ROW_START(table_share->db.str, table_share->table_name.str);
mark_trx_read_write(); mark_trx_read_write();
......
...@@ -5161,9 +5161,8 @@ class handler :public Sql_alloc ...@@ -5161,9 +5161,8 @@ class handler :public Sql_alloc
virtual int delete_table(const char *name); virtual int delete_table(const char *name);
bool check_table_binlog_row_based(); bool check_table_binlog_row_based();
bool prepare_for_row_logging(); bool prepare_for_row_logging();
int prepare_for_insert(bool do_create); int prepare_for_modify(bool can_set_fields, bool can_lookup);
int binlog_log_row(const uchar *before_record, int binlog_log_row(const uchar *before_record, const uchar *after_record,
const uchar *after_record,
Log_func *log_func); Log_func *log_func);
inline void clear_cached_table_binlog_row_based_flag() inline void clear_cached_table_binlog_row_based_flag()
......
...@@ -5086,7 +5086,8 @@ int Rows_log_event::do_apply_event(rpl_group_info *rgi) ...@@ -5086,7 +5086,8 @@ int Rows_log_event::do_apply_event(rpl_group_info *rgi)
Rows_log_event::Db_restore_ctx restore_ctx(this); Rows_log_event::Db_restore_ctx restore_ctx(this);
master_had_triggers= table->master_had_triggers; master_had_triggers= table->master_had_triggers;
bool transactional_table= table->file->has_transactions_and_rollback(); bool transactional_table= table->file->has_transactions_and_rollback();
table->file->prepare_for_insert(get_general_type_code() != WRITE_ROWS_EVENT); table->file->prepare_for_modify(true,
get_general_type_code() != WRITE_ROWS_EVENT);
/* /*
table == NULL means that this table should not be replicated table == NULL means that this table should not be replicated
......
...@@ -448,6 +448,7 @@ bool Sql_cmd_delete::delete_from_single_table(THD *thd) ...@@ -448,6 +448,7 @@ bool Sql_cmd_delete::delete_from_single_table(THD *thd)
if (thd->lex->describe) if (thd->lex->describe)
goto produce_explain_and_leave; goto produce_explain_and_leave;
table->file->prepare_for_modify(false, false);
if (likely(!(error=table->file->ha_delete_all_rows()))) if (likely(!(error=table->file->ha_delete_all_rows())))
{ {
/* /*
...@@ -804,8 +805,8 @@ bool Sql_cmd_delete::delete_from_single_table(THD *thd) ...@@ -804,8 +805,8 @@ bool Sql_cmd_delete::delete_from_single_table(THD *thd)
&& !table->versioned() && !table->versioned()
&& table->file->has_transactions(); && table->file->has_transactions();
if (table->versioned(VERS_TIMESTAMP) || (table_list->has_period())) table->file->prepare_for_modify(table->versioned(VERS_TIMESTAMP) ||
table->file->prepare_for_insert(1); table_list->has_period(), true);
DBUG_ASSERT(table->file->inited != handler::NONE); DBUG_ASSERT(table->file->inited != handler::NONE);
THD_STAGE_INFO(thd, stage_updating); THD_STAGE_INFO(thd, stage_updating);
...@@ -1128,9 +1129,7 @@ multi_delete::initialize_tables(JOIN *join) ...@@ -1128,9 +1129,7 @@ multi_delete::initialize_tables(JOIN *join)
normal_tables= 1; normal_tables= 1;
tbl->prepare_triggers_for_delete_stmt_or_event(); tbl->prepare_triggers_for_delete_stmt_or_event();
tbl->prepare_for_position(); tbl->prepare_for_position();
tbl->file->prepare_for_modify(tbl->versioned(VERS_TIMESTAMP), true);
if (tbl->versioned(VERS_TIMESTAMP))
tbl->file->prepare_for_insert(1);
} }
else if ((tab->type != JT_SYSTEM && tab->type != JT_CONST) && else if ((tab->type != JT_SYSTEM && tab->type != JT_CONST) &&
walk == delete_tables) walk == delete_tables)
......
...@@ -956,7 +956,7 @@ bool mysql_insert(THD *thd, TABLE_LIST *table_list, ...@@ -956,7 +956,7 @@ bool mysql_insert(THD *thd, TABLE_LIST *table_list,
if (lock_type != TL_WRITE_DELAYED) if (lock_type != TL_WRITE_DELAYED)
#endif /* EMBEDDED_LIBRARY */ #endif /* EMBEDDED_LIBRARY */
{ {
bool create_lookup_handler= duplic != DUP_ERROR; bool create_lookup_handler= false;
if (duplic != DUP_ERROR || ignore) if (duplic != DUP_ERROR || ignore)
{ {
create_lookup_handler= true; create_lookup_handler= true;
...@@ -967,7 +967,7 @@ bool mysql_insert(THD *thd, TABLE_LIST *table_list, ...@@ -967,7 +967,7 @@ bool mysql_insert(THD *thd, TABLE_LIST *table_list,
goto abort; goto abort;
} }
} }
if (table->file->prepare_for_insert(create_lookup_handler)) if (table->file->prepare_for_modify(true, create_lookup_handler))
goto abort; goto abort;
/** /**
This is a simple check for the case when the table has a trigger This is a simple check for the case when the table has a trigger
...@@ -3686,7 +3686,7 @@ bool Delayed_insert::handle_inserts(void) ...@@ -3686,7 +3686,7 @@ bool Delayed_insert::handle_inserts(void)
handler_writes() will not have called decide_logging_format. handler_writes() will not have called decide_logging_format.
*/ */
table->file->prepare_for_row_logging(); table->file->prepare_for_row_logging();
table->file->prepare_for_insert(1); table->file->prepare_for_modify(true, true);
using_bin_log= table->file->row_logging; using_bin_log= table->file->row_logging;
/* /*
...@@ -4195,7 +4195,7 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u) ...@@ -4195,7 +4195,7 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
#endif #endif
thd->cuted_fields=0; thd->cuted_fields=0;
bool create_lookup_handler= info.handle_duplicates != DUP_ERROR; bool create_lookup_handler= false;
if (info.ignore || info.handle_duplicates != DUP_ERROR) if (info.ignore || info.handle_duplicates != DUP_ERROR)
{ {
create_lookup_handler= true; create_lookup_handler= true;
...@@ -4206,7 +4206,7 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u) ...@@ -4206,7 +4206,7 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
DBUG_RETURN(1); DBUG_RETURN(1);
} }
} }
table->file->prepare_for_insert(create_lookup_handler); table->file->prepare_for_modify(true, create_lookup_handler);
if (info.handle_duplicates == DUP_REPLACE && if (info.handle_duplicates == DUP_REPLACE &&
(!table->triggers || !table->triggers->has_delete_triggers())) (!table->triggers || !table->triggers->has_delete_triggers()))
table->file->extra(HA_EXTRA_WRITE_CAN_REPLACE); table->file->extra(HA_EXTRA_WRITE_CAN_REPLACE);
...@@ -4984,7 +4984,7 @@ select_create::prepare(List<Item> &_values, SELECT_LEX_UNIT *u) ...@@ -4984,7 +4984,7 @@ select_create::prepare(List<Item> &_values, SELECT_LEX_UNIT *u)
restore_record(table,s->default_values); // Get empty record restore_record(table,s->default_values); // Get empty record
thd->cuted_fields=0; thd->cuted_fields=0;
bool create_lookup_handler= info.handle_duplicates != DUP_ERROR; bool create_lookup_handler= false;
if (info.ignore || info.handle_duplicates != DUP_ERROR) if (info.ignore || info.handle_duplicates != DUP_ERROR)
{ {
create_lookup_handler= true; create_lookup_handler= true;
...@@ -4995,7 +4995,7 @@ select_create::prepare(List<Item> &_values, SELECT_LEX_UNIT *u) ...@@ -4995,7 +4995,7 @@ select_create::prepare(List<Item> &_values, SELECT_LEX_UNIT *u)
DBUG_RETURN(1); DBUG_RETURN(1);
} }
} }
table->file->prepare_for_insert(create_lookup_handler); table->file->prepare_for_modify(true, create_lookup_handler);
if (info.handle_duplicates == DUP_REPLACE && if (info.handle_duplicates == DUP_REPLACE &&
(!table->triggers || !table->triggers->has_delete_triggers())) (!table->triggers || !table->triggers->has_delete_triggers()))
table->file->extra(HA_EXTRA_WRITE_CAN_REPLACE); table->file->extra(HA_EXTRA_WRITE_CAN_REPLACE);
......
...@@ -685,14 +685,14 @@ int mysql_load(THD *thd, const sql_exchange *ex, TABLE_LIST *table_list, ...@@ -685,14 +685,14 @@ int mysql_load(THD *thd, const sql_exchange *ex, TABLE_LIST *table_list,
thd->abort_on_warning= !ignore && thd->is_strict_mode(); thd->abort_on_warning= !ignore && thd->is_strict_mode();
thd->get_stmt_da()->reset_current_row_for_warning(1); thd->get_stmt_da()->reset_current_row_for_warning(1);
bool create_lookup_handler= handle_duplicates != DUP_ERROR; bool create_lookup_handler= false;
if ((table_list->table->file->ha_table_flags() & HA_DUPLICATE_POS)) if ((table_list->table->file->ha_table_flags() & HA_DUPLICATE_POS))
{ {
create_lookup_handler= true; create_lookup_handler= true;
if ((error= table_list->table->file->ha_rnd_init_with_error(0))) if ((error= table_list->table->file->ha_rnd_init_with_error(0)))
goto err; goto err;
} }
table->file->prepare_for_insert(create_lookup_handler); table->file->prepare_for_modify(true, create_lookup_handler);
thd_progress_init(thd, 2); thd_progress_init(thd, 2);
fix_rownum_pointers(thd, thd->lex->current_select, &info.copied); fix_rownum_pointers(thd, thd->lex->current_select, &info.copied);
if (table_list->table->validate_default_values_of_unset_fields(thd)) if (table_list->table->validate_default_values_of_unset_fields(thd))
......
...@@ -12246,7 +12246,7 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to, ...@@ -12246,7 +12246,7 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
from->file->column_bitmaps_signal(); from->file->column_bitmaps_signal();
to->file->prepare_for_insert(0); to->file->prepare_for_modify(true, false);
DBUG_ASSERT(to->file->inited == handler::NONE); DBUG_ASSERT(to->file->inited == handler::NONE);
/* Tell handler that we have values for all columns in the to table */ /* Tell handler that we have values for all columns in the to table */
......
...@@ -913,7 +913,7 @@ bool Sql_cmd_update::update_single_table(THD *thd) ...@@ -913,7 +913,7 @@ bool Sql_cmd_update::update_single_table(THD *thd)
can_compare_record= records_are_comparable(table); can_compare_record= records_are_comparable(table);
explain->tracker.on_scan_init(); explain->tracker.on_scan_init();
table->file->prepare_for_insert(1); table->file->prepare_for_modify(true, true);
DBUG_ASSERT(table->file->inited != handler::NONE); DBUG_ASSERT(table->file->inited != handler::NONE);
THD_STAGE_INFO(thd, stage_updating); THD_STAGE_INFO(thd, stage_updating);
...@@ -1843,7 +1843,7 @@ int multi_update::prepare(List<Item> &not_used_values, ...@@ -1843,7 +1843,7 @@ int multi_update::prepare(List<Item> &not_used_values,
table->read_set= &table->def_read_set; table->read_set= &table->def_read_set;
bitmap_union(table->read_set, &table->tmp_set); bitmap_union(table->read_set, &table->tmp_set);
if (!(thd->lex->context_analysis_only & CONTEXT_ANALYSIS_ONLY_PREPARE)) if (!(thd->lex->context_analysis_only & CONTEXT_ANALYSIS_ONLY_PREPARE))
table->file->prepare_for_insert(1); table->file->prepare_for_modify(true, true);
} }
} }
if (unlikely(error)) if (unlikely(error))
......
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