diff options
author | Galina Shalygina <galina.shalygina@mariadb.com> | 2018-06-01 21:57:10 +0200 |
---|---|---|
committer | Galina Shalygina <galina.shalygina@mariadb.com> | 2018-06-01 21:57:10 +0200 |
commit | 6db465d7ce455cf75ec224108cbe61ca8be63d3d (patch) | |
tree | 9648ff1fc677eebb60b278c2e2c13131934ed2a0 /sql/sql_delete.cc | |
parent | ffe83e8e7bef32eb2a80aad2d382f0b023dd3a44 (diff) | |
parent | 4a49f7f88cfa82ae6eb8e7b5a528e91416b33b52 (diff) | |
download | mariadb-git-shagalla-10.4.tar.gz |
Merge 10.3.7 into 10.4shagalla-10.4
Diffstat (limited to 'sql/sql_delete.cc')
-rw-r--r-- | sql/sql_delete.cc | 119 |
1 files changed, 60 insertions, 59 deletions
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 0a12d01596b..b6ca2e956cb 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -254,7 +254,12 @@ int TABLE::delete_row() store_record(this, record[1]); vers_update_end(); - return file->ha_update_row(record[1], record[0]); + int res; + if ((res= file->extra(HA_EXTRA_REMEMBER_POS))) + return res; + if ((res= file->ha_update_row(record[1], record[0]))) + return res; + return file->extra(HA_EXTRA_RESTORE_POS); } @@ -305,7 +310,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, THD_STAGE_INFO(thd, stage_init_update); - bool truncate_history= table_list->vers_conditions; + bool truncate_history= table_list->vers_conditions.is_set(); if (truncate_history) { if (table_list->is_view_or_derived()) @@ -324,13 +329,6 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, DBUG_ASSERT(!conds); conds= table_list->on_expr; table_list->on_expr= NULL; - - // trx_sees() in InnoDB reads row_start - if (!table->versioned(VERS_TIMESTAMP)) - { - DBUG_ASSERT(table_list->vers_conditions.type == SYSTEM_TIME_BEFORE); - bitmap_set_bit(table->read_set, table->vers_end_field()->field_index); - } } if (mysql_handle_list_of_derived(thd->lex, table_list, DT_MERGE_FOR_INSERT)) @@ -401,7 +399,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 +437,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 +493,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 +509,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 +660,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 +674,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 +701,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 +712,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 +724,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 +747,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 +778,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 +786,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 +827,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 +858,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) @@ -938,7 +939,7 @@ int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, select_lex->leaf_tables, FALSE, DELETE_ACL, SELECT_ACL, TRUE)) DBUG_RETURN(TRUE); - if (table_list->vers_conditions) + if (table_list->vers_conditions.is_set()) { if (table_list->is_view()) { @@ -948,7 +949,8 @@ int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, if (select_lex->vers_setup_conds(thd, table_list)) DBUG_RETURN(true); } - if ((wild_num && setup_wild(thd, table_list, field_list, NULL, wild_num)) || + if ((wild_num && setup_wild(thd, table_list, field_list, NULL, wild_num, + &select_lex->hidden_bit_fields)) || setup_fields(thd, Ref_ptr_array(), field_list, MARK_COLUMNS_READ, NULL, NULL, 0) || setup_conds(thd, table_list, select_lex->leaf_tables, conds) || @@ -1122,7 +1124,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; @@ -1132,7 +1135,7 @@ multi_delete::initialize_tables(JOIN *join) TABLE_LIST *tbl= walk->correspondent_table->find_table_for_update(); tables_to_delete_from|= tbl->table->map; if (delete_while_scanning && - unique_table(thd, tbl, join->tables_list, false)) + unique_table(thd, tbl, join->tables_list, 0)) { /* If the table we are going to delete from appears @@ -1252,7 +1255,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 +1278,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 +1374,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,27 +1416,23 @@ 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); - /* - Ignore any rows not found in reference tables as they may already have - been deleted by foreign key handling - */ - 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 +1443,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 +1458,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 +1506,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); } |