mysql/src/5.1-dbg/sql/sql_show.cc File Reference

#include "mysql_priv.h"
#include "sql_select.h"
#include "sql_show.h"
#include "repl_failsafe.h"
#include "sp.h"
#include "sp_head.h"
#include "sql_trigger.h"
#include "authors.h"
#include "contributors.h"
#include "events.h"
#include "event_timed.h"
#include <my_dir.h>

Include dependency graph for sql_show.cc:

Go to the source code of this file.

Classes

struct  show_privileges_st
struct  show_column_type_st
class  thread_info
struct  st_index_field_values
struct  run_hton_fill_schema_files_args

Defines

#define LIST_PROCESS_HOST_LEN   64

Typedefs

typedef st_index_field_values INDEX_FIELD_VALUES

Enumerations

enum  enum_i_s_events_fields {
  ISE_EVENT_CATALOG = 0, ISE_EVENT_SCHEMA, ISE_EVENT_NAME, ISE_DEFINER,
  ISE_EVENT_BODY, ISE_EVENT_DEFINITION, ISE_EVENT_TYPE, ISE_EXECUTE_AT,
  ISE_INTERVAL_VALUE, ISE_INTERVAL_FIELD, ISE_SQL_MODE, ISE_STARTS,
  ISE_ENDS, ISE_STATUS, ISE_ON_COMPLETION, ISE_CREATED,
  ISE_LAST_ALTERED, ISE_LAST_EXECUTED, ISE_EVENT_COMMENT
}
enum  find_files_result { FIND_FILES_OK, FIND_FILES_OOM, FIND_FILES_DIR }

Functions

