1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00

Prevent bugs by making DBUG_* expressions syntactically equivalent

to a single statement.
---
Bug#24795: SHOW PROFILE

Profiling is only partially functional on some architectures.  Where 
there is no getrusage() system call, presently Null values are 
returned where it would be required.  Notably, Windows needs some love 
applied to make it as useful.

  Syntax this adds:
  
  SHOW PROFILES
  
  SHOW PROFILE [types] [FOR QUERY n] [OFFSET n] [LIMIT n]
   where "n" is an integer
   and "types" is zero or many (comma-separated) of
      "CPU"
      "MEMORY" (not presently supported)
      "BLOCK IO"
      "CONTEXT SWITCHES"
      "PAGE FAULTS"
      "IPC"
      "SWAPS"
      "SOURCE"
      "ALL"

It also adds a session variable (boolean) "profiling", set to "no"
by default, and (integer) profiling_history_size, set to 15 by 
default.

This patch abstracts setting THDs' "proc_info" behind a macro that 
can be used as a hook into the profiling code when profiling 
support is compiled in.  All future code in this line should use
that mechanism for setting thd->proc_info.

---

Tests are now set to omit the statistics.

---

Adds an Information_schema table, "profiling" for access to 
"show profile" data.
---
Merge zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.0-community-3--bug24795
into  zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.0-community
---
Fix merge problems.
---
Fixed one bug in the query_source being NULL.  

Updated test results.
---
Include more thorough profiling tests.

Improve support for prepared statements.

Use session-specific query IDs, starting at zero.
---
Selecting from I_S.profiling is no longer quashed in profiling, as
requested by Giuseppe.

Limit the size of captured query text.

No longer log queries that are zero length.
This commit is contained in:
cmiller@zippy.cornsilk.net
2007-02-22 10:03:08 -05:00
parent dffdc8118b
commit 6e096ee8d9
48 changed files with 1602 additions and 574 deletions

View File

