diff options
Diffstat (limited to 'sql/sql_parse.cc')
-rw-r--r-- | sql/sql_parse.cc | 239 |
1 files changed, 118 insertions, 121 deletions
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 09ef7a587ba..cdc85e1de8a 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -420,7 +420,7 @@ static bool some_non_temp_table_to_be_updated(THD *thd, TABLE_LIST *tables) /* - Implicitly commit a active transaction if statement requires so. + Check whether the statement implicitly commits an active transaction. @param thd Thread handle. @param mask Bitmask used for the SQL command match. @@ -428,7 +428,7 @@ static bool some_non_temp_table_to_be_updated(THD *thd, TABLE_LIST *tables) @return 0 No implicit commit @return 1 Do a commit */ -static bool stmt_causes_implicit_commit(THD *thd, uint mask) +bool stmt_causes_implicit_commit(THD *thd, uint mask) { LEX *lex= thd->lex; bool skip= FALSE; @@ -952,7 +952,7 @@ static char *fgets_fn(char *buffer, size_t size, fgets_input_t input, int *error { MYSQL_FILE *in= static_cast<MYSQL_FILE*> (input); char *line= mysql_file_fgets(buffer, (int)size, in); - if (error) + if (unlikely(error)) *error= (line == NULL) ? ferror(in->m_file) : 0; return line; } @@ -1066,7 +1066,7 @@ static void handle_bootstrap_impl(THD *thd) #endif delete_explain_query(thd->lex); - if (bootstrap_error) + if (unlikely(bootstrap_error)) break; thd->reset_kill_query(); /* Ensure that killed_errmsg is released */ @@ -1214,13 +1214,13 @@ bool do_command(THD *thd) #ifdef WITH_WSREP if (WSREP(thd)) { - mysql_mutex_lock(&thd->LOCK_wsrep_thd); + mysql_mutex_lock(&thd->LOCK_thd_data); thd->wsrep_query_state= QUERY_IDLE; if (thd->wsrep_conflict_state==MUST_ABORT) { wsrep_client_rollback(thd); } - mysql_mutex_unlock(&thd->LOCK_wsrep_thd); + mysql_mutex_unlock(&thd->LOCK_thd_data); } #endif /* WITH_WSREP */ @@ -1266,15 +1266,15 @@ bool do_command(THD *thd) packet_length= my_net_read_packet(net, 1); #ifdef WITH_WSREP if (WSREP(thd)) { - mysql_mutex_lock(&thd->LOCK_wsrep_thd); + mysql_mutex_lock(&thd->LOCK_thd_data); /* these THD's are aborted or are aborting during being idle */ if (thd->wsrep_conflict_state == ABORTING) { while (thd->wsrep_conflict_state == ABORTING) { - mysql_mutex_unlock(&thd->LOCK_wsrep_thd); + mysql_mutex_unlock(&thd->LOCK_thd_data); my_sleep(1000); - mysql_mutex_lock(&thd->LOCK_wsrep_thd); + mysql_mutex_lock(&thd->LOCK_thd_data); } thd->store_globals(); } @@ -1284,11 +1284,11 @@ bool do_command(THD *thd) } thd->wsrep_query_state= QUERY_EXEC; - mysql_mutex_unlock(&thd->LOCK_wsrep_thd); + mysql_mutex_unlock(&thd->LOCK_thd_data); } #endif /* WITH_WSREP */ - if (packet_length == packet_error) + if (unlikely(packet_length == packet_error)) { DBUG_PRINT("info",("Got error %d reading command from socket %s", net->error, @@ -1297,14 +1297,14 @@ bool do_command(THD *thd) #ifdef WITH_WSREP if (WSREP(thd)) { - mysql_mutex_lock(&thd->LOCK_wsrep_thd); + mysql_mutex_lock(&thd->LOCK_thd_data); if (thd->wsrep_conflict_state == MUST_ABORT) { DBUG_PRINT("wsrep",("aborted for wsrep rollback: %lu", (ulong) thd->real_id)); wsrep_client_rollback(thd); } - mysql_mutex_unlock(&thd->LOCK_wsrep_thd); + mysql_mutex_unlock(&thd->LOCK_thd_data); } #endif /* WITH_WSREP */ @@ -1582,7 +1582,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, thd->wsrep_PA_safe= true; } - mysql_mutex_lock(&thd->LOCK_wsrep_thd); + mysql_mutex_lock(&thd->LOCK_thd_data); thd->wsrep_query_state= QUERY_EXEC; if (thd->wsrep_conflict_state== RETRY_AUTOCOMMIT) { @@ -1599,14 +1599,14 @@ bool dispatch_command(enum enum_server_command command, THD *thd, my_message(ER_LOCK_DEADLOCK, "Deadlock: wsrep aborted transaction", MYF(0)); WSREP_DEBUG("Deadlock error for: %s", thd->query()); - mysql_mutex_unlock(&thd->LOCK_wsrep_thd); + mysql_mutex_unlock(&thd->LOCK_thd_data); thd->reset_killed(); thd->mysys_var->abort = 0; thd->wsrep_conflict_state = NO_CONFLICT; thd->wsrep_retry_counter = 0; goto dispatch_end; } - mysql_mutex_unlock(&thd->LOCK_wsrep_thd); + mysql_mutex_unlock(&thd->LOCK_thd_data); } #endif /* WITH_WSREP */ #if defined(ENABLED_PROFILING) @@ -1686,8 +1686,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd, { LEX_CSTRING tmp; status_var_increment(thd->status_var.com_stat[SQLCOM_CHANGE_DB]); - if (thd->copy_with_error(system_charset_info, (LEX_STRING*) &tmp, - thd->charset(), packet, packet_length)) + if (unlikely(thd->copy_with_error(system_charset_info, (LEX_STRING*) &tmp, + thd->charset(), packet, packet_length))) break; if (!mysql_change_db(thd, &tmp, FALSE)) { @@ -1819,7 +1819,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, thd->m_digest= & thd->m_digest_state; thd->m_digest->reset(thd->m_token_array, max_digest_length); - if (alloc_query(thd, packet, packet_length)) + if (unlikely(alloc_query(thd, packet, packet_length))) break; // fatal error is set MYSQL_QUERY_START(thd->query(), thd->thread_id, thd->get_db(), @@ -1835,7 +1835,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, thd->query_length()); Parser_state parser_state; - if (parser_state.init(thd, thd->query(), thd->query_length())) + if (unlikely(parser_state.init(thd, thd->query(), thd->query_length()))) break; if (WSREP_ON) @@ -2378,10 +2378,10 @@ com_multi_end: DBUG_ASSERT((command != COM_QUIT && command != COM_STMT_CLOSE) || thd->get_stmt_da()->is_disabled()); /* wsrep BF abort in query exec phase */ - mysql_mutex_lock(&thd->LOCK_wsrep_thd); + mysql_mutex_lock(&thd->LOCK_thd_data); do_end_of_statement= thd->wsrep_conflict_state != REPLAYING && thd->wsrep_conflict_state != RETRY_AUTOCOMMIT; - mysql_mutex_unlock(&thd->LOCK_wsrep_thd); + mysql_mutex_unlock(&thd->LOCK_thd_data); } else do_end_of_statement= true; @@ -2406,7 +2406,7 @@ com_multi_end: if (drop_more_results) thd->server_status&= ~SERVER_MORE_RESULTS_EXISTS; - if (!thd->is_error() && !thd->killed_errno()) + if (likely(!thd->is_error() && !thd->killed_errno())) mysql_audit_general(thd, MYSQL_AUDIT_GENERAL_RESULT, 0, 0); mysql_audit_general(thd, MYSQL_AUDIT_GENERAL_STATUS, @@ -3933,7 +3933,7 @@ mysql_execute_command(THD *thd) { /* New replication created */ mi= new Master_info(&lex_mi->connection_name, relay_log_recovery); - if (!mi || mi->error()) + if (unlikely(!mi || mi->error())) { delete mi; res= 1; @@ -4043,7 +4043,7 @@ mysql_execute_command(THD *thd) copy. */ Alter_info alter_info(lex->alter_info, thd->mem_root); - if (thd->is_fatal_error) + if (unlikely(thd->is_fatal_error)) { /* If out of memory when creating a copy of alter_info. */ res= 1; @@ -4185,7 +4185,7 @@ mysql_execute_command(THD *thd) thd->lex->create_info.options|= create_info.options; res= open_and_lock_tables(thd, create_info, lex->query_tables, TRUE, 0); thd->lex->create_info.options= save_thd_create_info_options; - if (res) + if (unlikely(res)) { /* Got error or warning. Set res to 1 if error */ if (!(res= thd->is_error())) @@ -4197,9 +4197,9 @@ mysql_execute_command(THD *thd) if (create_info.or_replace() && !create_info.tmp_table()) { TABLE_LIST *duplicate; - if ((duplicate= unique_table(thd, lex->query_tables, - lex->query_tables->next_global, - 0))) + if (unlikely((duplicate= unique_table(thd, lex->query_tables, + lex->query_tables->next_global, + CHECK_DUP_FOR_CREATE)))) { update_non_unique_table_error(lex->query_tables, "CREATE", duplicate); @@ -4223,13 +4223,14 @@ mysql_execute_command(THD *thd) needs to be created for every execution of a PS/SP. Note: In wsrep-patch, CTAS is handled like a regular transaction. */ - if ((result= new (thd->mem_root) select_create(thd, create_table, - &create_info, - &alter_info, - select_lex->item_list, - lex->duplicates, - lex->ignore, - select_tables))) + if (unlikely((result= new (thd->mem_root) + select_create(thd, create_table, + &create_info, + &alter_info, + select_lex->item_list, + lex->duplicates, + lex->ignore, + select_tables)))) { /* CREATE from SELECT give its SELECT_LEX for SELECT, @@ -4310,7 +4311,7 @@ end_with_restore_list: HA_CREATE_INFO create_info; Alter_info alter_info(lex->alter_info, thd->mem_root); - if (thd->is_fatal_error) /* out of memory creating a copy of alter_info */ + if (unlikely(thd->is_fatal_error)) /* out of memory creating alter_info */ goto error; DBUG_ASSERT(first_table == all_tables && first_table != 0); @@ -4347,8 +4348,8 @@ end_with_restore_list: We don't need to ensure that only one user is using master_info as start_slave is protected against simultaneous usage */ - if ((mi= get_master_info(&lex_mi->connection_name, - Sql_condition::WARN_LEVEL_ERROR))) + if (unlikely((mi= get_master_info(&lex_mi->connection_name, + Sql_condition::WARN_LEVEL_ERROR)))) { if (load_error) { @@ -4891,7 +4892,7 @@ end_with_restore_list: unit->set_limit(select_lex); MYSQL_DELETE_START(thd->query()); - Protocol *save_protocol; + Protocol * UNINIT_VAR(save_protocol); bool replaced_protocol= false; if (!select_lex->item_list.is_empty()) @@ -4961,17 +4962,17 @@ end_with_restore_list: break; MYSQL_MULTI_DELETE_START(thd->query()); - if ((res= mysql_multi_delete_prepare(thd))) + if (unlikely(res= mysql_multi_delete_prepare(thd))) { MYSQL_MULTI_DELETE_DONE(1, 0); goto error; } - if (!thd->is_fatal_error) + if (likely(!thd->is_fatal_error)) { result= new (thd->mem_root) multi_delete(thd, aux_tables, lex->table_count); - if (result) + if (unlikely(result)) { res= mysql_select(thd, select_lex->get_table_list(), @@ -5132,9 +5133,9 @@ end_with_restore_list: if ((check_table_access(thd, SELECT_ACL, all_tables, FALSE, UINT_MAX, FALSE) || open_and_lock_tables(thd, all_tables, TRUE, 0))) goto error; - if (!(res= sql_set_variables(thd, lex_var_list, true))) + if (likely(!(res= sql_set_variables(thd, lex_var_list, true)))) { - if (!thd->is_error()) + if (likely(!thd->is_error())) my_ok(thd); } else @@ -6226,7 +6227,7 @@ end_with_restore_list: WSREP_TO_ISOLATION_BEGIN(WSREP_MYSQL_DB, NULL, NULL); - if ((error= alter_server(thd, &lex->server_options))) + if (unlikely((error= alter_server(thd, &lex->server_options)))) { DBUG_PRINT("info", ("problem altering server <%s>", lex->server_options.server_name.str)); @@ -6306,6 +6307,10 @@ finish: lex->unit.cleanup(); + /* close/reopen tables that were marked to need reopen under LOCK TABLES */ + if (! thd->lex->requires_prelocking()) + thd->locked_tables_list.reopen_tables(thd, true); + if (! thd->in_sub_stmt) { if (thd->killed != NOT_KILLED) @@ -6319,7 +6324,8 @@ finish: } thd->reset_kill_query(); } - if (thd->is_error() || (thd->variables.option_bits & OPTION_MASTER_SQL_ERROR)) + if (unlikely(thd->is_error()) || + (thd->variables.option_bits & OPTION_MASTER_SQL_ERROR)) { THD_STAGE_INFO(thd, stage_rollback); trans_rollback_stmt(thd); @@ -6467,7 +6473,7 @@ static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables) to prepend EXPLAIN to any query and receive output for it, even if the query itself redirects the output. */ - if (!(result= new (thd->mem_root) select_send(thd))) + if (unlikely(!(result= new (thd->mem_root) select_send(thd)))) return 1; /* purecov: inspected */ thd->send_explain_fields(result, lex->describe, lex->analyze_stmt); @@ -6478,7 +6484,7 @@ static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables) res= mysql_explain_union(thd, &lex->unit, result); /* Print EXPLAIN only if we don't have an error */ - if (!res) + if (likely(!res)) { /* Do like the original select_describe did: remove OFFSET from the @@ -6689,7 +6695,7 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, /* check access may be called twice in a row. Don't change to same stage */ if (thd->proc_info != stage_checking_permissions.m_name) THD_STAGE_INFO(thd, stage_checking_permissions); - if ((!db || !db[0]) && !thd->db.str && !dont_check_global_grants) + if (unlikely((!db || !db[0]) && !thd->db.str && !dont_check_global_grants)) { DBUG_PRINT("error",("No database")); if (!no_errors) @@ -6698,7 +6704,7 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, DBUG_RETURN(TRUE); /* purecov: tested */ } - if ((db != NULL) && (db != any_db)) + if (likely((db != NULL) && (db != any_db))) { /* Check if this is reserved database, like information schema or @@ -6768,8 +6774,8 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, *save_priv|= sctx->master_access; DBUG_RETURN(FALSE); } - if (((want_access & ~sctx->master_access) & ~DB_ACLS) || - (! db && dont_check_global_grants)) + if (unlikely(((want_access & ~sctx->master_access) & ~DB_ACLS) || + (! db && dont_check_global_grants))) { // We can never grant this DBUG_PRINT("error",("No possible access")); if (!no_errors) @@ -6785,7 +6791,7 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, DBUG_RETURN(TRUE); /* purecov: tested */ } - if (db == any_db) + if (unlikely(db == any_db)) { /* Access granted; Allow select on *any* db. @@ -7279,7 +7285,7 @@ bool check_global_access(THD *thd, ulong want_access, bool no_errors) char command[128]; if ((thd->security_ctx->master_access & want_access)) return 0; - if (!no_errors) + if (unlikely(!no_errors)) { get_privilege_desc(command, sizeof(command), want_access); my_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, MYF(0), command); @@ -7526,7 +7532,7 @@ void THD::reset_for_next_command(bool do_clear_error) DBUG_ASSERT(!spcont); /* not for substatements of routines */ DBUG_ASSERT(!in_sub_stmt); - if (do_clear_error) + if (likely(do_clear_error)) clear_error(1); free_list= 0; @@ -7534,8 +7540,9 @@ void THD::reset_for_next_command(bool do_clear_error) We also assign stmt_lex in lex_start(), but during bootstrap this code is executed first. */ - stmt_lex= &main_lex; stmt_lex->current_select_number= 1; - DBUG_PRINT("info", ("Lex %p stmt_lex: %p", lex, stmt_lex)); + DBUG_ASSERT(lex == &main_lex); + main_lex.stmt_lex= &main_lex; main_lex.current_select_number= 1; + DBUG_PRINT("info", ("Lex and stmt_lex: %p", &main_lex)); /* Those two lines below are theoretically unneeded as THD::cleanup_after_query() should take care of this already. @@ -7652,7 +7659,7 @@ mysql_new_select(LEX *lex, bool move_down, SELECT_LEX *select_lex) { if (!(select_lex= new (thd->mem_root) SELECT_LEX())) DBUG_RETURN(1); - select_lex->select_number= ++thd->stmt_lex->current_select_number; + select_lex->select_number= ++thd->lex->stmt_lex->current_select_number; select_lex->parent_lex= lex; /* Used in init_query. */ select_lex->init_query(); select_lex->init_select(); @@ -7803,13 +7810,22 @@ static void wsrep_mysql_parse(THD *thd, char *rawbuf, uint length, com_statement_info[thd->get_command()].m_key); MYSQL_SET_STATEMENT_TEXT(thd->m_statement_psi, thd->query(), thd->query_length()); + + DBUG_EXECUTE_IF("sync.wsrep_retry_autocommit", + { + const char act[]= + "now " + "SIGNAL wsrep_retry_autocommit_reached " + "WAIT_FOR wsrep_retry_autocommit_continue"; + DBUG_ASSERT(!debug_sync_set_action(thd, STRING_WITH_LEN(act))); + }); } mysql_parse(thd, rawbuf, length, parser_state, is_com_multi, is_next_command); if (WSREP(thd)) { /* wsrep BF abort in query exec phase */ - mysql_mutex_lock(&thd->LOCK_wsrep_thd); + mysql_mutex_lock(&thd->LOCK_thd_data); if (thd->wsrep_conflict_state == MUST_ABORT) { wsrep_client_rollback(thd); @@ -7818,8 +7834,11 @@ static void wsrep_mysql_parse(THD *thd, char *rawbuf, uint length, if (thd->wsrep_conflict_state == MUST_REPLAY) { + mysql_mutex_unlock(&thd->LOCK_thd_data); if (thd->lex->explain) delete_explain_query(thd->lex); + mysql_mutex_lock(&thd->LOCK_thd_data); + wsrep_replay_transaction(thd); } @@ -7861,13 +7880,13 @@ static void wsrep_mysql_parse(THD *thd, char *rawbuf, uint length, if (thd->wsrep_conflict_state != REPLAYING) thd->wsrep_retry_counter= 0; // reset } - mysql_mutex_unlock(&thd->LOCK_wsrep_thd); + mysql_mutex_unlock(&thd->LOCK_thd_data); thd->reset_killed(); } else { set_if_smaller(thd->wsrep_retry_counter, 0); // reset; eventually ok - mysql_mutex_unlock(&thd->LOCK_wsrep_thd); + mysql_mutex_unlock(&thd->LOCK_thd_data); } } @@ -7953,7 +7972,7 @@ void mysql_parse(THD *thd, char *rawbuf, uint length, bool err= parse_sql(thd, parser_state, NULL, true); - if (!err) + if (likely(!err)) { thd->m_statement_psi= MYSQL_REFINE_STATEMENT(thd->m_statement_psi, @@ -7968,7 +7987,7 @@ void mysql_parse(THD *thd, char *rawbuf, uint length, else #endif { - if (! thd->is_error()) + if (likely(! thd->is_error())) { const char *found_semicolon= parser_state->m_lip.found_semicolon; /* @@ -8062,7 +8081,7 @@ bool mysql_test_parse_for_slave(THD *thd, char *rawbuf, uint length) DBUG_ENTER("mysql_test_parse_for_slave"); Parser_state parser_state; - if (!(error= parser_state.init(thd, rawbuf, length))) + if (likely(!(error= parser_state.init(thd, rawbuf, length)))) { lex_start(thd); thd->reset_for_next_command(); @@ -8084,7 +8103,7 @@ add_proc_to_list(THD* thd, Item *item) ORDER *order; Item **item_ptr; - if (!(order = (ORDER *) thd->alloc(sizeof(ORDER)+sizeof(Item*)))) + if (unlikely(!(order = (ORDER *) thd->alloc(sizeof(ORDER)+sizeof(Item*))))) return 1; item_ptr = (Item**) (order+1); *item_ptr= item; @@ -8102,7 +8121,7 @@ bool add_to_list(THD *thd, SQL_I_List<ORDER> &list, Item *item,bool asc) { ORDER *order; DBUG_ENTER("add_to_list"); - if (!(order = (ORDER *) thd->alloc(sizeof(ORDER)))) + if (unlikely(!(order = (ORDER *) thd->alloc(sizeof(ORDER))))) DBUG_RETURN(1); order->item_ptr= item; order->item= &order->item_ptr; @@ -8145,25 +8164,25 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, List<String> *partition_names, LEX_STRING *option) { - register TABLE_LIST *ptr; + TABLE_LIST *ptr; TABLE_LIST *UNINIT_VAR(previous_table_ref); /* The table preceding the current one. */ LEX_CSTRING alias_str; LEX *lex= thd->lex; DBUG_ENTER("add_table_to_list"); - if (!table) + if (unlikely(!table)) DBUG_RETURN(0); // End of memory alias_str= alias ? *alias : table->table; DBUG_ASSERT(alias_str.str); if (!MY_TEST(table_options & TL_OPTION_ALIAS) && - check_table_name(table->table.str, table->table.length, FALSE)) + unlikely(check_table_name(table->table.str, table->table.length, FALSE))) { my_error(ER_WRONG_TABLE_NAME, MYF(0), table->table.str); DBUG_RETURN(0); } - if (table->is_derived_table() == FALSE && table->db.str && - check_db_name((LEX_STRING*) &table->db)) + if (unlikely(table->is_derived_table() == FALSE && table->db.str && + check_db_name((LEX_STRING*) &table->db))) { my_error(ER_WRONG_DB_NAME, MYF(0), table->db.str); DBUG_RETURN(0); @@ -8171,17 +8190,17 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, if (!alias) /* Alias is case sensitive */ { - if (table->sel) + if (unlikely(table->sel)) { my_message(ER_DERIVED_MUST_HAVE_ALIAS, ER_THD(thd, ER_DERIVED_MUST_HAVE_ALIAS), MYF(0)); DBUG_RETURN(0); } /* alias_str points to table->table; Let's make a copy */ - if (!(alias_str.str= (char*) thd->memdup(alias_str.str, alias_str.length+1))) + if (unlikely(!(alias_str.str= (char*) thd->memdup(alias_str.str, alias_str.length+1)))) DBUG_RETURN(0); } - if (!(ptr = (TABLE_LIST *) thd->calloc(sizeof(TABLE_LIST)))) + if (unlikely(!(ptr = (TABLE_LIST *) thd->calloc(sizeof(TABLE_LIST))))) DBUG_RETURN(0); /* purecov: inspected */ if (table->db.str) { @@ -8227,7 +8246,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, DBUG_RETURN(0); } schema_table= find_schema_table(thd, &ptr->table_name); - if (!schema_table || + if (unlikely(!schema_table) || (schema_table->hidden && ((sql_command_flags[lex->sql_command] & CF_STATUS_COMMAND) == 0 || /* @@ -8261,8 +8280,9 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, tables ; tables=tables->next_local) { - if (!my_strcasecmp(table_alias_charset, alias_str.str, tables->alias.str) && - !cmp(&ptr->db, &tables->db) && ! tables->sequence) + if (unlikely(!my_strcasecmp(table_alias_charset, alias_str.str, + tables->alias.str) && + !cmp(&ptr->db, &tables->db) && ! tables->sequence)) { my_error(ER_NONUNIQ_TABLE, MYF(0), alias_str.str); /* purecov: tested */ DBUG_RETURN(0); /* purecov: tested */ @@ -8270,7 +8290,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, } } /* Store the table reference preceding the current one. */ - if (table_list.elements > 0 && !ptr->sequence) + if (table_list.elements > 0 && likely(!ptr->sequence)) { /* table_list.next points to the last inserted TABLE_LIST->next_local' @@ -8298,7 +8318,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, We don't store sequences into the local list to hide them from INSERT and SELECT. */ - if (!ptr->sequence) + if (likely(!ptr->sequence)) table_list.link_in_list(ptr, &ptr->next_local); ptr->next_name_resolution_table= NULL; #ifdef WITH_PARTITION_STORAGE_ENGINE @@ -8343,13 +8363,14 @@ bool st_select_lex::init_nested_join(THD *thd) NESTED_JOIN *nested_join; DBUG_ENTER("init_nested_join"); - if (!(ptr= (TABLE_LIST*) thd->calloc(ALIGN_SIZE(sizeof(TABLE_LIST))+ - sizeof(NESTED_JOIN)))) + if (unlikely(!(ptr= (TABLE_LIST*) thd->calloc(ALIGN_SIZE(sizeof(TABLE_LIST))+ + sizeof(NESTED_JOIN))))) DBUG_RETURN(1); nested_join= ptr->nested_join= ((NESTED_JOIN*) ((uchar*) ptr + ALIGN_SIZE(sizeof(TABLE_LIST)))); - join_list->push_front(ptr, thd->mem_root); + if (unlikely(join_list->push_front(ptr, thd->mem_root))) + DBUG_RETURN(1); ptr->embedding= embedding; ptr->join_list= join_list; ptr->alias.str="(nested_join)"; @@ -8425,8 +8446,8 @@ TABLE_LIST *st_select_lex::nest_last_join(THD *thd) List<TABLE_LIST> *embedded_list; DBUG_ENTER("nest_last_join"); - if (!(ptr= (TABLE_LIST*) thd->calloc(ALIGN_SIZE(sizeof(TABLE_LIST))+ - sizeof(NESTED_JOIN)))) + if (unlikely(!(ptr= (TABLE_LIST*) thd->calloc(ALIGN_SIZE(sizeof(TABLE_LIST))+ + sizeof(NESTED_JOIN))))) DBUG_RETURN(0); nested_join= ptr->nested_join= ((NESTED_JOIN*) ((uchar*) ptr + ALIGN_SIZE(sizeof(TABLE_LIST)))); @@ -8441,7 +8462,7 @@ TABLE_LIST *st_select_lex::nest_last_join(THD *thd) for (uint i=0; i < 2; i++) { TABLE_LIST *table= join_list->pop(); - if (!table) + if (unlikely(!table)) DBUG_RETURN(NULL); table->join_list= embedded_list; table->embedding= ptr; @@ -8894,7 +8915,7 @@ kill_one_thread(THD *thd, longlong id, killed_state kill_signal, killed_type typ if (((thd->security_ctx->master_access & SUPER_ACL) || thd->security_ctx->user_matches(tmp->security_ctx)) && - !wsrep_thd_is_BF(tmp, true)) + !wsrep_thd_is_BF(tmp, false)) { tmp->awake_no_mutex(kill_signal); error=0; @@ -8932,7 +8953,7 @@ static uint kill_threads_for_user(THD *thd, LEX_USER *user, *rows= 0; - if (thd->is_fatal_error) // If we run out of memory + if (unlikely(thd->is_fatal_error)) // If we run out of memory DBUG_RETURN(ER_OUT_OF_RESOURCES); DBUG_PRINT("enter", ("user: %s signal: %u", user->user.str, @@ -9002,7 +9023,7 @@ static void sql_kill(THD *thd, longlong id, killed_state state, killed_type type) { uint error; - if (!(error= kill_one_thread(thd, id, state, type))) + if (likely(!(error= kill_one_thread(thd, id, state, type)))) { if (!thd->killed) my_ok(thd); @@ -9019,7 +9040,7 @@ void sql_kill_user(THD *thd, LEX_USER *user, killed_state state) { uint error; ha_rows rows; - if (!(error= kill_threads_for_user(thd, user, state, &rows))) + if (likely(!(error= kill_threads_for_user(thd, user, state, &rows)))) my_ok(thd, rows); else { @@ -9051,7 +9072,8 @@ bool append_file_to_dir(THD *thd, const char **filename_ptr, /* Fix is using unix filename format on dos */ strmov(buff,*filename_ptr); end=convert_dirname(buff, *filename_ptr, NullS); - if (!(ptr= (char*) thd->alloc((size_t) (end-buff) + table_name->length + 1))) + if (unlikely(!(ptr= (char*) thd->alloc((size_t) (end-buff) + + table_name->length + 1)))) return 1; // End of memory *filename_ptr=ptr; strxmov(ptr,buff,table_name->str,NullS); @@ -9059,32 +9081,6 @@ bool append_file_to_dir(THD *thd, const char **filename_ptr, } -/** - Check if the select is a simple select (not an union). - - @retval - 0 ok - @retval - 1 error ; In this case the error messege is sent to the client -*/ - -bool check_simple_select() -{ - THD *thd= current_thd; - LEX *lex= thd->lex; - if (lex->current_select != &lex->select_lex) - { - char command[80]; - Lex_input_stream *lip= & thd->m_parser_state->m_lip; - strmake(command, lip->yylval->symbol.str, - MY_MIN(lip->yylval->symbol.length, sizeof(command)-1)); - my_error(ER_CANT_USE_OPTION_HERE, MYF(0), command); - return 1; - } - return 0; -} - - Comp_creator *comp_eq_creator(bool invert) { return invert?(Comp_creator *)&ne_creator:(Comp_creator *)&eq_creator; @@ -9424,7 +9420,7 @@ bool update_precheck(THD *thd, TABLE_LIST *tables) bool delete_precheck(THD *thd, TABLE_LIST *tables) { DBUG_ENTER("delete_precheck"); - if (tables->vers_conditions) + if (tables->vers_conditions.is_set()) { if (check_one_table_access(thd, DELETE_HISTORY_ACL, tables)) DBUG_RETURN(TRUE); @@ -9724,7 +9720,7 @@ LEX_USER *create_default_definer(THD *thd, bool role) { LEX_USER *definer; - if (! (definer= (LEX_USER*) thd->alloc(sizeof(LEX_USER)))) + if (unlikely(! (definer= (LEX_USER*) thd->alloc(sizeof(LEX_USER))))) return 0; thd->get_definer(definer, role); @@ -9759,7 +9755,7 @@ LEX_USER *create_definer(THD *thd, LEX_CSTRING *user_name, /* Create and initialize. */ - if (! (definer= (LEX_USER*) thd->alloc(sizeof(LEX_USER)))) + if (unlikely(!(definer= (LEX_USER*) thd->alloc(sizeof(LEX_USER))))) return 0; definer->user= *user_name; @@ -9822,7 +9818,8 @@ bool check_string_char_length(const LEX_CSTRING *str, uint err_msg, bool no_error) { Well_formed_prefix prefix(cs, str->str, str->length, max_char_length); - if (!prefix.well_formed_error_pos() && str->length == prefix.length()) + if (likely(!prefix.well_formed_error_pos() && + str->length == prefix.length())) return FALSE; if (!no_error) |