diff options
Diffstat (limited to 'sql/sql_delete.cc')
-rw-r--r-- | sql/sql_delete.cc | 91 |
1 files changed, 49 insertions, 42 deletions
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 0a12d01596b..52796f03440 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -401,7 +401,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, } const_cond_result= const_cond && (!conds || conds->val_int()); - if (thd->is_error()) + if (unlikely(thd->is_error())) { /* Error evaluating val_int(). */ DBUG_RETURN(TRUE); @@ -439,7 +439,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, if (thd->lex->describe) goto produce_explain_and_leave; - if (!(error=table->file->ha_delete_all_rows())) + if (likely(!(error=table->file->ha_delete_all_rows()))) { /* If delete_all_rows() is used, it is not possible to log the @@ -495,7 +495,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, table->quick_keys.clear_all(); // Can't use 'only index' select=make_select(table, 0, 0, conds, (SORT_INFO*) 0, 0, &error); - if (error) + if (unlikely(error)) DBUG_RETURN(TRUE); if ((select && select->check_quick(thd, safe_update, limit)) || !limit) { @@ -511,7 +511,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, Currently they rely on the user checking DA for errors when unwinding the stack after calling Item::val_xxx(). */ - if (thd->is_error()) + if (unlikely(thd->is_error())) DBUG_RETURN(TRUE); my_ok(thd, 0); DBUG_RETURN(0); // Nothing to delete @@ -662,10 +662,10 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, else error= init_read_record_idx(&info, thd, table, 1, query_plan.index, reverse); - if (error) + if (unlikely(error)) goto got_error; - if (init_ftfuncs(thd, select_lex, 1)) + if (unlikely(init_ftfuncs(thd, select_lex, 1))) goto got_error; table->mark_columns_needed_for_delete(); @@ -676,9 +676,9 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, if (with_select) { - if (result->send_result_set_metadata(select_lex->item_list, - Protocol::SEND_NUM_ROWS | - Protocol::SEND_EOF)) + if (unlikely(result->send_result_set_metadata(select_lex->item_list, + Protocol::SEND_NUM_ROWS | + Protocol::SEND_EOF))) goto cleanup; } @@ -703,7 +703,8 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, if (record_should_be_deleted(thd, table, select, explain, truncate_history)) { table->file->position(table->record[0]); - if ((error= deltempfile->unique_add((char*) table->file->ref))) + if (unlikely((error= + deltempfile->unique_add((char*) table->file->ref)))) { error= 1; goto terminate_delete; @@ -713,8 +714,10 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, } } end_read_record(&info); - if (deltempfile->get(table) || table->file->ha_index_or_rnd_end() || - init_read_record(&info, thd, table, 0, &deltempfile->sort, 0, 1, false)) + if (unlikely(deltempfile->get(table)) || + unlikely(table->file->ha_index_or_rnd_end()) || + unlikely(init_read_record(&info, thd, table, 0, &deltempfile->sort, 0, + 1, false))) { error= 1; goto terminate_delete; @@ -723,8 +726,8 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, } THD_STAGE_INFO(thd, stage_updating); - while (!(error=info.read_record()) && !thd->killed && - ! thd->is_error()) + while (likely(!(error=info.read_record())) && likely(!thd->killed) && + likely(!thd->is_error())) { if (delete_while_scanning) delete_record= record_should_be_deleted(thd, table, select, explain, @@ -746,7 +749,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, } error= table->delete_row(); - if (!error) + if (likely(!error)) { deleted++; if (!truncate_history && table->triggers && @@ -777,7 +780,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, Don't try unlocking the row if skip_record reported an error since in this case the transaction might have been rolled back already. */ - else if (!thd->is_error()) + else if (likely(!thd->is_error())) table->file->unlock_row(); // Row failed selection, release lock on it else break; @@ -785,9 +788,9 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, terminate_delete: killed_status= thd->killed; - if (killed_status != NOT_KILLED || thd->is_error()) + if (unlikely(killed_status != NOT_KILLED || thd->is_error())) error= 1; // Aborted - if (will_batch && (loc_error= table->file->end_bulk_delete())) + if (will_batch && unlikely((loc_error= table->file->end_bulk_delete()))) { if (error != 1) table->file->print_error(loc_error,MYF(0)); @@ -826,7 +829,7 @@ cleanup: thd->transaction.all.modified_non_trans_table= TRUE; /* See similar binlogging code in sql_update.cc, for comments */ - if ((error < 0) || thd->transaction.stmt.modified_non_trans_table) + if (likely((error < 0) || thd->transaction.stmt.modified_non_trans_table)) { if (WSREP_EMULATE_BINLOG(thd) || mysql_bin_log.is_open()) { @@ -857,7 +860,7 @@ cleanup: } DBUG_ASSERT(transactional_table || !deleted || thd->transaction.stmt.modified_non_trans_table); - if (error < 0 || + if (likely(error < 0) || (thd->lex->ignore && !thd->is_error() && !thd->is_fatal_error)) { if (thd->lex->analyze_stmt) @@ -1122,7 +1125,8 @@ multi_delete::initialize_tables(JOIN *join) Unique **tempfiles_ptr; DBUG_ENTER("initialize_tables"); - if ((thd->variables.option_bits & OPTION_SAFE_UPDATES) && error_if_full_join(join)) + if (unlikely((thd->variables.option_bits & OPTION_SAFE_UPDATES) && + error_if_full_join(join))) DBUG_RETURN(1); table_map tables_to_delete_from=0; @@ -1252,7 +1256,7 @@ int multi_delete::send_data(List<Item> &values) table->status|= STATUS_DELETED; error= table->delete_row(); - if (!error) + if (likely(!error)) { deleted++; if (!table->file->has_transactions()) @@ -1275,7 +1279,7 @@ int multi_delete::send_data(List<Item> &values) else { error=tempfiles[secure_counter]->unique_add((char*) table->file->ref); - if (error) + if (unlikely(error)) { error= 1; // Fatal error DBUG_RETURN(1); @@ -1371,19 +1375,19 @@ int multi_delete::do_deletes() { TABLE *table = table_being_deleted->table; int local_error; - if (tempfiles[counter]->get(table)) + if (unlikely(tempfiles[counter]->get(table))) DBUG_RETURN(1); local_error= do_table_deletes(table, &tempfiles[counter]->sort, thd->lex->ignore); - if (thd->killed && !local_error) + if (unlikely(thd->killed) && likely(!local_error)) DBUG_RETURN(1); - if (local_error == -1) // End of file - local_error = 0; + if (unlikely(local_error == -1)) // End of file + local_error= 0; - if (local_error) + if (unlikely(local_error)) DBUG_RETURN(local_error); } DBUG_RETURN(0); @@ -1413,7 +1417,8 @@ int multi_delete::do_table_deletes(TABLE *table, SORT_INFO *sort_info, ha_rows last_deleted= deleted; DBUG_ENTER("do_deletes_for_table"); - if (init_read_record(&info, thd, table, NULL, sort_info, 0, 1, FALSE)) + if (unlikely(init_read_record(&info, thd, table, NULL, sort_info, 0, 1, + FALSE))) DBUG_RETURN(1); /* @@ -1422,18 +1427,18 @@ int multi_delete::do_table_deletes(TABLE *table, SORT_INFO *sort_info, */ info.ignore_not_found_rows= 1; bool will_batch= !table->file->start_bulk_delete(); - while (!(local_error= info.read_record()) && !thd->killed) + while (likely(!(local_error= info.read_record())) && likely(!thd->killed)) { if (table->triggers && - table->triggers->process_triggers(thd, TRG_EVENT_DELETE, - TRG_ACTION_BEFORE, FALSE)) + unlikely(table->triggers->process_triggers(thd, TRG_EVENT_DELETE, + TRG_ACTION_BEFORE, FALSE))) { local_error= 1; break; } local_error= table->delete_row(); - if (local_error && !ignore) + if (unlikely(local_error) && !ignore) { table->file->print_error(local_error, MYF(0)); break; @@ -1444,7 +1449,7 @@ int multi_delete::do_table_deletes(TABLE *table, SORT_INFO *sort_info, during ha_delete_row. Also, don't execute the AFTER trigger if the row operation failed. */ - if (!local_error) + if (unlikely(!local_error)) { deleted++; if (table->triggers && @@ -1459,7 +1464,7 @@ int multi_delete::do_table_deletes(TABLE *table, SORT_INFO *sort_info, if (will_batch) { int tmp_error= table->file->end_bulk_delete(); - if (tmp_error && !local_error) + if (unlikely(tmp_error) && !local_error) { local_error= tmp_error; table->file->print_error(local_error, MYF(0)); @@ -1507,28 +1512,30 @@ bool multi_delete::send_eof() { query_cache_invalidate3(thd, delete_tables, 1); } - if ((local_error == 0) || thd->transaction.stmt.modified_non_trans_table) + if (likely((local_error == 0) || + thd->transaction.stmt.modified_non_trans_table)) { if(WSREP_EMULATE_BINLOG(thd) || mysql_bin_log.is_open()) { int errcode= 0; - if (local_error == 0) + if (likely(local_error == 0)) thd->clear_error(); else errcode= query_error_code(thd, killed_status == NOT_KILLED); - if (thd->binlog_query(THD::ROW_QUERY_TYPE, - thd->query(), thd->query_length(), - transactional_tables, FALSE, FALSE, errcode) && + if (unlikely(thd->binlog_query(THD::ROW_QUERY_TYPE, + thd->query(), thd->query_length(), + transactional_tables, FALSE, FALSE, + errcode)) && !normal_tables) { local_error=1; // Log write failed: roll back the SQL statement } } } - if (local_error != 0) + if (unlikely(local_error != 0)) error_handled= TRUE; // to force early leave from ::abort_result_set() - if (!local_error && !thd->lex->analyze_stmt) + if (likely(!local_error && !thd->lex->analyze_stmt)) { ::my_ok(thd, deleted); } |