static void store_key_options (THD *thd, String *packet, TABLE *table, KEY *key_info)
static void append_algorithm (TABLE_LIST *table, String *buff)
static my_bool show_handlerton (THD *thd, st_plugin_int *plugin, void *arg)
bool mysqld_show_storage_engines (THD *thd)
static int make_version_string (char *buf, int buf_length, uint version)
static my_bool show_plugins (THD *thd, st_plugin_int *plugin, void *arg)
int fill_plugins (THD *thd, TABLE_LIST *tables, COND *cond)
bool mysqld_show_authors (THD *thd)
bool mysqld_show_contributors (THD *thd)
bool mysqld_show_privileges (THD *thd)
bool mysqld_show_column_types (THD *thd)
static find_files_result find_files (THD *thd, List< char > *files, const char *db, const char *path, const char *wild, bool dir)
bool mysqld_show_create (THD *thd, TABLE_LIST *table_list)
bool mysqld_show_create_db (THD *thd, char *dbname, HA_CREATE_INFO *create_info)
void mysqld_list_fields (THD *thd, TABLE_LIST *table_list, const char *wild)
int mysqld_dump_create_info (THD *thd, TABLE_LIST *table_list, int fd)
static const char * require_quotes (const char *name, uint name_length)
void append_identifier (THD *thd, String *packet, const char *name, uint length)
int get_quote_char_for_identifier (THD *thd, const char *name, uint length)
static void append_directory (THD *thd, String *packet, const char *dir_type, const char *filename)
int store_create_info (THD *thd, TABLE_LIST *table_list, String *packet, HA_CREATE_INFO *create_info_arg)
void view_store_options (THD *thd, TABLE_LIST *table, String *buff)
void append_definer (THD *thd, String *buffer, const LEX_STRING *definer_user, const LEX_STRING *definer_host)
int view_store_create_info (THD *thd, TABLE_LIST *table, String *buff)
void mysqld_list_processes (THD *thd, const char *user, bool verbose)
int fill_schema_processlist (THD *thd, TABLE_LIST *tables, COND *cond)
static int show_var_cmp (const void *var1, const void *var2)
static void shrink_var_array (DYNAMIC_ARRAY *array)
int add_status_vars (SHOW_VAR *list)
void init_status_vars ()
void free_status_vars ()
void remove_status_vars (SHOW_VAR *list)
static bool show_status_array (THD *thd, const char *wild, SHOW_VAR *variables, enum enum_var_type value_type, struct system_status_var *status_var, const char *prefix, TABLE *table)
void calc_sum_of_all_status (STATUS_VAR *to)
LEX_STRINGmake_lex_string (THD *thd, LEX_STRING *lex_str, const char *str, uint length, bool allocate_lex_string)
bool schema_table_store_record (THD *thd, TABLE *table)
void get_index_field_values (LEX *lex, INDEX_FIELD_VALUES *index_field_values)
int make_table_list (THD *thd, SELECT_LEX *sel, char *db, char *table)
bool uses_only_table_name_fields (Item *item, TABLE_LIST *table)
static CONDmake_cond_for_info_schema (COND *cond, TABLE_LIST *table)
enum enum_schema_tables get_schema_table_idx (ST_SCHEMA_TABLE *schema_table)
int make_db_list (THD *thd, List< char > *files, INDEX_FIELD_VALUES *idx_field_vals, bool *with_i_schema, bool is_wild_value)
int schema_tables_add (THD *thd, List< char > *files, const char *wild)
int get_all_tables (THD *thd, TABLE_LIST *tables, COND *cond)
bool store_schema_shemata (THD *thd, TABLE *table, const char *db_name, CHARSET_INFO *cs)
int fill_schema_shemata (THD *thd, TABLE_LIST *tables, COND *cond)
static int get_schema_tables_record (THD *thd, struct st_table_list *tables, TABLE *table, bool res, const char *base_name, const char *file_name)
static int get_schema_column_record (THD *thd, struct st_table_list *tables, TABLE *table, bool res, const char *base_name, const char *file_name)
int fill_schema_charsets (THD *thd, TABLE_LIST *tables, COND *cond)
static my_bool iter_schema_engines (THD *thd, st_plugin_int *plugin, void *ptable)
int fill_schema_engines (THD *thd, TABLE_LIST *tables, COND *cond)
int fill_schema_collation (THD *thd, TABLE_LIST *tables, COND *cond)
int fill_schema_coll_charset_app (THD *thd, TABLE_LIST *tables, COND *cond)
bool store_schema_proc (THD *thd, TABLE *table, TABLE *proc_table, const char *wild, bool full_access, const char *sp_user)
int fill_schema_proc (THD *thd, TABLE_LIST *tables, COND *cond)
static int get_schema_stat_record (THD *thd, struct st_table_list *tables, TABLE *table, bool res, const char *base_name, const char *file_name)
static int get_schema_views_record (THD *thd, struct st_table_list *tables, TABLE *table, bool res, const char *base_name, const char *file_name)
bool store_constraints (THD *thd, TABLE *table, const char *db, const char *tname, const char *key_name, uint key_len, const char *con_type, uint con_len)
static int get_schema_constraints_record (THD *thd, struct st_table_list *tables, TABLE *table, bool res, const char *base_name, const char *file_name)
static bool store_trigger (THD *thd, TABLE *table, const char *db, const char *tname, LEX_STRING *trigger_name, enum trg_event_type event, enum trg_action_time_type timing, LEX_STRING *trigger_stmt, ulong sql_mode, LEX_STRING *definer_buffer)
static int get_schema_triggers_record (THD *thd, struct st_table_list *tables, TABLE *table, bool res, const char *base_name, const char *file_name)
void store_key_column_usage (TABLE *table, const char *db, const char *tname, const char *key_name, uint key_len, const char *con_type, uint con_len, longlong idx)
static int get_schema_key_column_usage_record (THD *thd, struct st_table_list *tables, TABLE *table, bool res, const char *base_name, const char *file_name)
static void collect_partition_expr (List< char > &field_list, String *str)
static void store_schema_partitions_record (THD *thd, TABLE *table, partition_element *part_elem, handler *file, uint part_id)
static int get_schema_partitions_record (THD *thd, struct st_table_list *tables, TABLE *table, bool res, const char *base_name, const char *file_name)
static interval_type get_real_interval_type (interval_type i_type)
static int copy_event_to_schema_table (THD *thd, TABLE *sch_table, TABLE *event_table)
static int events_table_index_read_for_db (THD *thd, TABLE *schema_table, TABLE *event_table)
static int events_table_scan_all (THD *thd, TABLE *schema_table, TABLE *event_table)
int fill_schema_events (THD *thd, TABLE_LIST *tables, COND *)
int fill_open_tables (THD *thd, TABLE_LIST *tables, COND *cond)
int fill_variables (THD *thd, TABLE_LIST *tables, COND *cond)
int fill_status (THD *thd, TABLE_LIST *tables, COND *cond)
static int get_referential_constraints_record (THD *thd, struct st_table_list *tables, TABLE *table, bool res, const char *base_name, const char *file_name)
ST_SCHEMA_TABLEfind_schema_table (THD *thd, const char *table_name)
ST_SCHEMA_TABLEget_schema_table (enum enum_schema_tables schema_table_idx)
TABLEcreate_schema_table (THD *thd, TABLE_LIST *table_list)
int make_old_format (THD *thd, ST_SCHEMA_TABLE *schema_table)
int make_schemata_old_format (THD *thd, ST_SCHEMA_TABLE *schema_table)
int make_table_names_old_format (THD *thd, ST_SCHEMA_TABLE *schema_table)
int make_columns_old_format (THD *thd, ST_SCHEMA_TABLE *schema_table)
int make_character_sets_old_format (THD *thd, ST_SCHEMA_TABLE *schema_table)
int make_proc_old_format (THD *thd, ST_SCHEMA_TABLE *schema_table)
int mysql_schema_table (THD *thd, LEX *lex, TABLE_LIST *table_list)
int make_schema_select (THD *thd, SELECT_LEX *sel, enum enum_schema_tables schema_table_idx)
bool get_schema_tables_result (JOIN *join)
static my_bool run_hton_fill_schema_files (THD *thd, st_plugin_int *plugin, void *arg)
int fill_schema_files (THD *thd, TABLE_LIST *tables, COND *cond)

