summaryrefslogtreecommitdiff
path: root/sql/log_event_old.cc
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2018-04-04 12:16:12 +0300
committerMonty <monty@mariadb.org>2018-05-07 00:07:32 +0300
commit30ebc3ee9efcab635b1f3e14b9198a58ae93c233 (patch)
tree81e3ad66cd4ec8693964317cbf23515d0e9ecf35 /sql/log_event_old.cc
parenta22a339f8e044a1e8df011beb0b4c8f43792ac96 (diff)
downloadmariadb-git-30ebc3ee9efcab635b1f3e14b9198a58ae93c233.tar.gz
Add likely/unlikely to speed up execution
Added to: - if (error) - Lex - sql_yacc.yy and sql_yacc_ora.yy - In header files to alloc() calls - Added thd argument to thd_net_is_killed()
Diffstat (limited to 'sql/log_event_old.cc')
-rw-r--r--sql/log_event_old.cc103
1 files changed, 55 insertions, 48 deletions
diff --git a/sql/log_event_old.cc b/sql/log_event_old.cc
index b1552bfcbba..6154f30070f 100644
--- a/sql/log_event_old.cc
+++ b/sql/log_event_old.cc
@@ -99,7 +99,7 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, rpl_group_info *rgi)
*/
ev_thd->lex->set_stmt_row_injection();
- if (open_and_lock_tables(ev_thd, rgi->tables_to_lock, FALSE, 0))
+ if (unlikely(open_and_lock_tables(ev_thd, rgi->tables_to_lock, FALSE, 0)))
{
uint actual_error= ev_thd->get_stmt_da()->sql_errno();
if (ev_thd->is_slave_error || ev_thd->is_fatal_error)
@@ -228,7 +228,8 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, rpl_group_info *rgi)
while (error == 0 && row_start < ev->m_rows_end)
{
uchar const *row_end= NULL;
- if ((error= do_prepare_row(ev_thd, rgi, table, row_start, &row_end)))
+ if (unlikely((error= do_prepare_row(ev_thd, rgi, table, row_start,
+ &row_end))))
break; // We should perform the after-row operation even in
// the case of error
@@ -267,7 +268,7 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, rpl_group_info *rgi)
error= do_after_row_operations(table, error);
}
- if (error)
+ if (unlikely(error))
{ /* error has occurred during the transaction */
rli->report(ERROR_LEVEL, ev_thd->get_stmt_da()->sql_errno(), NULL,
"Error in %s event: error during transaction execution "
@@ -478,14 +479,14 @@ replace_record(THD *thd, TABLE *table,
DBUG_PRINT_BITSET("debug", "read_set = %s", table->read_set);
#endif
- while ((error= table->file->ha_write_row(table->record[0])))
+ while (unlikely(error= table->file->ha_write_row(table->record[0])))
{
if (error == HA_ERR_LOCK_DEADLOCK || error == HA_ERR_LOCK_WAIT_TIMEOUT)
{
table->file->print_error(error, MYF(0)); /* to check at exec_relay_log_event */
DBUG_RETURN(error);
}
- if ((keynum= table->file->get_dup_key(error)) < 0)
+ if (unlikely((keynum= table->file->get_dup_key(error)) < 0))
{
table->file->print_error(error, MYF(0));
/*
@@ -509,7 +510,7 @@ replace_record(THD *thd, TABLE *table,
if (table->file->ha_table_flags() & HA_DUPLICATE_POS)
{
error= table->file->ha_rnd_pos(table->record[1], table->file->dup_ref);
- if (error)
+ if (unlikely(error))
{
DBUG_PRINT("info",("rnd_pos() returns error %d",error));
if (error == HA_ERR_RECORD_DELETED)
@@ -520,7 +521,7 @@ replace_record(THD *thd, TABLE *table,
}
else
{
- if (table->file->extra(HA_EXTRA_FLUSH_CACHE))
+ if (unlikely(table->file->extra(HA_EXTRA_FLUSH_CACHE)))
{
DBUG_RETURN(my_errno);
}
@@ -528,7 +529,7 @@ replace_record(THD *thd, TABLE *table,
if (key.get() == NULL)
{
key.assign(static_cast<char*>(my_alloca(table->s->max_unique_length)));
- if (key.get() == NULL)
+ if (unlikely(key.get() == NULL))
DBUG_RETURN(ENOMEM);
}
@@ -538,7 +539,7 @@ replace_record(THD *thd, TABLE *table,
(const uchar*)key.get(),
HA_WHOLE_KEY,
HA_READ_KEY_EXACT);
- if (error)
+ if (unlikely(error))
{
DBUG_PRINT("info", ("index_read_idx() returns error %d", error));
if (error == HA_ERR_RECORD_DELETED)
@@ -578,7 +579,7 @@ replace_record(THD *thd, TABLE *table,
{
error=table->file->ha_update_row(table->record[1],
table->record[0]);
- if (error && error != HA_ERR_RECORD_IS_THE_SAME)
+ if (unlikely(error) && error != HA_ERR_RECORD_IS_THE_SAME)
table->file->print_error(error, MYF(0));
else
error= 0;
@@ -586,7 +587,7 @@ replace_record(THD *thd, TABLE *table,
}
else
{
- if ((error= table->file->ha_delete_row(table->record[1])))
+ if (unlikely((error= table->file->ha_delete_row(table->record[1]))))
{
table->file->print_error(error, MYF(0));
DBUG_RETURN(error);
@@ -672,7 +673,8 @@ static int find_and_fetch_row(TABLE *table, uchar *key)
{
int error;
/* We have a key: search the table using the index */
- if (!table->file->inited && (error= table->file->ha_index_init(0, FALSE)))
+ if (!table->file->inited &&
+ unlikely(error= table->file->ha_index_init(0, FALSE)))
{
table->file->print_error(error, MYF(0));
DBUG_RETURN(error);
@@ -696,9 +698,9 @@ static int find_and_fetch_row(TABLE *table, uchar *key)
my_ptrdiff_t const pos=
table->s->null_bytes > 0 ? table->s->null_bytes - 1 : 0;
table->record[1][pos]= 0xFF;
- if ((error= table->file->ha_index_read_map(table->record[1], key,
- HA_WHOLE_KEY,
- HA_READ_KEY_EXACT)))
+ if (unlikely((error= table->file->ha_index_read_map(table->record[1], key,
+ HA_WHOLE_KEY,
+ HA_READ_KEY_EXACT))))
{
table->file->print_error(error, MYF(0));
table->file->ha_index_end();
@@ -740,7 +742,7 @@ static int find_and_fetch_row(TABLE *table, uchar *key)
while ((error= table->file->ha_index_next(table->record[1])))
{
/* We just skip records that has already been deleted */
- if (error == HA_ERR_RECORD_DELETED)
+ if (unlikely(error == HA_ERR_RECORD_DELETED))
continue;
table->file->print_error(error, MYF(0));
table->file->ha_index_end();
@@ -759,7 +761,7 @@ static int find_and_fetch_row(TABLE *table, uchar *key)
int error;
/* We don't have a key: search the table using rnd_next() */
- if ((error= table->file->ha_rnd_init_with_error(1)))
+ if (unlikely((error= table->file->ha_rnd_init_with_error(1))))
return error;
/* Continue until we find the right record or have made a full loop */
@@ -786,7 +788,7 @@ static int find_and_fetch_row(TABLE *table, uchar *key)
if (++restart_count < 2)
{
int error2;
- if ((error2= table->file->ha_rnd_init_with_error(1)))
+ if (unlikely((error2= table->file->ha_rnd_init_with_error(1))))
DBUG_RETURN(error2);
}
break;
@@ -854,7 +856,7 @@ int Write_rows_log_event_old::do_after_row_operations(TABLE *table, int error)
fires bug#27077
todo: explain or fix
*/
- if ((local_error= table->file->ha_end_bulk_insert()))
+ if (unlikely((local_error= table->file->ha_end_bulk_insert())))
{
table->file->print_error(local_error, MYF(0));
}
@@ -986,7 +988,7 @@ int Delete_rows_log_event_old::do_exec_row(TABLE *table)
int error;
DBUG_ASSERT(table != NULL);
- if (!(error= ::find_and_fetch_row(table, m_key)))
+ if (likely(!(error= ::find_and_fetch_row(table, m_key))))
{
/*
Now we should have the right row to delete. We are using
@@ -1095,7 +1097,7 @@ int Update_rows_log_event_old::do_exec_row(TABLE *table)
DBUG_ASSERT(table != NULL);
int error= ::find_and_fetch_row(table, m_key);
- if (error)
+ if (unlikely(error))
return error;
/*
@@ -1121,7 +1123,7 @@ int Update_rows_log_event_old::do_exec_row(TABLE *table)
database into the after image delivered from the master.
*/
error= table->file->ha_update_row(table->record[1], table->record[0]);
- if (error == HA_ERR_RECORD_IS_THE_SAME)
+ if (unlikely(error == HA_ERR_RECORD_IS_THE_SAME))
error= 0;
return error;
@@ -1417,8 +1419,8 @@ int Old_rows_log_event::do_apply_event(rpl_group_info *rgi)
*/
lex_start(thd);
- if ((error= lock_tables(thd, rgi->tables_to_lock,
- rgi->tables_to_lock_count, 0)))
+ if (unlikely((error= lock_tables(thd, rgi->tables_to_lock,
+ rgi->tables_to_lock_count, 0))))
{
if (thd->is_slave_error || thd->is_fatal_error)
{
@@ -1610,7 +1612,7 @@ int Old_rows_log_event::do_apply_event(rpl_group_info *rgi)
DBUG_PRINT("info", ("curr_row: %p; curr_row_end:%p; rows_end: %p",
m_curr_row, m_curr_row_end, m_rows_end));
- if (!m_curr_row_end && !error)
+ if (!m_curr_row_end && likely(!error))
unpack_current_row(rgi);
// at this moment m_curr_row_end should be set
@@ -1627,7 +1629,7 @@ int Old_rows_log_event::do_apply_event(rpl_group_info *rgi)
error= do_after_row_operations(rli, error);
} // if (table)
- if (error)
+ if (unlikely(error))
{ /* error has occurred during the transaction */
rli->report(ERROR_LEVEL, thd->net.last_errno, NULL,
"Error in %s event: error during transaction execution "
@@ -1711,7 +1713,9 @@ int Old_rows_log_event::do_apply_event(rpl_group_info *rgi)
already. So there should be no need to rollback the transaction.
*/
DBUG_ASSERT(! thd->transaction_rollback_request);
- if ((error= (binlog_error ? trans_rollback_stmt(thd) : trans_commit_stmt(thd))))
+ if (unlikely((error= (binlog_error ?
+ trans_rollback_stmt(thd) :
+ trans_commit_stmt(thd)))))
rli->report(ERROR_LEVEL, error, NULL,
"Error in %s event: commit of row events failed, "
"table `%s`.`%s`",
@@ -1932,8 +1936,9 @@ Old_rows_log_event::write_row(rpl_group_info *rgi, const bool overwrite)
/* fill table->record[0] with default values */
- if ((error= prepare_record(table, m_width,
- TRUE /* check if columns have def. values */)))
+ if (unlikely((error=
+ prepare_record(table, m_width,
+ TRUE /* check if columns have def. values */))))
DBUG_RETURN(error);
/* unpack row into table->record[0] */
@@ -1954,14 +1959,14 @@ Old_rows_log_event::write_row(rpl_group_info *rgi, const bool overwrite)
TODO: Add safety measures against infinite looping.
*/
- while ((error= table->file->ha_write_row(table->record[0])))
+ while (unlikely(error= table->file->ha_write_row(table->record[0])))
{
if (error == HA_ERR_LOCK_DEADLOCK || error == HA_ERR_LOCK_WAIT_TIMEOUT)
{
table->file->print_error(error, MYF(0)); /* to check at exec_relay_log_event */
DBUG_RETURN(error);
}
- if ((keynum= table->file->get_dup_key(error)) < 0)
+ if (unlikely((keynum= table->file->get_dup_key(error)) < 0))
{
DBUG_PRINT("info",("Can't locate duplicate key (get_dup_key returns %d)",keynum));
table->file->print_error(error, MYF(0));
@@ -1987,7 +1992,7 @@ Old_rows_log_event::write_row(rpl_group_info *rgi, const bool overwrite)
{
DBUG_PRINT("info",("Locating offending record using rnd_pos()"));
error= table->file->ha_rnd_pos(table->record[1], table->file->dup_ref);
- if (error)
+ if (unlikely(error))
{
DBUG_PRINT("info",("rnd_pos() returns error %d",error));
if (error == HA_ERR_RECORD_DELETED)
@@ -2009,7 +2014,7 @@ Old_rows_log_event::write_row(rpl_group_info *rgi, const bool overwrite)
if (key.get() == NULL)
{
key.assign(static_cast<char*>(my_alloca(table->s->max_unique_length)));
- if (key.get() == NULL)
+ if (unlikely(key.get() == NULL))
{
DBUG_PRINT("info",("Can't allocate key buffer"));
DBUG_RETURN(ENOMEM);
@@ -2022,7 +2027,7 @@ Old_rows_log_event::write_row(rpl_group_info *rgi, const bool overwrite)
(const uchar*)key.get(),
HA_WHOLE_KEY,
HA_READ_KEY_EXACT);
- if (error)
+ if (unlikely(error))
{
DBUG_PRINT("info",("index_read_idx() returns error %d", error));
if (error == HA_ERR_RECORD_DELETED)
@@ -2095,7 +2100,7 @@ Old_rows_log_event::write_row(rpl_group_info *rgi, const bool overwrite)
else
{
DBUG_PRINT("info",("Deleting offending row and trying to write new one again"));
- if ((error= table->file->ha_delete_row(table->record[1])))
+ if (unlikely((error= table->file->ha_delete_row(table->record[1]))))
{
DBUG_PRINT("info",("ha_delete_row() returns error %d",error));
table->file->print_error(error, MYF(0));
@@ -2183,7 +2188,7 @@ int Old_rows_log_event::find_row(rpl_group_info *rgi)
*/
DBUG_PRINT("info",("locating record using primary key (position)"));
int error= table->file->ha_rnd_pos_by_record(table->record[0]);
- if (error)
+ if (unlikely(error))
{
DBUG_PRINT("info",("rnd_pos returns error %d",error));
if (error == HA_ERR_RECORD_DELETED)
@@ -2212,7 +2217,8 @@ int Old_rows_log_event::find_row(rpl_group_info *rgi)
DBUG_PRINT("info",("locating record using primary key (index_read)"));
/* We have a key: search the table using the index */
- if (!table->file->inited && (error= table->file->ha_index_init(0, FALSE)))
+ if (!table->file->inited &&
+ unlikely(error= table->file->ha_index_init(0, FALSE)))
{
DBUG_PRINT("info",("ha_index_init returns error %d",error));
table->file->print_error(error, MYF(0));
@@ -2242,9 +2248,10 @@ int Old_rows_log_event::find_row(rpl_group_info *rgi)
table->s->null_bytes > 0 ? table->s->null_bytes - 1 : 0;
table->record[0][pos]= 0xFF;
- if ((error= table->file->ha_index_read_map(table->record[0], m_key,
- HA_WHOLE_KEY,
- HA_READ_KEY_EXACT)))
+ if (unlikely((error= table->file->ha_index_read_map(table->record[0],
+ m_key,
+ HA_WHOLE_KEY,
+ HA_READ_KEY_EXACT))))
{
DBUG_PRINT("info",("no record matching the key found in the table"));
if (error == HA_ERR_RECORD_DELETED)
@@ -2316,7 +2323,7 @@ int Old_rows_log_event::find_row(rpl_group_info *rgi)
while (record_compare(table))
{
- while ((error= table->file->ha_index_next(table->record[0])))
+ while (unlikely(error= table->file->ha_index_next(table->record[0])))
{
/* We just skip records that has already been deleted */
if (error == HA_ERR_RECORD_DELETED)
@@ -2335,7 +2342,7 @@ int Old_rows_log_event::find_row(rpl_group_info *rgi)
int restart_count= 0; // Number of times scanning has restarted from top
/* We don't have a key: search the table using rnd_next() */
- if ((error= table->file->ha_rnd_init_with_error(1)))
+ if (unlikely((error= table->file->ha_rnd_init_with_error(1))))
{
DBUG_PRINT("info",("error initializing table scan"
" (ha_rnd_init returns %d)",error));
@@ -2361,7 +2368,7 @@ int Old_rows_log_event::find_row(rpl_group_info *rgi)
{
int error2;
table->file->ha_rnd_end();
- if ((error2= table->file->ha_rnd_init_with_error(1)))
+ if (unlikely((error2= table->file->ha_rnd_init_with_error(1))))
DBUG_RETURN(error2);
goto restart_rnd_next;
}
@@ -2480,7 +2487,7 @@ Write_rows_log_event_old::do_after_row_operations(const Slave_reporting_capabili
fires bug#27077
todo: explain or fix
*/
- if ((local_error= m_table->file->ha_end_bulk_insert()))
+ if (unlikely((local_error= m_table->file->ha_end_bulk_insert())))
{
m_table->file->print_error(local_error, MYF(0));
}
@@ -2494,7 +2501,7 @@ Write_rows_log_event_old::do_exec_row(rpl_group_info *rgi)
DBUG_ASSERT(m_table != NULL);
int error= write_row(rgi, TRUE /* overwrite */);
- if (error && !thd->net.last_errno)
+ if (unlikely(error) && !thd->net.last_errno)
thd->net.last_errno= error;
return error;
@@ -2597,7 +2604,7 @@ int Delete_rows_log_event_old::do_exec_row(rpl_group_info *rgi)
int error;
DBUG_ASSERT(m_table != NULL);
- if (!(error= find_row(rgi)))
+ if (likely(!(error= find_row(rgi))) )
{
/*
Delete the record found, located in record[0]
@@ -2697,7 +2704,7 @@ Update_rows_log_event_old::do_exec_row(rpl_group_info *rgi)
DBUG_ASSERT(m_table != NULL);
int error= find_row(rgi);
- if (error)
+ if (unlikely(error))
{
/*
We need to read the second image in the event of error to be
@@ -2741,7 +2748,7 @@ Update_rows_log_event_old::do_exec_row(rpl_group_info *rgi)
error= m_table->file->ha_update_row(m_table->record[1], m_table->record[0]);
m_table->file->ha_index_or_rnd_end();
- if (error == HA_ERR_RECORD_IS_THE_SAME)
+ if (unlikely(error == HA_ERR_RECORD_IS_THE_SAME))
error= 0;
return error;