2006-12-31 01:02:27 +01:00
|
|
|
/* Copyright (C) 2000-2006 MySQL AB
|
2001-12-06 13:10:51 +01:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2001-12-06 13:10:51 +01:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2001-12-06 13:10:51 +01:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
|
|
|
|
|
|
|
|
/* Write some debug info */
|
|
|
|
|
|
|
|
|
|
|
|
#include "mysql_priv.h"
|
|
|
|
#include "sql_select.h"
|
|
|
|
#include <hash.h>
|
2002-06-27 10:27:04 +02:00
|
|
|
#include <thr_alarm.h>
|
2003-10-16 19:55:15 +02:00
|
|
|
#if defined(HAVE_MALLINFO) && defined(HAVE_MALLOC_H)
|
2003-10-11 21:00:24 +02:00
|
|
|
#include <malloc.h>
|
2003-10-16 19:55:15 +02:00
|
|
|
#elif defined(HAVE_MALLINFO) && defined(HAVE_SYS_MALLOC_H)
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#endif
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2008-05-09 09:43:02 +02:00
|
|
|
#ifdef HAVE_EVENT_SCHEDULER
|
2006-09-12 12:26:12 +02:00
|
|
|
#include "events.h"
|
2008-05-09 09:43:02 +02:00
|
|
|
#endif
|
2006-09-12 12:26:12 +02:00
|
|
|
|
2002-10-30 18:30:57 +01:00
|
|
|
static const char *lock_descriptions[] =
|
|
|
|
{
|
2009-04-14 14:05:32 +02:00
|
|
|
/* TL_UNLOCK */ "No lock",
|
|
|
|
/* TL_READ_DEFAULT */ NULL,
|
|
|
|
/* TL_READ */ "Low priority read lock",
|
|
|
|
/* TL_READ_WITH_SHARED_LOCKS */ "Shared read lock",
|
|
|
|
/* TL_READ_HIGH_PRIORITY */ "High priority read lock",
|
|
|
|
/* TL_READ_NO_INSERT */ "Read lock without concurrent inserts",
|
|
|
|
/* TL_WRITE_ALLOW_WRITE */ "Write lock that allows other writers",
|
|
|
|
/* TL_WRITE_ALLOW_READ */ "Write lock, but allow reading",
|
|
|
|
/* TL_WRITE_CONCURRENT_INSERT */ "Concurrent insert lock",
|
|
|
|
/* TL_WRITE_DELAYED */ "Lock used by delayed insert",
|
|
|
|
/* TL_WRITE_DEFAULT */ NULL,
|
|
|
|
/* TL_WRITE_LOW_PRIORITY */ "Low priority write lock",
|
|
|
|
/* TL_WRITE */ "High priority write lock",
|
|
|
|
/* TL_WRITE_ONLY */ "Highest priority write lock"
|
2002-10-30 18:30:57 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
#ifndef DBUG_OFF
|
|
|
|
|
|
|
|
void
|
2008-02-22 11:30:33 +01:00
|
|
|
print_where(COND *cond,const char *info, enum_query_type query_type)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
if (cond)
|
|
|
|
{
|
|
|
|
char buff[256];
|
2003-02-26 11:30:39 +01:00
|
|
|
String str(buff,(uint32) sizeof(buff), system_charset_info);
|
2000-07-31 21:29:14 +02:00
|
|
|
str.length(0);
|
2008-02-22 11:30:33 +01:00
|
|
|
cond->print(&str, query_type);
|
2000-07-31 21:29:14 +02:00
|
|
|
str.append('\0');
|
|
|
|
DBUG_LOCK_FILE;
|
|
|
|
(void) fprintf(DBUG_FILE,"\nWHERE:(%s) ",info);
|
|
|
|
(void) fputs(str.ptr(),DBUG_FILE);
|
|
|
|
(void) fputc('\n',DBUG_FILE);
|
|
|
|
DBUG_UNLOCK_FILE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* This is for debugging purposes */
|
|
|
|
|
|
|
|
|
|
|
|
void print_cached_tables(void)
|
|
|
|
{
|
|
|
|
uint idx,count,unused;
|
|
|
|
TABLE *start_link,*lnk;
|
|
|
|
|
2009-04-14 14:05:32 +02:00
|
|
|
compile_time_assert(TL_WRITE_ONLY+1 == array_elements(lock_descriptions));
|
|
|
|
|
2007-02-23 12:13:55 +01:00
|
|
|
/* purecov: begin tested */
|
2000-07-31 21:29:14 +02:00
|
|
|
VOID(pthread_mutex_lock(&LOCK_open));
|
2007-02-23 12:13:55 +01:00
|
|
|
puts("DB Table Version Thread Open Lock");
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
for (idx=unused=0 ; idx < open_cache.records ; idx++)
|
|
|
|
{
|
|
|
|
TABLE *entry=(TABLE*) hash_element(&open_cache,idx);
|
2007-02-23 12:13:55 +01:00
|
|
|
printf("%-14.14s %-32s%6ld%8ld%6d %s\n",
|
|
|
|
entry->s->db.str, entry->s->table_name.str, entry->s->version,
|
2000-07-31 21:29:14 +02:00
|
|
|
entry->in_use ? entry->in_use->thread_id : 0L,
|
2007-02-23 12:13:55 +01:00
|
|
|
entry->db_stat ? 1 : 0,
|
|
|
|
entry->in_use ? lock_descriptions[(int)entry->reginfo.lock_type] : "Not in use");
|
2000-07-31 21:29:14 +02:00
|
|
|
if (!entry->in_use)
|
|
|
|
unused++;
|
|
|
|
}
|
|
|
|
count=0;
|
|
|
|
if ((start_link=lnk=unused_tables))
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (lnk != lnk->next->prev || lnk != lnk->prev->next)
|
|
|
|
{
|
|
|
|
printf("unused_links isn't linked properly\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} while (count++ < open_cache.records && (lnk=lnk->next) != start_link);
|
|
|
|
if (lnk != start_link)
|
|
|
|
{
|
|
|
|
printf("Unused_links aren't connected\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (count != unused)
|
2000-08-16 11:17:40 +02:00
|
|
|
printf("Unused_links (%d) doesn't match open_cache: %d\n", count,unused);
|
2000-07-31 21:29:14 +02:00
|
|
|
printf("\nCurrent refresh version: %ld\n",refresh_version);
|
|
|
|
if (hash_check(&open_cache))
|
|
|
|
printf("Error: File hash table is corrupted\n");
|
|
|
|
fflush(stdout);
|
|
|
|
VOID(pthread_mutex_unlock(&LOCK_open));
|
2007-02-23 12:13:55 +01:00
|
|
|
/* purecov: end */
|
2000-07-31 21:29:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-16 16:21:47 +02:00
|
|
|
void TEST_filesort(SORT_FIELD *sortorder,uint s_length)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
char buff[256],buff2[256];
|
2003-02-26 11:30:39 +01:00
|
|
|
String str(buff,sizeof(buff),system_charset_info);
|
|
|
|
String out(buff2,sizeof(buff2),system_charset_info);
|
2000-07-31 21:29:14 +02:00
|
|
|
const char *sep;
|
|
|
|
DBUG_ENTER("TEST_filesort");
|
|
|
|
|
|
|
|
out.length(0);
|
|
|
|
for (sep=""; s_length-- ; sortorder++, sep=" ")
|
|
|
|
{
|
|
|
|
out.append(sep);
|
|
|
|
if (sortorder->reverse)
|
|
|
|
out.append('-');
|
|
|
|
if (sortorder->field)
|
|
|
|
{
|
|
|
|
if (sortorder->field->table_name)
|
|
|
|
{
|
2005-01-06 12:00:13 +01:00
|
|
|
out.append(*sortorder->field->table_name);
|
2000-07-31 21:29:14 +02:00
|
|
|
out.append('.');
|
|
|
|
}
|
|
|
|
out.append(sortorder->field->field_name ? sortorder->field->field_name:
|
|
|
|
"tmp_table_column");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
str.length(0);
|
2008-02-22 11:30:33 +01:00
|
|
|
sortorder->item->print(&str, QT_ORDINARY);
|
2000-07-31 21:29:14 +02:00
|
|
|
out.append(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out.append('\0'); // Purify doesn't like c_ptr()
|
|
|
|
DBUG_LOCK_FILE;
|
|
|
|
VOID(fputs("\nInfo about FILESORT\n",DBUG_FILE));
|
|
|
|
fprintf(DBUG_FILE,"Sortorder: %s\n",out.ptr());
|
|
|
|
DBUG_UNLOCK_FILE;
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
TEST_join(JOIN *join)
|
|
|
|
{
|
|
|
|
uint i,ref;
|
|
|
|
DBUG_ENTER("TEST_join");
|
|
|
|
|
|
|
|
DBUG_LOCK_FILE;
|
|
|
|
VOID(fputs("\nInfo about JOIN\n",DBUG_FILE));
|
|
|
|
for (i=0 ; i < join->tables ; i++)
|
|
|
|
{
|
|
|
|
JOIN_TAB *tab=join->join_tab+i;
|
|
|
|
TABLE *form=tab->table;
|
2003-11-02 13:00:25 +01:00
|
|
|
char key_map_buff[128];
|
|
|
|
fprintf(DBUG_FILE,"%-16.16s type: %-7s q_keys: %s refs: %d key: %d len: %d\n",
|
2005-01-06 12:00:13 +01:00
|
|
|
form->alias,
|
2000-07-31 21:29:14 +02:00
|
|
|
join_type_str[tab->type],
|
2003-11-02 13:00:25 +01:00
|
|
|
tab->keys.print(key_map_buff),
|
2000-07-31 21:29:14 +02:00
|
|
|
tab->ref.key_parts,
|
|
|
|
tab->ref.key,
|
|
|
|
tab->ref.key_length);
|
|
|
|
if (tab->select)
|
|
|
|
{
|
2003-10-11 13:06:55 +02:00
|
|
|
char buf[MAX_KEY/8+1];
|
2000-07-31 21:29:14 +02:00
|
|
|
if (tab->use_quick == 2)
|
|
|
|
fprintf(DBUG_FILE,
|
2003-10-11 13:06:55 +02:00
|
|
|
" quick select checked for each record (keys: %s)\n",
|
|
|
|
tab->select->quick_keys.print(buf));
|
2000-07-31 21:29:14 +02:00
|
|
|
else if (tab->select->quick)
|
2003-11-13 15:52:02 +01:00
|
|
|
{
|
2004-05-12 23:38:40 +02:00
|
|
|
fprintf(DBUG_FILE, " quick select used:\n");
|
2005-05-06 10:39:30 +02:00
|
|
|
tab->select->quick->dbug_dump(18, FALSE);
|
2003-11-13 15:52:02 +01:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
else
|
|
|
|
VOID(fputs(" select used\n",DBUG_FILE));
|
|
|
|
}
|
|
|
|
if (tab->ref.key_parts)
|
|
|
|
{
|
|
|
|
VOID(fputs(" refs: ",DBUG_FILE));
|
|
|
|
for (ref=0 ; ref < tab->ref.key_parts ; ref++)
|
|
|
|
{
|
|
|
|
Item *item=tab->ref.items[ref];
|
|
|
|
fprintf(DBUG_FILE,"%s ", item->full_name());
|
|
|
|
}
|
|
|
|
VOID(fputc('\n',DBUG_FILE));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DBUG_UNLOCK_FILE;
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
2004-05-10 14:48:50 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Print the current state during query optimization.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
print_plan()
|
|
|
|
join pointer to the structure providing all context info for
|
|
|
|
the query
|
|
|
|
read_time the cost of the best partial plan
|
|
|
|
record_count estimate for the number of records returned by the best
|
|
|
|
partial plan
|
|
|
|
idx length of the partial QEP in 'join->positions';
|
|
|
|
also an index in the array 'join->best_ref';
|
|
|
|
info comment string to appear above the printout
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
This function prints to the log file DBUG_FILE the members of 'join' that
|
|
|
|
are used during query optimization (join->positions, join->best_positions,
|
|
|
|
and join->best_ref) and few other related variables (read_time,
|
|
|
|
record_count).
|
|
|
|
Useful to trace query optimizer functions.
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
None
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2006-05-03 03:31:20 +02:00
|
|
|
print_plan(JOIN* join, uint idx, double record_count, double read_time,
|
|
|
|
double current_read_time, const char *info)
|
2004-05-10 14:48:50 +02:00
|
|
|
{
|
|
|
|
uint i;
|
|
|
|
POSITION pos;
|
|
|
|
JOIN_TAB *join_table;
|
|
|
|
JOIN_TAB **plan_nodes;
|
|
|
|
TABLE* table;
|
|
|
|
|
|
|
|
if (info == 0)
|
|
|
|
info= "";
|
|
|
|
|
|
|
|
DBUG_LOCK_FILE;
|
|
|
|
if (join->best_read == DBL_MAX)
|
|
|
|
{
|
2006-05-03 03:31:20 +02:00
|
|
|
fprintf(DBUG_FILE,
|
2006-11-27 00:47:38 +01:00
|
|
|
"%s; idx: %u best: DBL_MAX atime: %g itime: %g count: %g\n",
|
|
|
|
info, idx, current_read_time, read_time, record_count);
|
2004-05-10 14:48:50 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-05-03 03:31:20 +02:00
|
|
|
fprintf(DBUG_FILE,
|
2006-11-27 00:47:38 +01:00
|
|
|
"%s; idx :%u best: %g accumulated: %g increment: %g count: %g\n",
|
|
|
|
info, idx, join->best_read, current_read_time, read_time,
|
|
|
|
record_count);
|
2004-05-10 14:48:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Print the tables in JOIN->positions */
|
|
|
|
fputs(" POSITIONS: ", DBUG_FILE);
|
|
|
|
for (i= 0; i < idx ; i++)
|
|
|
|
{
|
|
|
|
pos = join->positions[i];
|
|
|
|
table= pos.table->table;
|
|
|
|
if (table)
|
2005-11-23 21:45:02 +01:00
|
|
|
fputs(table->s->table_name.str, DBUG_FILE);
|
2004-05-10 14:48:50 +02:00
|
|
|
fputc(' ', DBUG_FILE);
|
|
|
|
}
|
|
|
|
fputc('\n', DBUG_FILE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Print the tables in JOIN->best_positions only if at least one complete plan
|
|
|
|
has been found. An indicator for this is the value of 'join->best_read'.
|
|
|
|
*/
|
|
|
|
if (join->best_read < DBL_MAX)
|
|
|
|
{
|
2006-05-04 06:35:27 +02:00
|
|
|
fputs("BEST_POSITIONS: ", DBUG_FILE);
|
2004-05-10 14:48:50 +02:00
|
|
|
for (i= 0; i < idx ; i++)
|
|
|
|
{
|
|
|
|
pos= join->best_positions[i];
|
|
|
|
table= pos.table->table;
|
|
|
|
if (table)
|
2005-11-23 21:45:02 +01:00
|
|
|
fputs(table->s->table_name.str, DBUG_FILE);
|
2004-05-10 14:48:50 +02:00
|
|
|
fputc(' ', DBUG_FILE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fputc('\n', DBUG_FILE);
|
|
|
|
|
|
|
|
/* Print the tables in JOIN->best_ref */
|
|
|
|
fputs(" BEST_REF: ", DBUG_FILE);
|
|
|
|
for (plan_nodes= join->best_ref ; *plan_nodes ; plan_nodes++)
|
|
|
|
{
|
|
|
|
join_table= (*plan_nodes);
|
2005-11-23 21:45:02 +01:00
|
|
|
fputs(join_table->table->s->table_name.str, DBUG_FILE);
|
2004-05-17 14:14:19 +02:00
|
|
|
fprintf(DBUG_FILE, "(%lu,%lu,%lu)",
|
|
|
|
(ulong) join_table->found_records,
|
|
|
|
(ulong) join_table->records,
|
|
|
|
(ulong) join_table->read_time);
|
2004-05-10 14:48:50 +02:00
|
|
|
fputc(' ', DBUG_FILE);
|
|
|
|
}
|
|
|
|
fputc('\n', DBUG_FILE);
|
|
|
|
|
|
|
|
DBUG_UNLOCK_FILE;
|
|
|
|
}
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
#endif
|
|
|
|
|
2002-10-30 15:52:12 +01:00
|
|
|
typedef struct st_debug_lock
|
|
|
|
{
|
|
|
|
ulong thread_id;
|
|
|
|
char table_name[FN_REFLEN];
|
|
|
|
bool waiting;
|
|
|
|
const char *lock_text;
|
|
|
|
enum thr_lock_type type;
|
|
|
|
} TABLE_LOCK_INFO;
|
|
|
|
|
|
|
|
static int dl_compare(TABLE_LOCK_INFO *a,TABLE_LOCK_INFO *b)
|
|
|
|
{
|
|
|
|
if (a->thread_id > b->thread_id)
|
|
|
|
return 1;
|
|
|
|
if (a->thread_id < b->thread_id)
|
|
|
|
return -1;
|
|
|
|
if (a->waiting == b->waiting)
|
|
|
|
return 0;
|
|
|
|
else if (a->waiting)
|
|
|
|
return -1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2003-11-18 12:47:27 +01:00
|
|
|
|
|
|
|
static void push_locks_into_array(DYNAMIC_ARRAY *ar, THR_LOCK_DATA *data,
|
|
|
|
bool wait, const char *text)
|
2002-10-30 15:52:12 +01:00
|
|
|
{
|
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
TABLE *table=(TABLE *)data->debug_print_param;
|
2005-01-06 12:00:13 +01:00
|
|
|
if (table && table->s->tmp_table == NO_TMP_TABLE)
|
2002-10-30 15:52:12 +01:00
|
|
|
{
|
|
|
|
TABLE_LOCK_INFO table_lock_info;
|
2005-01-06 12:00:13 +01:00
|
|
|
table_lock_info.thread_id= table->in_use->thread_id;
|
2005-11-23 21:45:02 +01:00
|
|
|
memcpy(table_lock_info.table_name, table->s->table_cache_key.str,
|
|
|
|
table->s->table_cache_key.length);
|
2002-10-30 15:52:12 +01:00
|
|
|
table_lock_info.table_name[strlen(table_lock_info.table_name)]='.';
|
|
|
|
table_lock_info.waiting=wait;
|
|
|
|
table_lock_info.lock_text=text;
|
2003-11-18 12:47:27 +01:00
|
|
|
// lock_type is also obtainable from THR_LOCK_DATA
|
|
|
|
table_lock_info.type=table->reginfo.lock_type;
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
VOID(push_dynamic(ar,(uchar*) &table_lock_info));
|
2002-10-30 15:52:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-18 12:47:27 +01:00
|
|
|
/*
|
|
|
|
Regarding MERGE tables:
|
|
|
|
|
|
|
|
For now, the best option is to use the common TABLE *pointer for all
|
|
|
|
cases; The drawback is that for MERGE tables we will see many locks
|
|
|
|
for the merge tables even if some of them are for individual tables.
|
2002-10-30 15:52:12 +01:00
|
|
|
|
2003-11-18 12:47:27 +01:00
|
|
|
The way to solve this is to add to 'THR_LOCK' structure a pointer to
|
|
|
|
the filename and use this when printing the data.
|
|
|
|
(We can for now ignore this and just print the same name for all merge
|
|
|
|
table parts; Please add the above as a comment to the display_lock
|
|
|
|
function so that we can easily add this if we ever need this.
|
2002-10-30 15:52:12 +01:00
|
|
|
*/
|
|
|
|
|
2003-11-18 12:47:27 +01:00
|
|
|
static void display_table_locks(void)
|
2002-10-30 15:52:12 +01:00
|
|
|
{
|
|
|
|
LIST *list;
|
|
|
|
DYNAMIC_ARRAY saved_table_locks;
|
|
|
|
|
|
|
|
VOID(my_init_dynamic_array(&saved_table_locks,sizeof(TABLE_LOCK_INFO),open_cache.records + 20,50));
|
|
|
|
VOID(pthread_mutex_lock(&THR_LOCK_lock));
|
2005-08-10 03:02:36 +02:00
|
|
|
for (list= thr_lock_thread_list; list; list= list_rest(list))
|
2002-10-30 15:52:12 +01:00
|
|
|
{
|
|
|
|
THR_LOCK *lock=(THR_LOCK*) list->data;
|
|
|
|
|
|
|
|
VOID(pthread_mutex_lock(&lock->mutex));
|
2004-03-30 01:32:41 +02:00
|
|
|
push_locks_into_array(&saved_table_locks, lock->write.data, FALSE,
|
|
|
|
"Locked - write");
|
|
|
|
push_locks_into_array(&saved_table_locks, lock->write_wait.data, TRUE,
|
|
|
|
"Waiting - write");
|
|
|
|
push_locks_into_array(&saved_table_locks, lock->read.data, FALSE,
|
|
|
|
"Locked - read");
|
|
|
|
push_locks_into_array(&saved_table_locks, lock->read_wait.data, TRUE,
|
|
|
|
"Waiting - read");
|
2002-10-30 15:52:12 +01:00
|
|
|
VOID(pthread_mutex_unlock(&lock->mutex));
|
|
|
|
}
|
|
|
|
VOID(pthread_mutex_unlock(&THR_LOCK_lock));
|
|
|
|
if (!saved_table_locks.elements) goto end;
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
qsort((uchar*) dynamic_element(&saved_table_locks,0,TABLE_LOCK_INFO *),saved_table_locks.elements,sizeof(TABLE_LOCK_INFO),(qsort_cmp) dl_compare);
|
2002-10-30 15:52:12 +01:00
|
|
|
freeze_size(&saved_table_locks);
|
|
|
|
|
|
|
|
puts("\nThread database.table_name Locked/Waiting Lock_type\n");
|
|
|
|
|
2003-01-18 23:04:34 +01:00
|
|
|
unsigned int i;
|
2003-01-04 04:19:17 +01:00
|
|
|
for (i=0 ; i < saved_table_locks.elements ; i++)
|
2002-10-30 15:52:12 +01:00
|
|
|
{
|
|
|
|
TABLE_LOCK_INFO *dl_ptr=dynamic_element(&saved_table_locks,i,TABLE_LOCK_INFO*);
|
|
|
|
printf("%-8ld%-28.28s%-22s%s\n",
|
|
|
|
dl_ptr->thread_id,dl_ptr->table_name,dl_ptr->lock_text,lock_descriptions[(int)dl_ptr->type]);
|
|
|
|
}
|
|
|
|
puts("\n\n");
|
|
|
|
end:
|
|
|
|
delete_dynamic(&saved_table_locks);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-20 21:06:25 +01:00
|
|
|
static int print_key_cache_status(const char *name, KEY_CACHE *key_cache)
|
2003-11-18 12:47:27 +01:00
|
|
|
{
|
2005-09-14 13:18:16 +02:00
|
|
|
char llbuff1[22];
|
|
|
|
char llbuff2[22];
|
|
|
|
char llbuff3[22];
|
|
|
|
char llbuff4[22];
|
|
|
|
|
2003-11-20 21:06:25 +01:00
|
|
|
if (!key_cache->key_cache_inited)
|
2003-11-18 12:47:27 +01:00
|
|
|
{
|
|
|
|
printf("%s: Not in use\n", name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("%s\n\
|
|
|
|
Buffer_size: %10lu\n\
|
|
|
|
Block_size: %10lu\n\
|
|
|
|
Division_limit: %10lu\n\
|
|
|
|
Age_limit: %10lu\n\
|
|
|
|
blocks used: %10lu\n\
|
|
|
|
not flushed: %10lu\n\
|
2005-09-14 13:18:16 +02:00
|
|
|
w_requests: %10s\n\
|
|
|
|
writes: %10s\n\
|
|
|
|
r_requests: %10s\n\
|
|
|
|
reads: %10s\n\n",
|
2003-11-18 12:47:27 +01:00
|
|
|
name,
|
2003-11-20 21:06:25 +01:00
|
|
|
(ulong) key_cache->param_buff_size, key_cache->param_block_size,
|
|
|
|
key_cache->param_division_limit, key_cache->param_age_threshold,
|
2004-05-03 15:55:21 +02:00
|
|
|
key_cache->blocks_used,key_cache->global_blocks_changed,
|
2005-09-14 13:18:16 +02:00
|
|
|
llstr(key_cache->global_cache_w_requests,llbuff1),
|
|
|
|
llstr(key_cache->global_cache_write,llbuff2),
|
|
|
|
llstr(key_cache->global_cache_r_requests,llbuff3),
|
|
|
|
llstr(key_cache->global_cache_read,llbuff4));
|
2003-11-18 12:47:27 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-17 13:07:28 +01:00
|
|
|
void mysql_print_status()
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2001-08-18 09:49:00 +02:00
|
|
|
char current_dir[FN_REFLEN];
|
2005-02-17 13:07:28 +01:00
|
|
|
STATUS_VAR tmp;
|
|
|
|
|
|
|
|
calc_sum_of_all_status(&tmp);
|
2000-07-31 21:29:14 +02:00
|
|
|
printf("\nStatus information:\n\n");
|
2006-01-03 17:54:54 +01:00
|
|
|
VOID(my_getwd(current_dir, sizeof(current_dir),MYF(0)));
|
2001-08-18 09:49:00 +02:00
|
|
|
printf("Current dir: %s\n", current_dir);
|
2003-10-15 14:21:50 +02:00
|
|
|
printf("Running threads: %d Stack size: %ld\n", thread_count,
|
2007-10-11 17:07:40 +02:00
|
|
|
(long) my_thread_stack_size);
|
2000-07-31 21:29:14 +02:00
|
|
|
thr_print_locks(); // Write some debug info
|
|
|
|
#ifndef DBUG_OFF
|
|
|
|
print_cached_tables();
|
|
|
|
#endif
|
|
|
|
/* Print key cache status */
|
2003-11-18 12:47:27 +01:00
|
|
|
puts("\nKey caches:");
|
|
|
|
process_key_caches(print_key_cache_status);
|
2000-07-31 21:29:14 +02:00
|
|
|
pthread_mutex_lock(&LOCK_status);
|
|
|
|
printf("\nhandler status:\n\
|
|
|
|
read_key: %10lu\n\
|
|
|
|
read_next: %10lu\n\
|
|
|
|
read_rnd %10lu\n\
|
|
|
|
read_first: %10lu\n\
|
|
|
|
write: %10lu\n\
|
|
|
|
delete %10lu\n\
|
|
|
|
update: %10lu\n",
|
2005-02-17 13:07:28 +01:00
|
|
|
tmp.ha_read_key_count,
|
|
|
|
tmp.ha_read_next_count,
|
|
|
|
tmp.ha_read_rnd_count,
|
|
|
|
tmp.ha_read_first_count,
|
|
|
|
tmp.ha_write_count,
|
|
|
|
tmp.ha_delete_count,
|
|
|
|
tmp.ha_update_count);
|
2000-07-31 21:29:14 +02:00
|
|
|
pthread_mutex_unlock(&LOCK_status);
|
|
|
|
printf("\nTable status:\n\
|
|
|
|
Opened tables: %10lu\n\
|
|
|
|
Open tables: %10lu\n\
|
|
|
|
Open files: %10lu\n\
|
|
|
|
Open streams: %10lu\n",
|
2005-02-17 13:07:28 +01:00
|
|
|
tmp.opened_tables,
|
2005-11-23 21:45:02 +01:00
|
|
|
(ulong) cached_open_tables(),
|
2000-07-31 21:29:14 +02:00
|
|
|
(ulong) my_file_opened,
|
|
|
|
(ulong) my_stream_opened);
|
2002-06-27 10:27:04 +02:00
|
|
|
|
|
|
|
ALARM_INFO alarm_info;
|
2002-08-08 02:12:02 +02:00
|
|
|
#ifndef DONT_USE_THR_ALARM
|
2002-06-27 10:27:04 +02:00
|
|
|
thr_alarm_info(&alarm_info);
|
|
|
|
printf("\nAlarm status:\n\
|
|
|
|
Active alarms: %u\n\
|
|
|
|
Max used alarms: %u\n\
|
|
|
|
Next alarm time: %lu\n",
|
|
|
|
alarm_info.active_alarms,
|
|
|
|
alarm_info.max_used_alarms,
|
|
|
|
alarm_info.next_alarm_time);
|
2002-08-08 02:12:02 +02:00
|
|
|
#endif
|
2002-10-30 15:52:12 +01:00
|
|
|
display_table_locks();
|
2000-07-31 21:29:14 +02:00
|
|
|
fflush(stdout);
|
2001-04-01 12:45:48 +02:00
|
|
|
my_checkmalloc();
|
2007-05-24 13:11:45 +02:00
|
|
|
fprintf(stdout,"\nBegin safemalloc memory dump:\n"); // tag needed for test suite
|
2007-08-01 21:59:05 +02:00
|
|
|
TERMINATE(stdout, 1); // Write malloc information
|
2007-05-24 13:11:45 +02:00
|
|
|
fprintf(stdout,"\nEnd safemalloc memory dump.\n");
|
2009-01-26 16:39:00 +01:00
|
|
|
fflush(stdout);
|
2003-10-11 21:00:24 +02:00
|
|
|
#ifdef HAVE_MALLINFO
|
|
|
|
struct mallinfo info= mallinfo();
|
|
|
|
printf("\nMemory status:\n\
|
|
|
|
Non-mmapped space allocated from system: %d\n\
|
|
|
|
Number of free chunks: %d\n\
|
|
|
|
Number of fastbin blocks: %d\n\
|
|
|
|
Number of mmapped regions: %d\n\
|
|
|
|
Space in mmapped regions: %d\n\
|
|
|
|
Maximum total allocated space: %d\n\
|
|
|
|
Space available in freed fastbin blocks: %d\n\
|
|
|
|
Total allocated space: %d\n\
|
|
|
|
Total free space: %d\n\
|
2003-10-15 14:21:50 +02:00
|
|
|
Top-most, releasable space: %d\n\
|
|
|
|
Estimated memory (with thread stack): %ld\n",
|
|
|
|
(int) info.arena ,
|
2003-10-11 21:00:24 +02:00
|
|
|
(int) info.ordblks,
|
|
|
|
(int) info.smblks,
|
|
|
|
(int) info.hblks,
|
|
|
|
(int) info.hblkhd,
|
|
|
|
(int) info.usmblks,
|
|
|
|
(int) info.fsmblks,
|
|
|
|
(int) info.uordblks,
|
|
|
|
(int) info.fordblks,
|
2003-10-15 14:21:50 +02:00
|
|
|
(int) info.keepcost,
|
2007-10-11 17:07:40 +02:00
|
|
|
(long) (thread_count * my_thread_stack_size + info.hblkhd + info.arena));
|
2003-10-11 21:00:24 +02:00
|
|
|
#endif
|
2006-09-12 12:26:12 +02:00
|
|
|
|
2008-05-09 09:43:02 +02:00
|
|
|
#ifdef HAVE_EVENT_SCHEDULER
|
2007-04-05 13:24:34 +02:00
|
|
|
Events::dump_internal_status();
|
2008-05-09 09:43:02 +02:00
|
|
|
#endif
|
2003-10-11 21:00:24 +02:00
|
|
|
puts("");
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|