@ -598,7 +598,7 @@ JOIN::optimize()
if (thd->lex->orig_sql_command != SQLCOM_SHOW_STATUS)
thd->status_var.last_query_cost= 0.0;
THD_PROC_INFO(thd, "optimizing");
thd_proc_info(thd, "optimizing");
row_limit= ((select_distinct || order || group_list) ? HA_POS_ERROR :
unit->select_limit_cnt);
/* select_limit is used to decide if we are likely to scan the whole table */
@ -745,7 +745,7 @@ JOIN::optimize()
sort_by_table= get_sort_by_table(order, group_list, select_lex->leaf_tables);
/* Calculate how to do the join */
THD_PROC_INFO(thd, "statistics");
thd_proc_info(thd, "statistics");
if (make_join_statistics(this, select_lex->leaf_tables, conds, &keyuse) ||
thd->is_fatal_error)
{
@ -755,7 +755,7 @@ JOIN::optimize()
/* Remove distinct if only const tables */
select_distinct= select_distinct && (const_tables != tables);
THD_PROC_INFO(thd, "preparing");
thd_proc_info(thd, "preparing");
if (result->initialize_tables(this))
{
DBUG_PRINT("error",("Error: initialize_tables() failed"));
@ -1162,7 +1162,7 @@ JOIN::optimize()
if (need_tmp)
{
DBUG_PRINT("info",("Creating tmp table"));
THD_PROC_INFO(thd, "creating temporary table");
thd_proc_info(thd, "Creating tmp table");
init_items_ref_array();
@ -1213,7 +1213,7 @@ JOIN::optimize()
if (group_list && simple_group)
{
DBUG_PRINT("info",("Sorting for group"));
THD_PROC_INFO(thd, "sorting for group");
thd_proc_info(thd, "Sorting for group");
if (create_sort_index(thd, this, group_list,
HA_POS_ERROR, HA_POS_ERROR) ||
alloc_group_fields(this, group_list) ||
@ -1234,9 +1234,8 @@ JOIN::optimize()
if (!group_list && ! exec_tmp_table1->distinct && order && simple_order)
{
DBUG_PRINT("info",("Sorting for order"));
THD_PROC_INFO(thd, "Sorting for order");
if (create_sort_index(thd, this, order,
thd_proc_info(thd, "Sorting for order");
if (create_sort_index(thd, this, order,
HA_POS_ERROR, HA_POS_ERROR))
{
DBUG_RETURN(1);
@ -1364,7 +1363,7 @@ JOIN::exec()
int tmp_error;
DBUG_ENTER("JOIN::exec");
THD_PROC_INFO(thd, "executing");
thd_proc_info(thd, "executing");
error= 0;
if (procedure)
{
@ -1504,7 +1503,7 @@ JOIN::exec()
curr_tmp_table= exec_tmp_table1;
/* Copy data to the temporary table */
THD_PROC_INFO(thd, "Copying to tmp table");
thd_proc_info(thd, "Copying to tmp table");
DBUG_PRINT("info", ("%s", thd->proc_info));
if ((tmp_error= do_select(curr_join, (List<Item> *) 0, curr_tmp_table, 0)))
{
@ -1627,7 +1626,7 @@ JOIN::exec()
}
if (curr_join->group_list)
{
THD_PROC_INFO(thd, "Creating sort index");
thd_proc_info(thd, "Creating sort index");
if (curr_join->join_tab == join_tab && save_join_tab())
{
DBUG_VOID_RETURN;
@ -1641,7 +1640,7 @@ JOIN::exec()
sortorder= curr_join->sortorder;
}
THD_PROC_INFO(thd, "Copying to group table");
thd_proc_info(thd, "Copying to group table");
DBUG_PRINT("info", ("%s", thd->proc_info));
tmp_error= -1;
if (curr_join != this)
@ -1697,7 +1696,7 @@ JOIN::exec()
curr_join->join_free(); /* Free quick selects */
if (curr_join->select_distinct && ! curr_join->group_list)
{
THD_PROC_INFO(thd, "Removing duplicates");
thd_proc_info(thd, "Removing duplicates");
if (curr_join->tmp_having)
curr_join->tmp_having->update_used_tables();
if (remove_duplicates(curr_join, curr_tmp_table,
@ -1758,7 +1757,7 @@ JOIN::exec()
if (curr_join->group_list || curr_join->order)
{
DBUG_PRINT("info",("Sorting for send_fields"));
THD_PROC_INFO(thd, "Sorting result");
thd_proc_info(thd, "Sorting result");
/* If we have already done the group, add HAVING to sorted table */
if (curr_join->tmp_having && ! curr_join->group_list &&
! curr_join->sort_and_group)
@ -1882,7 +1881,7 @@ JOIN::exec()
}
else
{
THD_PROC_INFO(thd, "Sending data");
thd_proc_info(thd, "Sending data");
DBUG_PRINT("info", ("%s", thd->proc_info));
result->send_fields((procedure ? curr_join->procedure_fields_list :
*curr_fields_list),
@ -2030,7 +2029,7 @@ mysql_select(THD *thd, Item ***rref_pointer_array,
{
if (!(join= new JOIN(thd, fields, select_options, result)))
DBUG_RETURN(TRUE);
THD_PROC_INFO(thd, "init");
thd_proc_info(thd, "init");
thd->used_tables=0; // Updated by setup_fields
if (err= join->prepare(rref_pointer_array, tables, wild_num,
conds, og_num, order, group, having, proc_param,
@ -2075,9 +2074,9 @@ mysql_select(THD *thd, Item ***rref_pointer_array,
err:
if (free_join)
{
THD_PROC_INFO(thd, "cleaning up");
thd_proc_info(thd, "end");
err|= select_lex->cleanup();
THD_PROC_INFO(thd, "end");
thd_proc_info(thd, "end");
DBUG_RETURN(err || thd->net.report_error);
}
DBUG_RETURN(join->error);
@ -9807,7 +9806,7 @@ free_tmp_table(THD *thd, TABLE *entry)
DBUG_PRINT("enter",("table: %s",entry->alias));
save_proc_info=thd->proc_info;
THD_PROC_INFO(thd, "removing tmp table");
thd_proc_info(thd, "removing tmp table");
if (entry->file)
{
@ -9835,7 +9834,7 @@ free_tmp_table(THD *thd, TABLE *entry)
bitmap_clear_bit(&temp_pool, entry->temp_pool_slot);
free_root(&own_root, MYF(0)); /* the table is allocated in its own root */
THD_PROC_INFO(thd, save_proc_info);
thd_proc_info(thd, save_proc_info);
DBUG_VOID_RETURN;
}
@ -9865,7 +9864,7 @@ bool create_myisam_from_heap(THD *thd, TABLE *table, TMP_TABLE_PARAM *param,
DBUG_RETURN(1); // End of memory
save_proc_info=thd->proc_info;
THD_PROC_INFO(thd, "converting HEAP to MyISAM");
thd_proc_info(thd, "converting HEAP to MyISAM");
if (create_myisam_tmp_table(&new_table,param,
thd->lex->select_lex.options | thd->options))
@ -9918,8 +9917,8 @@ bool create_myisam_from_heap(THD *thd, TABLE *table, TMP_TABLE_PARAM *param,
table->s= &table->share_not_to_be_used;
table->file->change_table_ptr(table);
if (save_proc_info)
THD_PROC_INFO(thd, (!strcmp(save_proc_info,"Copying to tmp table") ?
"Copying to tmp table on disk" : save_proc_info));
thd_proc_info(thd, (!strcmp(save_proc_info,"Copying to tmp table") ?
"Copying to tmp table on disk" : save_proc_info));
DBUG_RETURN(0);
err:
@ -9931,7 +9930,7 @@ bool create_myisam_from_heap(THD *thd, TABLE *table, TMP_TABLE_PARAM *param,
new_table.file->delete_table(new_table.s->table_name);
delete new_table.file;
err2:
THD_PROC_INFO(thd, save_proc_info);
thd_proc_info(thd, save_proc_info);
DBUG_RETURN(1);
}