summaryrefslogtreecommitdiff
path: root/sql/sql_parse.cc
diff options
context:
space:
mode:
authorChad MILLER <chad@mysql.com>2009-05-06 09:06:32 -0400
committerChad MILLER <chad@mysql.com>2009-05-06 09:06:32 -0400
commit128afdc3e5d06381f525e0d9cdc2df7c497e886c (patch)
treeb7a5df1540af07a49f7d577804919b7027fc4edf /sql/sql_parse.cc
parent0f95bd31058f21f0872191eac49809622725564d (diff)
parent9d58239dea8c615a10a0939e34d052b22808e75f (diff)
downloadmariadb-git-128afdc3e5d06381f525e0d9cdc2df7c497e886c.tar.gz
Merge community up to enterprise, thus ending the community-server
adventure.
Diffstat (limited to 'sql/sql_parse.cc')
-rw-r--r--sql/sql_parse.cc103
1 files changed, 79 insertions, 24 deletions
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 7fbe6b86fbd..507805ec0c4 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -178,14 +178,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;
+ thd->options&= ~OPTION_BEGIN;
thd->transaction.all.modified_non_trans_table= FALSE;
}
DBUG_RETURN(error);
@@ -211,7 +211,7 @@ static bool begin_trans(THD *thd)
{
LEX *lex= thd->lex;
thd->transaction.all.modified_non_trans_table= FALSE;
- thd->options|= (ulong) OPTION_BEGIN;
+ thd->options|= OPTION_BEGIN;
thd->server_status|= SERVER_STATUS_IN_TRANS;
if (lex->start_transaction_opt & MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT)
error= ha_start_consistent_snapshot(thd);
@@ -1099,7 +1099,7 @@ void execute_init_command(THD *thd, sys_var_str *init_command_var,
Vio* save_vio;
ulong save_client_capabilities;
- thd->proc_info= "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
@@ -1203,7 +1203,7 @@ pthread_handler_t handle_one_connection(void *arg)
net->compress=1; // Use compression
thd->version= refresh_version;
- thd->proc_info= 0;
+ thd_proc_info(thd, 0);
thd->command= COM_SLEEP;
thd->init_for_queries();
@@ -1219,7 +1219,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=0;
+ thd_proc_info(thd, 0);
thd->init_for_queries();
}
@@ -1311,7 +1311,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=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));
@@ -1355,6 +1355,10 @@ pthread_handler_t handle_bootstrap(void *arg)
thd->db_length+1+QUERY_CACHE_FLAGS_SIZE);
thd->query[length] = '\0';
DBUG_PRINT("query",("%-.4096s",thd->query));
+#if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER)
+ thd->profiling.set_query_source(thd->query, length);
+#endif
+
/*
We don't need to obtain LOCK_thread_count here because in bootstrap
mode we have only one thread.
@@ -1512,7 +1516,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;
+ thd->options&= ~OPTION_BEGIN;
thd->transaction.all.modified_non_trans_table= FALSE;
break;
case COMMIT_RELEASE:
@@ -1530,7 +1534,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;
+ thd->options&= ~OPTION_BEGIN;
thd->transaction.all.modified_non_trans_table= FALSE;
if (!res && (completion == ROLLBACK_AND_CHAIN))
res= begin_trans(thd);
@@ -1564,6 +1568,7 @@ int end_trans(THD *thd, enum enum_mysql_completiontype completion)
static bool do_command(THD *thd)
{
+ bool return_value;
char *packet= 0;
ulong packet_length;
NET *net= &thd->net;
@@ -1587,7 +1592,12 @@ static bool do_command(THD *thd)
thd->clear_error(); // Clear error message
net_new_transaction(net);
- if ((packet_length=my_net_read(net)) == packet_error)
+
+ packet_length= my_net_read(net);
+#if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER)
+ thd->profiling.start_new_query();
+#endif
+ if (packet_length == packet_error)
{
DBUG_PRINT("info",("Got error %d reading command from socket %s",
net->error,
@@ -1596,11 +1606,15 @@ static bool do_command(THD *thd)
/* Check if we can continue without closing the connection */
if (net->error != 3)
- DBUG_RETURN(TRUE); // We have to close it.
+ {
+ return_value= TRUE; // We have to close it.
+ goto out;
+ }
net_send_error(thd, net->last_errno, NullS);
net->error= 0;
- DBUG_RETURN(FALSE);
+ return_value= FALSE;
+ goto out;
}
else
{
@@ -1625,7 +1639,13 @@ static bool do_command(THD *thd)
command == packet[0] == COM_SLEEP).
In dispatch_command packet[packet_length] points beyond the end of packet.
*/
- DBUG_RETURN(dispatch_command(command,thd, packet+1, (uint) packet_length));
+ return_value= dispatch_command(command, thd, packet+1, (uint) (packet_length));
+
+out:
+#if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER)
+ thd->profiling.finish_current_query();
+#endif
+ DBUG_RETURN(return_value);
}
#endif /* EMBEDDED_LIBRARY */
@@ -1931,6 +1951,9 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
mysql_log.write(thd,command, format, thd->query_length, thd->query);
DBUG_PRINT("query",("%-.4096s",thd->query));
+#if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER)
+ thd->profiling.set_query_source(thd->query, thd->query_length);
+#endif
if (!(specialflag & SPECIAL_NO_PRIOR))
my_pthread_setprio(pthread_self(),QUERY_PRIOR);
@@ -1957,6 +1980,13 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
next_packet++;
length--;
}
+
+#if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER)
+ thd->profiling.finish_current_query();
+ thd->profiling.start_new_query("continuing");
+ thd->profiling.set_query_source(next_packet, length);
+#endif
+
VOID(pthread_mutex_lock(&LOCK_thread_count));
thd->query_length= length;
thd->query= next_packet;
@@ -2273,7 +2303,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="closing tables";
+ thd_proc_info(thd, "closing tables");
close_thread_tables(thd); /* Free tables */
}
/*
@@ -2296,9 +2326,9 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
log_slow_statement(thd);
- thd->proc_info="cleaning up";
+ thd_proc_info(thd, "cleaning up");
VOID(pthread_mutex_lock(&LOCK_thread_count)); // For process list
- thd->proc_info=0;
+ thd_proc_info(thd, 0);
thd->command=COM_SLEEP;
thd->query=0;
thd->query_length=0;
@@ -2331,7 +2361,7 @@ void log_slow_statement(THD *thd)
*/
if (thd->enable_slow_log && !thd->user_time)
{
- thd->proc_info="logging slow query";
+ thd_proc_info(thd, "logging slow query");
if ((thd->start_time > thd->time_after_lock &&
(ulong) (thd->start_time - thd->time_after_lock) >
@@ -2342,6 +2372,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->status_var.long_query_count++;
mysql_slow_log.write(thd, thd->query, thd->query_length, start_of_query);
}
@@ -2449,6 +2480,15 @@ int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident,
break;
}
#endif
+ case SCH_PROFILES:
+ /*
+ Mark this current profiling record to be discarded. We don't
+ wish to have SHOW commands show up in profiling.
+ */
+#if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER)
+ thd->profiling.discard_current_query();
+#endif
+ break;
case SCH_OPEN_TABLES:
case SCH_VARIABLES:
case SCH_STATUS:
@@ -2923,6 +2963,19 @@ mysql_execute_command(THD *thd)
(1L << (uint) MYSQL_ERROR::WARN_LEVEL_ERROR));
break;
}
+ case SQLCOM_SHOW_PROFILES:
+ {
+#if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER)
+ thd->profiling.discard_current_query();
+ res= thd->profiling.show_profiles();
+ if (res)
+ goto error;
+#else
+ my_error(ER_FEATURE_DISABLED, MYF(0), "SHOW PROFILES", "enable-profiling");
+ goto error;
+#endif
+ break;
+ }
case SQLCOM_SHOW_NEW_MASTER:
{
if (check_global_access(thd, REPL_SLAVE_ACL))
@@ -3920,7 +3973,7 @@ end_with_restore_list:
if (add_item_to_list(thd, new Item_null()))
goto error;
- thd->proc_info="init";
+ thd_proc_info(thd, "init");
if ((res= open_and_lock_tables(thd, all_tables)))
break;
@@ -4091,7 +4144,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);
@@ -4130,7 +4183,7 @@ end_with_restore_list:
that it can't lock a table in its list
*/
end_active_trans(thd);
- thd->options&= ~(ulong) (OPTION_TABLE_LOCK);
+ thd->options&= ~(OPTION_TABLE_LOCK);
}
thd->in_lock_tables=0;
break;
@@ -5241,7 +5294,7 @@ create_sp_error:
thd->transaction.xid_state.xid.set(thd->lex->xid);
xid_cache_insert(&thd->transaction.xid_state);
thd->transaction.all.modified_non_trans_table= FALSE;
- thd->options|= (ulong) OPTION_BEGIN;
+ thd->options|= OPTION_BEGIN;
thd->server_status|= SERVER_STATUS_IN_TRANS;
send_ok(thd);
break;
@@ -5347,7 +5400,7 @@ create_sp_error:
xa_state_names[thd->transaction.xid_state.xa_state]);
break;
}
- thd->options&= ~(ulong) OPTION_BEGIN;
+ thd->options&= ~OPTION_BEGIN;
thd->transaction.all.modified_non_trans_table= FALSE;
thd->server_status&= ~SERVER_STATUS_IN_TRANS;
xid_cache_delete(&thd->transaction.xid_state);
@@ -5392,7 +5445,7 @@ create_sp_error:
send_ok(thd);
break;
}
- thd->proc_info="query end";
+ thd_proc_info(thd, "query end");
/* Two binlog-related cleanups: */
/*
@@ -5576,6 +5629,7 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv,
else
save_priv= &dummy;
+ thd_proc_info(thd, "checking permissions");
if ((!db || !db[0]) && !thd->db && !dont_check_global_grants)
{
DBUG_PRINT("error",("No database"));
@@ -5774,6 +5828,7 @@ static bool check_show_access(THD *thd, TABLE_LIST *table)
case SCH_COLUMN_PRIVILEGES:
case SCH_TABLE_CONSTRAINTS:
case SCH_KEY_COLUMN_USAGE:
+ case SCH_PROFILES:
break;
}
@@ -6401,7 +6456,7 @@ void mysql_parse(THD *thd, const char *inBuf, uint length,
thd->lex->sphead= 0;
}
lex->unit.cleanup();
- thd->proc_info="freeing items";
+ thd_proc_info(thd, "freeing items");
thd->end_statement();
thd->cleanup_after_query();
DBUG_ASSERT(thd->change_list.is_empty());