Variables

static const char * grant_names []
static TYPELIB grant_types
static struct show_privileges_st sys_privileges []
static struct show_column_type_st sys_column_types []
static DYNAMIC_ARRAY all_status_vars
static bool status_vars_inited = 0
LEX_STRING information_schema_name = { C_STRING_WITH_LEN("information_schema")}
ST_SCHEMA_TABLE schema_tables []
LEX_STRING interval_type_to_name []
ST_FIELD_INFO schema_fields_info []
ST_FIELD_INFO tables_fields_info []
ST_FIELD_INFO columns_fields_info []
ST_FIELD_INFO charsets_fields_info []
ST_FIELD_INFO collation_fields_info []
ST_FIELD_INFO engines_fields_info []
ST_FIELD_INFO events_fields_info []
ST_FIELD_INFO coll_charset_app_fields_info []
ST_FIELD_INFO proc_fields_info []
ST_FIELD_INFO stat_fields_info []
ST_FIELD_INFO view_fields_info []
ST_FIELD_INFO user_privileges_fields_info []
ST_FIELD_INFO schema_privileges_fields_info []
ST_FIELD_INFO table_privileges_fields_info []
ST_FIELD_INFO column_privileges_fields_info []
ST_FIELD_INFO table_constraints_fields_info []
ST_FIELD_INFO key_column_usage_fields_info []
ST_FIELD_INFO table_names_fields_info []
ST_FIELD_INFO open_tables_fields_info []
ST_FIELD_INFO triggers_fields_info []
ST_FIELD_INFO partitions_fields_info []
ST_FIELD_INFO variables_fields_info []
ST_FIELD_INFO processlist_fields_info []
ST_FIELD_INFO plugin_fields_info []
ST_FIELD_INFO files_fields_info []
ST_FIELD_INFO referential_constraints_fields_info []
ST_SCHEMA_TABLE schema_tables []


