Skip to content

Commit

Permalink
Delete: code duplication fix
Browse files Browse the repository at this point in the history
  • Loading branch information
midenok committed May 5, 2017
1 parent 8f5f4c2 commit 8936abc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 27 deletions.
47 changes: 20 additions & 27 deletions sql/sql_delete.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,22 @@ void Update_plan::save_explain_data_intern(MEM_ROOT *mem_root,
}


inline
int TABLE::delete_row()
{
int error;
if (!versioned())
error= file->ha_delete_row(record[0]);
else
{
store_record(this, record[1]);
vers_end_field()->set_time();
error= file->ha_update_row(record[1], record[0]);
}
return error;
}


/**
Implement DELETE SQL word.
Expand Down Expand Up @@ -587,15 +603,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
break;
}

if (!table->versioned())
error= table->file->ha_delete_row(table->record[0]);
else
{
store_record(table,record[1]);
table->vers_end_field()->set_time();
error= table->file->ha_update_row(table->record[1],
table->record[0]);
}
error= table->delete_row();
if (!error)
{
deleted++;
Expand Down Expand Up @@ -1086,15 +1094,8 @@ int multi_delete::send_data(List<Item> &values)
TRG_ACTION_BEFORE, FALSE))
DBUG_RETURN(1);
table->status|= STATUS_DELETED;
if (!table->versioned())
error= table->file->ha_delete_row(table->record[0]);
else
{
store_record(table,record[1]);
table->vers_end_field()->set_time();
error= table->file->ha_update_row(table->record[1],
table->record[0]);
}

error= table->delete_row();
if (!error)
{
deleted++;
Expand Down Expand Up @@ -1275,15 +1276,7 @@ int multi_delete::do_table_deletes(TABLE *table, SORT_INFO *sort_info,
break;
}

if (!table->versioned())
local_error= table->file->ha_delete_row(table->record[0]);
else
{
store_record(table,record[1]);
table->vers_end_field()->set_time();
local_error= table->file->ha_update_row(table->record[1],
table->record[0]);
}
local_error= table->delete_row();
if (local_error && !ignore)
{
table->file->print_error(local_error, MYF(0));
Expand Down
2 changes: 2 additions & 0 deletions sql/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,8 @@ struct TABLE
return field[s->row_end_field];
}

int delete_row();

/** Number of additional fields used in versioned tables */
#define VERSIONING_FIELDS 2

Expand Down

0 comments on commit 8936abc

Please sign in to comment.