diff options
Diffstat (limited to 'sql/sql_class.cc')
-rw-r--r-- | sql/sql_class.cc | 133 |
1 files changed, 102 insertions, 31 deletions
diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 185b43dd807..9d30ad65be4 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -28,7 +28,7 @@ #pragma implementation // gcc: Class implementation #endif -#include <my_global.h> /* NO_EMBEDDED_ACCESS_CHECKS */ +#include "mariadb.h" #include "sql_priv.h" #include "sql_class.h" #include "sql_cache.h" // query_cache_abort @@ -121,8 +121,8 @@ extern "C" void free_sequence_last(SEQUENCE_LAST_VALUE *entry) bool Key_part_spec::operator==(const Key_part_spec& other) const { return length == other.length && - !my_strcasecmp(system_charset_info, field_name.str, - other.field_name.str); + !lex_string_cmp(system_charset_info, &field_name, + &other.field_name); } /** @@ -249,9 +249,9 @@ bool Foreign_key::validate(List<Create_field> &table_fields) { it.rewind(); while ((sql_field= it++) && - my_strcasecmp(system_charset_info, - column->field_name.str, - sql_field->field_name.str)) {} + lex_string_cmp(system_charset_info, + &column->field_name, + &sql_field->field_name)) {} if (!sql_field) { my_error(ER_KEY_COLUMN_DOES_NOT_EXITS, MYF(0), column->field_name.str); @@ -834,7 +834,7 @@ THD::THD(my_thread_id id, bool is_wsrep_applier) enable_slow_log= 0; durability_property= HA_REGULAR_DURABILITY; -#ifndef DBUG_OFF +#ifdef DBUG_ASSERT_EXISTS dbug_sentry=THD_SENTRY_MAGIC; #endif mysql_audit_init_thd(this); @@ -1646,7 +1646,7 @@ THD::~THD() mysql_mutex_destroy(&LOCK_wakeup_ready); mysql_mutex_destroy(&LOCK_thd_data); mysql_mutex_destroy(&LOCK_thd_kill); -#ifndef DBUG_OFF +#ifdef DBUG_ASSERT_EXISTS dbug_sentry= THD_SENTRY_GONE; #endif #ifndef EMBEDDED_LIBRARY @@ -1727,6 +1727,9 @@ void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var) to_var->binlog_bytes_written+= from_var->binlog_bytes_written; to_var->cpu_time+= from_var->cpu_time; to_var->busy_time+= from_var->busy_time; + to_var->table_open_cache_hits+= from_var->table_open_cache_hits; + to_var->table_open_cache_misses+= from_var->table_open_cache_misses; + to_var->table_open_cache_overflows+= from_var->table_open_cache_overflows; /* Update global_memory_used. We have to do this with atomic_add as the @@ -1778,6 +1781,12 @@ void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var, dec_var->binlog_bytes_written; to_var->cpu_time+= from_var->cpu_time - dec_var->cpu_time; to_var->busy_time+= from_var->busy_time - dec_var->busy_time; + to_var->table_open_cache_hits+= from_var->table_open_cache_hits - + dec_var->table_open_cache_hits; + to_var->table_open_cache_misses+= from_var->table_open_cache_misses - + dec_var->table_open_cache_misses; + to_var->table_open_cache_overflows+= from_var->table_open_cache_overflows - + dec_var->table_open_cache_overflows; /* We don't need to accumulate memory_used as these are not reset or used by @@ -2063,6 +2072,23 @@ int THD::killed_errno() } +void THD::reset_killed() +{ + /* + Resetting killed has to be done under a mutex to ensure + its not done during an awake() call. + */ + DBUG_ENTER("reset_killed"); + if (killed != NOT_KILLED) + { + mysql_mutex_lock(&LOCK_thd_kill); + killed= NOT_KILLED; + killed_err= 0; + mysql_mutex_unlock(&LOCK_thd_kill); + } + DBUG_VOID_RETURN; +} + /* Remember the location of thread info, the structure needed for the structure for the net buffer @@ -3766,7 +3792,7 @@ void THD::set_n_backup_active_arena(Query_arena *set, Query_arena *backup) backup->set_query_arena(this); set_query_arena(set); -#ifndef DBUG_OFF +#ifdef DBUG_ASSERT_EXISTS backup->is_backup_arena= TRUE; #endif DBUG_VOID_RETURN; @@ -3785,7 +3811,7 @@ void THD::restore_active_arena(Query_arena *set, Query_arena *backup) DBUG_ASSERT(backup->is_backup_arena); set->set_query_arena(this); set_query_arena(backup); -#ifndef DBUG_OFF +#ifdef DBUG_ASSERT_EXISTS backup->is_backup_arena= FALSE; #endif DBUG_VOID_RETURN; @@ -4679,7 +4705,6 @@ void destroy_thd(MYSQL_THD thd) thd->add_status_to_global(); unlink_not_visible_thd(thd); delete thd; - dec_thread_running(); } void reset_thd(MYSQL_THD thd) @@ -4746,13 +4771,6 @@ extern "C" int thd_slave_thread(const MYSQL_THD thd) return(thd->slave_thread); } -/* Returns true for a worker thread in parallel replication. */ -extern "C" int thd_rpl_is_parallel(const MYSQL_THD thd) -{ - return thd->rgi_slave && thd->rgi_slave->is_parallel_exec; -} - - /* Returns high resolution timestamp for the start of the current query. */ extern "C" unsigned long long thd_start_utime(const MYSQL_THD thd) @@ -4790,7 +4808,7 @@ thd_need_wait_reports(const MYSQL_THD thd) } /* - Used by storage engines (currently TokuDB and InnoDB/XtraDB) to report that + Used by storage engines (currently TokuDB and InnoDB) to report that one transaction THD is about to go to wait for a transactional lock held by another transactions OTHER_THD. @@ -4812,7 +4830,7 @@ thd_need_wait_reports(const MYSQL_THD thd) transaction, and later re-try it, to resolve the deadlock. This call need only receive reports about waits for locks that will remain - until the holding transaction commits. InnoDB/XtraDB auto-increment locks, + until the holding transaction commits. InnoDB auto-increment locks, for example, are released earlier, and so need not be reported. (Such false positives are not harmful, but could lead to unnecessary kill and retry, so best avoided). @@ -4865,7 +4883,7 @@ thd_rpl_deadlock_check(MYSQL_THD thd, MYSQL_THD other_thd) } /* - This function is called from InnoDB/XtraDB to check if the commit order of + This function is called from InnoDB to check if the commit order of two transactions has already been decided by the upper layer. This happens in parallel replication, where the commit order is forced to be the same on the slave as it was originally on the master. @@ -4895,7 +4913,7 @@ thd_rpl_deadlock_check(MYSQL_THD thd, MYSQL_THD other_thd) If this function returns true, normal locking should be done as required by the binlogging and transaction isolation level in effect. But if it returns - false, the correct order will be enforced anyway, and InnoDB/XtraDB can + false, the correct order will be enforced anyway, and InnoDB can avoid taking the gap lock, preventing the lock conflict. Calling this function is just an optimisation to avoid unnecessary @@ -5174,10 +5192,7 @@ void THD::reset_sub_statement_state(Sub_statement_state *backup, backup->count_cuted_fields= count_cuted_fields; backup->in_sub_stmt= in_sub_stmt; backup->enable_slow_log= enable_slow_log; - backup->query_plan_flags= query_plan_flags; backup->limit_found_rows= limit_found_rows; - backup->examined_row_count= m_examined_row_count; - backup->sent_row_count= m_sent_row_count; backup->cuted_fields= cuted_fields; backup->client_capabilities= client_capabilities; backup->savepoints= transaction.savepoints; @@ -5185,6 +5200,7 @@ void THD::reset_sub_statement_state(Sub_statement_state *backup, first_successful_insert_id_in_prev_stmt; backup->first_successful_insert_id_in_cur_stmt= first_successful_insert_id_in_cur_stmt; + store_slow_query_state(backup); if ((!lex->requires_prelocking() || is_update_query(lex->sql_command)) && !is_current_stmt_binlog_format_row()) @@ -5200,14 +5216,12 @@ void THD::reset_sub_statement_state(Sub_statement_state *backup, /* Disable result sets */ client_capabilities &= ~CLIENT_MULTI_RESULTS; in_sub_stmt|= new_state; - m_examined_row_count= 0; - m_sent_row_count= 0; cuted_fields= 0; transaction.savepoints= 0; first_successful_insert_id_in_cur_stmt= 0; + reset_slow_query_state(); } - void THD::restore_sub_statement_state(Sub_statement_state *backup) { DBUG_ENTER("THD::restore_sub_statement_state"); @@ -5242,7 +5256,6 @@ void THD::restore_sub_statement_state(Sub_statement_state *backup) variables.option_bits= backup->option_bits; in_sub_stmt= backup->in_sub_stmt; enable_slow_log= backup->enable_slow_log; - query_plan_flags= backup->query_plan_flags; first_successful_insert_id_in_prev_stmt= backup->first_successful_insert_id_in_prev_stmt; first_successful_insert_id_in_cur_stmt= @@ -5250,6 +5263,10 @@ void THD::restore_sub_statement_state(Sub_statement_state *backup) limit_found_rows= backup->limit_found_rows; set_sent_row_count(backup->sent_row_count); client_capabilities= backup->client_capabilities; + + /* Restore statistic needed for slow log */ + add_slow_query_state(backup); + /* If we've left sub-statement mode, reset the fatal error flag. Otherwise keep the current value, to propagate it up the sub-statement @@ -5274,6 +5291,56 @@ void THD::restore_sub_statement_state(Sub_statement_state *backup) DBUG_VOID_RETURN; } +/* + Store slow query state at start of a stored procedure statment +*/ + +void THD::store_slow_query_state(Sub_statement_state *backup) +{ + backup->affected_rows= affected_rows; + backup->bytes_sent_old= bytes_sent_old; + backup->examined_row_count= m_examined_row_count; + backup->query_plan_flags= query_plan_flags; + backup->query_plan_fsort_passes= query_plan_fsort_passes; + backup->sent_row_count= m_sent_row_count; + backup->tmp_tables_disk_used= tmp_tables_disk_used; + backup->tmp_tables_size= tmp_tables_size; + backup->tmp_tables_used= tmp_tables_used; +} + +/* Reset variables related to slow query log */ + +void THD::reset_slow_query_state() +{ + affected_rows= 0; + bytes_sent_old= status_var.bytes_sent; + m_examined_row_count= 0; + m_sent_row_count= 0; + query_plan_flags= QPLAN_INIT; + query_plan_fsort_passes= 0; + tmp_tables_disk_used= 0; + tmp_tables_size= 0; + tmp_tables_used= 0; +} + +/* + Add back the stored values to the current counters to be able to get + right status for 'call procedure_name' +*/ + +void THD::add_slow_query_state(Sub_statement_state *backup) +{ + affected_rows+= backup->affected_rows; + bytes_sent_old= backup->bytes_sent_old; + m_examined_row_count+= backup->examined_row_count; + m_sent_row_count+= backup->sent_row_count; + query_plan_flags|= backup->query_plan_flags; + query_plan_fsort_passes+= backup->query_plan_fsort_passes; + tmp_tables_disk_used+= backup->tmp_tables_disk_used; + tmp_tables_size+= backup->tmp_tables_size; + tmp_tables_used+= backup->tmp_tables_used; +} + void THD::set_statement(Statement *stmt) { @@ -5308,6 +5375,8 @@ void THD::inc_examined_row_count(ha_rows count) void THD::inc_status_created_tmp_disk_tables() { + tmp_tables_disk_used++; + query_plan_flags|= QPLAN_TMP_DISK; status_var_increment(status_var.created_tmp_disk_tables_); #ifdef HAVE_PSI_STATEMENT_INTERFACE PSI_STATEMENT_CALL(inc_statement_created_tmp_disk_tables)(m_statement_psi, 1); @@ -5316,6 +5385,8 @@ void THD::inc_status_created_tmp_disk_tables() void THD::inc_status_created_tmp_tables() { + tmp_tables_used++; + query_plan_flags|= QPLAN_TMP_TABLE; status_var_increment(status_var.created_tmp_tables_); #ifdef HAVE_PSI_STATEMENT_INTERFACE PSI_STATEMENT_CALL(inc_statement_created_tmp_tables)(m_statement_psi, 1); @@ -5972,7 +6043,7 @@ int THD::decide_logging_format(TABLE_LIST *tables) DBUG_PRINT("info", ("table: %s; ha_table_flags: 0x%llx", table->table_name, flags)); - if (table->table->no_replicate) + if (table->table->s->no_replicate) { /* The statement uses a table that is not replicated. @@ -6486,7 +6557,7 @@ CPP_UNNAMED_NS_START { DBUG_ASSERT(s < sizeof(m_ptr)/sizeof(*m_ptr)); DBUG_ASSERT(m_ptr[s] != 0); - DBUG_ASSERT(m_alloc_checked == TRUE); + DBUG_SLOW_ASSERT(m_alloc_checked == TRUE); return m_ptr[s]; } |