Define Documentation

#define LIST_PROCESS_HOST_LEN   64

Definition at line 985 of file sql_show.cc.

Referenced by fill_schema_processlist(), and mysqld_list_processes().


Typedef Documentation

typedef struct st_index_field_values INDEX_FIELD_VALUES


Enumeration Type Documentation

enum enum_i_s_events_fields

Enumerator:
ISE_EVENT_CATALOG 
ISE_EVENT_SCHEMA 
ISE_EVENT_NAME 
ISE_DEFINER 
ISE_EVENT_BODY 
ISE_EVENT_DEFINITION 
ISE_EVENT_TYPE 
ISE_EXECUTE_AT 
ISE_INTERVAL_VALUE 
ISE_INTERVAL_FIELD 
ISE_SQL_MODE 
ISE_STARTS 
ISE_ENDS 
ISE_STATUS 
ISE_ON_COMPLETION 
ISE_CREATED 
ISE_LAST_ALTERED 
ISE_LAST_EXECUTED 
ISE_EVENT_COMMENT 

Definition at line 37 of file sql_show.cc.

enum find_files_result

Enumerator:
FIND_FILES_OK 
FIND_FILES_OOM 
FIND_FILES_DIR 

Definition at line 477 of file sql_show.cc.

00477                        {
00478   FIND_FILES_OK,
00479   FIND_FILES_OOM,
00480   FIND_FILES_DIR
00481 };


Function Documentation

int add_status_vars ( SHOW_VAR list  ) 

Definition at line 1886 of file sql_show.cc.

References all_status_vars, st_dynamic_array::buffer, st_dynamic_array::elements, err, insert_dynamic(), list(), LOCK_status, my_init_dynamic_array, pthread_mutex_lock, pthread_mutex_unlock, show_var_cmp(), and sort_dynamic.

Referenced by init_common_variables(), and plugin_add().

