diff options
Diffstat (limited to 'sql/sql_parse.cc')
-rw-r--r-- | sql/sql_parse.cc | 71 |
1 files changed, 47 insertions, 24 deletions
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 779db99a4ff..449d57c2b2d 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -140,14 +140,14 @@ static bool end_active_trans(THD *thd) if (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN | OPTION_TABLE_LOCK)) { - DBUG_PRINT("info",("options: 0x%lx", (ulong) thd->options)); + DBUG_PRINT("info",("options: 0x%llx", thd->options)); /* Safety if one did "drop table" on locked tables */ if (!thd->locked_tables) thd->options&= ~OPTION_TABLE_LOCK; thd->server_status&= ~SERVER_STATUS_IN_TRANS; if (ha_commit(thd)) error=1; - thd->options&= ~(ulong) (OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE); + thd->options&= ~(OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE); } DBUG_RETURN(error); } @@ -171,7 +171,7 @@ static bool begin_trans(THD *thd) else { LEX *lex= thd->lex; - thd->options= ((thd->options & (ulong) ~(OPTION_STATUS_NO_TRANS_UPDATE)) | + thd->options= ((thd->options & ~(OPTION_STATUS_NO_TRANS_UPDATE)) | OPTION_BEGIN); thd->server_status|= SERVER_STATUS_IN_TRANS; if (lex->start_transaction_opt & MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT) @@ -1058,7 +1058,7 @@ void execute_init_command(THD *thd, sys_var_str *init_command_var, Vio* save_vio; ulong save_client_capabilities; - THD_PROC_INFO(thd, "Execution of init_command"); + thd_proc_info(thd, "Execution of init_command"); /* We need to lock init_command_var because during execution of init_command_var query @@ -1158,7 +1158,7 @@ pthread_handler_t handle_one_connection(void *arg) net->compress=1; // Use compression thd->version= refresh_version; - THD_PROC_INFO(thd, 0); + thd_proc_info(thd, 0); thd->command= COM_SLEEP; thd->set_time(); thd->init_for_queries(); @@ -1175,7 +1175,7 @@ pthread_handler_t handle_one_connection(void *arg) sctx->host_or_ip, "init_connect command failed"); sql_print_warning("%s", net->last_error); } - THD_PROC_INFO(thd, 0); + thd_proc_info(thd, 0); thd->set_time(); thd->init_for_queries(); } @@ -1258,7 +1258,7 @@ pthread_handler_t handle_bootstrap(void *arg) if (thd->variables.max_join_size == HA_POS_ERROR) thd->options |= OPTION_BIG_SELECTS; - THD_PROC_INFO(thd, 0); + thd_proc_info(thd, 0); thd->version=refresh_version; thd->security_ctx->priv_user= thd->security_ctx->user= (char*) my_strdup("boot", MYF(MY_WME)); @@ -1447,7 +1447,7 @@ int end_trans(THD *thd, enum enum_mysql_completiontype completion) */ thd->server_status&= ~SERVER_STATUS_IN_TRANS; res= ha_commit(thd); - thd->options&= ~(ulong) (OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE); + thd->options&= ~(OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE); break; case COMMIT_RELEASE: do_release= 1; /* fall through */ @@ -1464,7 +1464,7 @@ int end_trans(THD *thd, enum enum_mysql_completiontype completion) thd->server_status&= ~SERVER_STATUS_IN_TRANS; if (ha_rollback(thd)) res= -1; - thd->options&= ~(ulong) (OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE); + thd->options&= ~(OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE); if (!res && (completion == ROLLBACK_AND_CHAIN)) res= begin_trans(thd); break; @@ -2105,7 +2105,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, if (thd->lock || thd->open_tables || thd->derived_tables || thd->prelocked_mode) { - THD_PROC_INFO(thd, "closing tables"); + thd_proc_info(thd, "closing tables"); close_thread_tables(thd); /* Free tables */ } /* @@ -2128,9 +2128,9 @@ bool dispatch_command(enum enum_server_command command, THD *thd, log_slow_statement(thd); - THD_PROC_INFO(thd, "cleaning up"); + thd_proc_info(thd, "cleaning up"); VOID(pthread_mutex_lock(&LOCK_thread_count)); // For process list - THD_PROC_INFO(thd, 0); + thd_proc_info(thd, 0); thd->command=COM_SLEEP; thd->query=0; thd->query_length=0; @@ -2163,6 +2163,8 @@ void log_slow_statement(THD *thd) */ if (thd->enable_slow_log && !thd->user_time) { + thd_proc_info(thd, "logging slow query"); + if ((ulong) (thd->start_time - thd->time_after_lock) > thd->variables.long_query_time || (thd->server_status & @@ -2171,7 +2173,7 @@ void log_slow_statement(THD *thd) /* == SQLCOM_END unless this is a SHOW command */ thd->lex->orig_sql_command == SQLCOM_END) { - THD_PROC_INFO(thd, "logging slow query"); + thd_proc_info(thd, "logging slow query"); thd->status_var.long_query_count++; mysql_slow_log.write(thd, thd->query, thd->query_length, start_of_query); } @@ -2698,16 +2700,33 @@ mysql_execute_command(THD *thd) } case SQLCOM_SHOW_PROFILES: { +#ifdef ENABLED_PROFILING thd->profiling.store(); thd->profiling.discard(); res= thd->profiling.show_profiles(); + if (res) + goto error; +#else + my_error(ER_FEATURE_DISABLED, MYF(0), "query profiling", "enable-profiling"); + goto error; +#endif break; } case SQLCOM_SHOW_PROFILE: { +#ifdef ENABLED_PROFILING thd->profiling.store(); thd->profiling.discard(); // will get re-enabled by reset() - res= thd->profiling.show_last(lex->profile_options); + if (lex->profile_query_id != 0) + res= thd->profiling.show(lex->profile_options, lex->profile_query_id); + else + res= thd->profiling.show_last(lex->profile_options); + if (res) + goto error; +#else + my_error(ER_FEATURE_DISABLED, MYF(0), "query profiling", "enable-profiling"); + goto error; +#endif break; } case SQLCOM_SHOW_NEW_MASTER: @@ -3557,7 +3576,7 @@ end_with_restore_list: if (add_item_to_list(thd, new Item_null())) goto error; - THD_PROC_INFO(thd, "init"); + thd_proc_info(thd, "init"); if ((res= open_and_lock_tables(thd, all_tables))) break; @@ -3721,7 +3740,7 @@ end_with_restore_list: if (thd->options & OPTION_TABLE_LOCK) { end_active_trans(thd); - thd->options&= ~(ulong) (OPTION_TABLE_LOCK); + thd->options&= ~(OPTION_TABLE_LOCK); } if (thd->global_read_lock) unlock_global_read_lock(thd); @@ -3747,7 +3766,7 @@ end_with_restore_list: send_ok(thd); } else - thd->options&= ~(ulong) (OPTION_TABLE_LOCK); + thd->options&= ~(OPTION_TABLE_LOCK); thd->in_lock_tables=0; break; case SQLCOM_CREATE_DB: @@ -4847,7 +4866,7 @@ create_sp_error: thd->transaction.xid_state.xa_state=XA_ACTIVE; thd->transaction.xid_state.xid.set(thd->lex->xid); xid_cache_insert(&thd->transaction.xid_state); - thd->options= ((thd->options & (ulong) ~(OPTION_STATUS_NO_TRANS_UPDATE)) | + thd->options= ((thd->options & ~(OPTION_STATUS_NO_TRANS_UPDATE)) | OPTION_BEGIN); thd->server_status|= SERVER_STATUS_IN_TRANS; send_ok(thd); @@ -4941,7 +4960,7 @@ create_sp_error: xa_state_names[thd->transaction.xid_state.xa_state]); break; } - thd->options&= ~(ulong) (OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE); + thd->options&= ~(OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE); thd->server_status&= ~SERVER_STATUS_IN_TRANS; xid_cache_delete(&thd->transaction.xid_state); thd->transaction.xid_state.xa_state=XA_NOTR; @@ -4971,7 +4990,7 @@ create_sp_error: my_error(ER_XAER_RMERR, MYF(0)); else send_ok(thd); - thd->options&= ~(ulong) (OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE); + thd->options&= ~(OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE); thd->server_status&= ~SERVER_STATUS_IN_TRANS; xid_cache_delete(&thd->transaction.xid_state); thd->transaction.xid_state.xa_state=XA_NOTR; @@ -4986,7 +5005,7 @@ create_sp_error: send_ok(thd); break; } - THD_PROC_INFO(thd, "query end"); + thd_proc_info(thd, "query end"); /* Two binlog-related cleanups: */ /* @@ -5157,8 +5176,7 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, else save_priv= &dummy; - THD_PROC_INFO(thd, "checking permissions"); - + thd_proc_info(thd, "checking permissions"); if ((!db || !db[0]) && !thd->db && !dont_check_global_grants) { DBUG_PRINT("error",("No database")); @@ -5605,6 +5623,9 @@ mysql_init_query(THD *thd, uchar *buf, uint length) DBUG_ENTER("mysql_init_query"); lex_start(thd, buf, length); mysql_reset_thd_for_next_command(thd); +#ifdef ENABLED_PROFILING + thd->profiling.reset(); +#endif DBUG_VOID_RETURN; } @@ -5646,7 +5667,9 @@ void mysql_reset_thd_for_next_command(THD *thd) thd->total_warn_count=0; // Warnings for this query thd->rand_used= 0; thd->sent_row_count= thd->examined_row_count= 0; +#ifdef ENABLED_PROFILING thd->profiling.reset(); +#endif } DBUG_VOID_RETURN; } @@ -5870,7 +5893,7 @@ void mysql_parse(THD *thd, char *inBuf, uint length) query_cache_abort(&thd->net); lex->unit.cleanup(); } - THD_PROC_INFO(thd, "freeing items"); + thd_proc_info(thd, "freeing items"); thd->end_statement(); thd->cleanup_after_query(); DBUG_ASSERT(thd->change_list.is_empty()); |