mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
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()
This commit is contained in:
@ -67,25 +67,29 @@ bool Sql_cmd_alter_table_exchange_partition::execute(THD *thd)
|
||||
|
||||
DBUG_ENTER("Sql_cmd_alter_table_exchange_partition::execute");
|
||||
|
||||
if (thd->is_fatal_error) /* out of memory creating a copy of alter_info */
|
||||
if (unlikely(thd->is_fatal_error))
|
||||
{
|
||||
/* out of memory creating a copy of alter_info */
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
|
||||
/* Must be set in the parser */
|
||||
DBUG_ASSERT(select_lex->db.str);
|
||||
/* also check the table to be exchanged with the partition */
|
||||
DBUG_ASSERT(alter_info.partition_flags & ALTER_PARTITION_EXCHANGE);
|
||||
|
||||
if (check_access(thd, priv_needed, first_table->db.str,
|
||||
&first_table->grant.privilege,
|
||||
&first_table->grant.m_internal,
|
||||
0, 0) ||
|
||||
check_access(thd, priv_needed, first_table->next_local->db.str,
|
||||
&first_table->next_local->grant.privilege,
|
||||
&first_table->next_local->grant.m_internal,
|
||||
0, 0))
|
||||
if (unlikely(check_access(thd, priv_needed, first_table->db.str,
|
||||
&first_table->grant.privilege,
|
||||
&first_table->grant.m_internal,
|
||||
0, 0)) ||
|
||||
unlikely(check_access(thd, priv_needed, first_table->next_local->db.str,
|
||||
&first_table->next_local->grant.privilege,
|
||||
&first_table->next_local->grant.m_internal,
|
||||
0, 0)))
|
||||
DBUG_RETURN(TRUE);
|
||||
|
||||
if (check_grant(thd, priv_needed, first_table, FALSE, UINT_MAX, FALSE))
|
||||
if (unlikely(check_grant(thd, priv_needed, first_table, FALSE, UINT_MAX,
|
||||
FALSE)))
|
||||
DBUG_RETURN(TRUE);
|
||||
|
||||
/* Not allowed with EXCHANGE PARTITION */
|
||||
@ -109,31 +113,32 @@ bool Sql_cmd_alter_table_exchange_partition::execute(THD *thd)
|
||||
|
||||
@retval FALSE if OK, otherwise error is reported and TRUE is returned.
|
||||
*/
|
||||
|
||||
static bool check_exchange_partition(TABLE *table, TABLE *part_table)
|
||||
{
|
||||
DBUG_ENTER("check_exchange_partition");
|
||||
|
||||
/* Both tables must exist */
|
||||
if (!part_table || !table)
|
||||
if (unlikely(!part_table || !table))
|
||||
{
|
||||
my_error(ER_CHECK_NO_SUCH_TABLE, MYF(0));
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
|
||||
/* The first table must be partitioned, and the second must not */
|
||||
if (!part_table->part_info)
|
||||
if (unlikely(!part_table->part_info))
|
||||
{
|
||||
my_error(ER_PARTITION_MGMT_ON_NONPARTITIONED, MYF(0));
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
if (table->part_info)
|
||||
if (unlikely(table->part_info))
|
||||
{
|
||||
my_error(ER_PARTITION_EXCHANGE_PART_TABLE, MYF(0),
|
||||
table->s->table_name.str);
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
|
||||
if (part_table->file->ht != partition_hton)
|
||||
if (unlikely(part_table->file->ht != partition_hton))
|
||||
{
|
||||
/*
|
||||
Only allowed on partitioned tables throught the generic ha_partition
|
||||
@ -143,14 +148,14 @@ static bool check_exchange_partition(TABLE *table, TABLE *part_table)
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
|
||||
if (table->file->ht != part_table->part_info->default_engine_type)
|
||||
if (unlikely(table->file->ht != part_table->part_info->default_engine_type))
|
||||
{
|
||||
my_error(ER_MIX_HANDLER_ERROR, MYF(0));
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
|
||||
/* Verify that table is not tmp table, partitioned tables cannot be tmp. */
|
||||
if (table->s->tmp_table != NO_TMP_TABLE)
|
||||
if (unlikely(table->s->tmp_table != NO_TMP_TABLE))
|
||||
{
|
||||
my_error(ER_PARTITION_EXCHANGE_TEMP_TABLE, MYF(0),
|
||||
table->s->table_name.str);
|
||||
@ -158,7 +163,7 @@ static bool check_exchange_partition(TABLE *table, TABLE *part_table)
|
||||
}
|
||||
|
||||
/* The table cannot have foreign keys constraints or be referenced */
|
||||
if(!table->file->can_switch_engines())
|
||||
if (unlikely(!table->file->can_switch_engines()))
|
||||
{
|
||||
my_error(ER_PARTITION_EXCHANGE_FOREIGN_KEY, MYF(0),
|
||||
table->s->table_name.str);
|
||||
@ -197,8 +202,8 @@ static bool compare_table_with_partition(THD *thd, TABLE *table,
|
||||
/* mark all columns used, since they are used when preparing the new table */
|
||||
part_table->use_all_columns();
|
||||
table->use_all_columns();
|
||||
if (mysql_prepare_alter_table(thd, part_table, &part_create_info,
|
||||
&part_alter_info, &part_alter_ctx))
|
||||
if (unlikely(mysql_prepare_alter_table(thd, part_table, &part_create_info,
|
||||
&part_alter_info, &part_alter_ctx)))
|
||||
{
|
||||
my_error(ER_TABLES_DIFFERENT_METADATA, MYF(0));
|
||||
DBUG_RETURN(TRUE);
|
||||
@ -336,7 +341,7 @@ static bool exchange_name_with_ddl_log(THD *thd,
|
||||
handler *file= NULL;
|
||||
DBUG_ENTER("exchange_name_with_ddl_log");
|
||||
|
||||
if (!(file= get_new_handler(NULL, thd->mem_root, ht)))
|
||||
if (unlikely(!(file= get_new_handler(NULL, thd->mem_root, ht))))
|
||||
{
|
||||
mem_alloc_error(sizeof(handler));
|
||||
DBUG_RETURN(TRUE);
|
||||
@ -360,12 +365,13 @@ static bool exchange_name_with_ddl_log(THD *thd,
|
||||
*/
|
||||
DBUG_EXECUTE_IF("exchange_partition_fail_1", goto err_no_action_written;);
|
||||
DBUG_EXECUTE_IF("exchange_partition_abort_1", DBUG_SUICIDE(););
|
||||
if (write_ddl_log_entry(&exchange_entry, &log_entry))
|
||||
if (unlikely(write_ddl_log_entry(&exchange_entry, &log_entry)))
|
||||
goto err_no_action_written;
|
||||
|
||||
DBUG_EXECUTE_IF("exchange_partition_fail_2", goto err_no_execute_written;);
|
||||
DBUG_EXECUTE_IF("exchange_partition_abort_2", DBUG_SUICIDE(););
|
||||
if (write_execute_ddl_log_entry(log_entry->entry_pos, FALSE, &exec_log_entry))
|
||||
if (unlikely(write_execute_ddl_log_entry(log_entry->entry_pos, FALSE,
|
||||
&exec_log_entry)))
|
||||
goto err_no_execute_written;
|
||||
/* ddl_log is written and synced */
|
||||
|
||||
@ -383,7 +389,7 @@ static bool exchange_name_with_ddl_log(THD *thd,
|
||||
error_set= TRUE;
|
||||
goto err_rename;);
|
||||
DBUG_EXECUTE_IF("exchange_partition_abort_3", DBUG_SUICIDE(););
|
||||
if (file->ha_rename_table(name, tmp_name))
|
||||
if (unlikely(file->ha_rename_table(name, tmp_name)))
|
||||
{
|
||||
my_error(ER_ERROR_ON_RENAME, MYF(0), name, tmp_name, my_errno);
|
||||
error_set= TRUE;
|
||||
@ -391,7 +397,7 @@ static bool exchange_name_with_ddl_log(THD *thd,
|
||||
}
|
||||
DBUG_EXECUTE_IF("exchange_partition_fail_4", goto err_rename;);
|
||||
DBUG_EXECUTE_IF("exchange_partition_abort_4", DBUG_SUICIDE(););
|
||||
if (deactivate_ddl_log_entry(log_entry->entry_pos))
|
||||
if (unlikely(deactivate_ddl_log_entry(log_entry->entry_pos)))
|
||||
goto err_rename;
|
||||
|
||||
/* call rename table from partition to table */
|
||||
@ -400,7 +406,7 @@ static bool exchange_name_with_ddl_log(THD *thd,
|
||||
error_set= TRUE;
|
||||
goto err_rename;);
|
||||
DBUG_EXECUTE_IF("exchange_partition_abort_5", DBUG_SUICIDE(););
|
||||
if (file->ha_rename_table(from_name, name))
|
||||
if (unlikely(file->ha_rename_table(from_name, name)))
|
||||
{
|
||||
my_error(ER_ERROR_ON_RENAME, MYF(0), from_name, name, my_errno);
|
||||
error_set= TRUE;
|
||||
@ -408,7 +414,7 @@ static bool exchange_name_with_ddl_log(THD *thd,
|
||||
}
|
||||
DBUG_EXECUTE_IF("exchange_partition_fail_6", goto err_rename;);
|
||||
DBUG_EXECUTE_IF("exchange_partition_abort_6", DBUG_SUICIDE(););
|
||||
if (deactivate_ddl_log_entry(log_entry->entry_pos))
|
||||
if (unlikely(deactivate_ddl_log_entry(log_entry->entry_pos)))
|
||||
goto err_rename;
|
||||
|
||||
/* call rename table from tmp-nam to partition */
|
||||
@ -417,7 +423,7 @@ static bool exchange_name_with_ddl_log(THD *thd,
|
||||
error_set= TRUE;
|
||||
goto err_rename;);
|
||||
DBUG_EXECUTE_IF("exchange_partition_abort_7", DBUG_SUICIDE(););
|
||||
if (file->ha_rename_table(tmp_name, from_name))
|
||||
if (unlikely(file->ha_rename_table(tmp_name, from_name)))
|
||||
{
|
||||
my_error(ER_ERROR_ON_RENAME, MYF(0), tmp_name, from_name, my_errno);
|
||||
error_set= TRUE;
|
||||
@ -425,7 +431,7 @@ static bool exchange_name_with_ddl_log(THD *thd,
|
||||
}
|
||||
DBUG_EXECUTE_IF("exchange_partition_fail_8", goto err_rename;);
|
||||
DBUG_EXECUTE_IF("exchange_partition_abort_8", DBUG_SUICIDE(););
|
||||
if (deactivate_ddl_log_entry(log_entry->entry_pos))
|
||||
if (unlikely(deactivate_ddl_log_entry(log_entry->entry_pos)))
|
||||
goto err_rename;
|
||||
|
||||
/* The exchange is complete and ddl_log is deactivated */
|
||||
@ -525,23 +531,24 @@ bool Sql_cmd_alter_table_exchange_partition::
|
||||
to be able to verify the structure/metadata.
|
||||
*/
|
||||
table_list->mdl_request.set_type(MDL_SHARED_NO_WRITE);
|
||||
if (open_tables(thd, &table_list, &table_counter, 0,
|
||||
&alter_prelocking_strategy))
|
||||
if (unlikely(open_tables(thd, &table_list, &table_counter, 0,
|
||||
&alter_prelocking_strategy)))
|
||||
DBUG_RETURN(true);
|
||||
|
||||
part_table= table_list->table;
|
||||
swap_table= swap_table_list->table;
|
||||
|
||||
if (check_exchange_partition(swap_table, part_table))
|
||||
if (unlikely(check_exchange_partition(swap_table, part_table)))
|
||||
DBUG_RETURN(TRUE);
|
||||
|
||||
/* set lock pruning on first table */
|
||||
partition_name= alter_info->partition_names.head();
|
||||
if (table_list->table->part_info->
|
||||
set_named_partition_bitmap(partition_name, strlen(partition_name)))
|
||||
if (unlikely(table_list->table->part_info->
|
||||
set_named_partition_bitmap(partition_name,
|
||||
strlen(partition_name))))
|
||||
DBUG_RETURN(true);
|
||||
|
||||
if (lock_tables(thd, table_list, table_counter, 0))
|
||||
if (unlikely(lock_tables(thd, table_list, table_counter, 0)))
|
||||
DBUG_RETURN(true);
|
||||
|
||||
|
||||
@ -569,32 +576,35 @@ bool Sql_cmd_alter_table_exchange_partition::
|
||||
table_list->next_local->db.str,
|
||||
temp_name, "", FN_IS_TMP);
|
||||
|
||||
if (!(part_elem= part_table->part_info->get_part_elem(partition_name,
|
||||
part_file_name + part_file_name_len,
|
||||
sizeof(part_file_name) - part_file_name_len,
|
||||
&swap_part_id)))
|
||||
if (unlikely(!(part_elem=
|
||||
part_table->part_info->get_part_elem(partition_name,
|
||||
part_file_name +
|
||||
part_file_name_len,
|
||||
sizeof(part_file_name) -
|
||||
part_file_name_len,
|
||||
&swap_part_id))))
|
||||
{
|
||||
// my_error(ER_UNKNOWN_PARTITION, MYF(0), partition_name,
|
||||
// part_table->alias);
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
|
||||
if (swap_part_id == NOT_A_PARTITION_ID)
|
||||
if (unlikely(swap_part_id == NOT_A_PARTITION_ID))
|
||||
{
|
||||
DBUG_ASSERT(part_table->part_info->is_sub_partitioned());
|
||||
my_error(ER_PARTITION_INSTEAD_OF_SUBPARTITION, MYF(0));
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
|
||||
if (compare_table_with_partition(thd, swap_table, part_table, part_elem,
|
||||
swap_part_id))
|
||||
if (unlikely(compare_table_with_partition(thd, swap_table, part_table,
|
||||
part_elem,
|
||||
swap_part_id)))
|
||||
DBUG_RETURN(TRUE);
|
||||
|
||||
/* Table and partition has same structure/options, OK to exchange */
|
||||
|
||||
thd_proc_info(thd, "Verifying data with partition");
|
||||
|
||||
if (verify_data_with_partition(swap_table, part_table, swap_part_id))
|
||||
if (unlikely(verify_data_with_partition(swap_table, part_table,
|
||||
swap_part_id)))
|
||||
DBUG_RETURN(TRUE);
|
||||
|
||||
/*
|
||||
@ -621,8 +631,8 @@ bool Sql_cmd_alter_table_exchange_partition::
|
||||
|
||||
DEBUG_SYNC(thd, "swap_partition_before_rename");
|
||||
|
||||
if (exchange_name_with_ddl_log(thd, swap_file_name, part_file_name,
|
||||
temp_file_name, table_hton))
|
||||
if (unlikely(exchange_name_with_ddl_log(thd, swap_file_name, part_file_name,
|
||||
temp_file_name, table_hton)))
|
||||
goto err;
|
||||
|
||||
/*
|
||||
@ -632,7 +642,8 @@ bool Sql_cmd_alter_table_exchange_partition::
|
||||
*/
|
||||
(void) thd->locked_tables_list.reopen_tables(thd, false);
|
||||
|
||||
if ((error= write_bin_log(thd, TRUE, thd->query(), thd->query_length())))
|
||||
if (unlikely((error= write_bin_log(thd, TRUE, thd->query(),
|
||||
thd->query_length()))))
|
||||
{
|
||||
/*
|
||||
The error is reported in write_bin_log().
|
||||
@ -651,7 +662,7 @@ err:
|
||||
part_table_mdl_ticket->downgrade_lock(MDL_SHARED_NO_READ_WRITE);
|
||||
}
|
||||
|
||||
if (!error)
|
||||
if (unlikely(!error))
|
||||
my_ok(thd);
|
||||
|
||||
// For query cache
|
||||
@ -823,7 +834,8 @@ bool Sql_cmd_alter_table_truncate_partition::execute(THD *thd)
|
||||
|
||||
partition= (ha_partition*) first_table->table->file;
|
||||
/* Invoke the handler method responsible for truncating the partition. */
|
||||
if ((error= partition->truncate_partition(alter_info, &binlog_stmt)))
|
||||
if (unlikely(error= partition->truncate_partition(alter_info,
|
||||
&binlog_stmt)))
|
||||
partition->print_error(error, MYF(0));
|
||||
|
||||
/*
|
||||
@ -836,7 +848,7 @@ bool Sql_cmd_alter_table_truncate_partition::execute(THD *thd)
|
||||
Since we've changed data within the table, we also have to invalidate
|
||||
the query cache for it.
|
||||
*/
|
||||
if (error != HA_ERR_WRONG_COMMAND)
|
||||
if (likely(error != HA_ERR_WRONG_COMMAND))
|
||||
{
|
||||
query_cache_invalidate3(thd, first_table, FALSE);
|
||||
if (binlog_stmt)
|
||||
@ -851,7 +863,7 @@ bool Sql_cmd_alter_table_truncate_partition::execute(THD *thd)
|
||||
if (thd->locked_tables_mode)
|
||||
ticket->downgrade_lock(MDL_SHARED_NO_READ_WRITE);
|
||||
|
||||
if (! error)
|
||||
if (likely(!error))
|
||||
my_ok(thd);
|
||||
|
||||
// Invalidate query cache
|
||||
|
Reference in New Issue
Block a user