01887 {
01888   int res= 0;
01889   if (status_vars_inited)
01890     pthread_mutex_lock(&LOCK_status);
01891   if (!all_status_vars.buffer && // array is not allocated yet - do it now
01892       my_init_dynamic_array(&all_status_vars, sizeof(SHOW_VAR), 200, 20))
01893   {
01894     res= 1;
01895     goto err;
01896   }
01897   while (list->name)
01898     res|= insert_dynamic(&all_status_vars, (gptr)list++);
01899   res|= insert_dynamic(&all_status_vars, (gptr)list); // appending NULL-element
01900   all_status_vars.elements--; // but next insert_dynamic should overwite it
01901   if (status_vars_inited)
01902     sort_dynamic(&all_status_vars, show_var_cmp);
01903 err:
01904   if (status_vars_inited)
01905     pthread_mutex_unlock(&LOCK_status);
01906   return res;
01907 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void append_algorithm ( TABLE_LIST table,
String buff 
) [static]

Definition at line 1469 of file sql_show.cc.

References st_table_list::algorithm, String::append(), DBUG_ASSERT, STRING_WITH_LEN, VIEW_ALGORITHM_MERGE, VIEW_ALGORITHM_TMPTABLE, and VIEW_ALGORITHM_UNDEFINED.

Referenced by get_schema_views_record(), and view_store_options().

01470 {
01471   buff->append(STRING_WITH_LEN("ALGORITHM="));
01472   switch ((int8)table->algorithm) {
01473   case VIEW_ALGORITHM_UNDEFINED:
01474     buff->append(STRING_WITH_LEN("UNDEFINED "));
01475     break;
01476   case VIEW_ALGORITHM_TMPTABLE:
01477     buff->append(STRING_WITH_LEN("TEMPTABLE "));
01478     break;
01479   case VIEW_ALGORITHM_MERGE:
01480     buff->append(STRING_WITH_LEN("MERGE "));
01481     break;
01482   default:
01483     DBUG_ASSERT(0); // never should happen
01484   }
01485 }

Here is the call graph for this function:

Here is the caller graph for this function:

void append_definer ( THD *  thd,
String buffer,
const LEX_STRING definer_user,
const LEX_STRING definer_host 
)

Definition at line 1498 of file sql_show.cc.

References append_identifier(), buffer, LEX_STRING::length, LEX_STRING::str, and STRING_WITH_LEN.

Referenced by create_string(), db_create_routine(), mysql_create_or_drop_trigger(), and view_store_options().

01500 {
01501   buffer->append(STRING_WITH_LEN("DEFINER="));
01502   append_identifier(thd, buffer, definer_user->str, definer_user->length);
01503   buffer->append('@');
01504   append_identifier(thd, buffer, definer_host->str, definer_host->length);
01505   buffer->append(' ');
01506 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void append_directory ( THD *  thd,
String packet,
const char *  dir_type,
const char *  filename 
) [static]

Definition at line 959 of file sql_show.cc.

References String::append(), dirname_length(), MODE_NO_DIR_IN_CREATE, pos(), and STRING_WITH_LEN.

Referenced by store_create_info().

00961 {
00962   if (filename && !(thd->variables.sql_mode & MODE_NO_DIR_IN_CREATE))
00963   {
00964     uint length= dirname_length(filename);
00965     packet->append(' ');
00966     packet->append(dir_type);
00967     packet->append(STRING_WITH_LEN(" DIRECTORY='"));
00968 #ifdef __WIN__
00969     /* Convert \ to / to be able to create table on unix */
00970     char *winfilename= (char*) thd->memdup(filename, length);
00971     char *pos, *end;
00972     for (pos= winfilename, end= pos+length ; pos < end ; pos++)
00973     {
00974       if (*pos == '\\')
00975         *pos = '/';
00976     }
00977     filename= winfilename;
00978 #endif
00979     packet->append(filename, length);
00980     packet->append('\'');
00981   }
00982 }

Here is the call graph for this function:

Here is the caller graph for this function:

void append_identifier ( THD *  thd,
String packet,
const char *  name,
uint  length 
)

Definition at line 879 of file sql_show.cc.

References String::append(), String::charset(), get_quote_char_for_identifier(), my_mbcharlen, String::reserve(), system_charset_info, and VOID.

Referenced by ha_myisammrg::append_create_info(), append_definer(), Table_triggers_list::change_table_name_in_triggers(), close_temporary_tables(), create_string(), evex_print_warnings(), sp_head::execute_function(), Item_func_sp::func_name(), Event_timed::get_create_event(), mysql_execute_command(), mysql_show_grants(), mysqld_show_create_db(), st_table_list::print(), Item_ref::print(), Item_ident::print(), Item::print_item_w_name(), show_routine_grants(), and store_create_info().

00880 {
00881   const char *name_end;
00882   char quote_char;
00883   int q= get_quote_char_for_identifier(thd, name, length);
00884 
00885   if (q == EOF)
00886   {
00887     packet->append(name, length, system_charset_info);
00888     return;
00889   }
00890 
00891   /*
00892     The identifier must be quoted as it includes a quote character or
00893    it's a keyword
00894   */
00895 
00896   VOID(packet->reserve(length*2 + 2));
00897   quote_char= (char) q;
00898   packet->append(&quote_char, 1, system_charset_info);
00899 
00900   for (name_end= name+length ; name < name_end ; name+= length)
00901   {
00902     uchar chr= (uchar) *name;
00903     length= my_mbcharlen(system_charset_info, chr);
00904     /*
00905       my_mbcharlen can retur 0 on a wrong multibyte
00906       sequence. It is possible when upgrading from 4.0,
00907       and identifier contains some accented characters.
00908       The manual says it does not work. So we'll just
00909       change length to 1 not to hang in the endless loop.
00910     */
00911     if (!length)
00912       length= 1;
00913     if (length == 1 && chr == (uchar) quote_char)
00914       packet->append(&quote_char, 1, system_charset_info);
00915     packet->append(name, length, packet->charset());
00916   }
00917   packet->append(&quote_char, 1, system_charset_info);
00918 }

Here is the call graph for this function:

Here is the caller graph for this function:

void calc_sum_of_all_status ( STATUS_VAR to  ) 

Definition at line 2137 of file sql_show.cc.

References add_to_status(), DBUG_ENTER, DBUG_VOID_RETURN, global_status_var, LOCK_thread_count, pthread_mutex_lock, pthread_mutex_unlock, threads, to, and VOID.

Referenced by dispatch_command(), fill_status(), and mysql_print_status().

02138 {
02139   DBUG_ENTER("calc_sum_of_all_status");
02140 
02141   /* Ensure that thread id not killed during loop */
02142   VOID(pthread_mutex_lock(&LOCK_thread_count)); // For unlink from list
02143 
02144   I_List_iterator<THD> it(threads);
02145   THD *tmp;
02146   
02147   /* Get global values as base */
02148   *to= global_status_var;
02149   
02150   /* Add to this status from existing threads */
02151   while ((tmp= it++))
02152     add_to_status(to, &tmp->status_var);
02153   
02154   VOID(pthread_mutex_unlock(&LOCK_thread_count));
02155   DBUG_VOID_RETURN;
02156 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void collect_partition_expr ( List< char > &  field_list,
String str 
) [static]

Definition at line 3873 of file sql_show.cc.

References String::append(), base_list::elements, and String::length().

Referenced by get_schema_partitions_record().

03874 {
03875   List_iterator<char> part_it(field_list);
03876   ulong no_fields= field_list.elements;
03877   const char *field_str;
03878   str->length(0);
03879   while ((field_str= part_it++))
03880   {
03881     str->append(field_str);
03882     if (--no_fields != 0)
03883       str->append(",");
03884   }
03885   return;
03886 }

Here is the call graph for this function:

Here is the caller graph for this function:

static int copy_event_to_schema_table ( THD *  thd,
TABLE sch_table,
TABLE event_table 
) [static]

Definition at line 4221 of file sql_show.cc.

References Event_timed::body, check_access(), Event_timed::comment, Event_timed::created, Event_timed::dbname, DBUG_ASSERT, DBUG_ENTER, DBUG_RETURN, Event_timed::definer, Event_timed::ENABLED, Event_timed::ends, Event_timed::ends_null, ER_CANNOT_LOAD_FROM_TABLE, EVENT_ACL, Event_timed::execute_at, Event_timed::expression, st_table::field, Event_timed::interval, interval_type_to_name, ISE_CREATED, ISE_DEFINER, ISE_ENDS, ISE_EVENT_BODY, ISE_EVENT_COMMENT, ISE_EVENT_DEFINITION, ISE_EVENT_NAME, ISE_EVENT_SCHEMA, ISE_EVENT_TYPE, ISE_EXECUTE_AT, ISE_INTERVAL_FIELD, ISE_INTERVAL_VALUE, ISE_LAST_ALTERED, ISE_LAST_EXECUTED, ISE_ON_COMPLETION, ISE_SQL_MODE, ISE_STARTS, ISE_STATUS, Event_timed::last_executed, LEX_STRING::length, Event_timed::load_from_row(), Event_timed::modified, my_error(), MYF, MYSQL_TIMESTAMP_DATETIME, Event_timed::name, NullS, number_to_datetime(), Event_timed::on_completion, Event_timed::ON_COMPLETION_DROP, Events::reconstruct_interval_expression(), restore_record, schema_table_store_record(), Field::set_notnull(), Event_timed::sql_mode, sql_mode_str, SQLCOM_SHOW_EVENTS, Event_timed::starts, Event_timed::status,