diff options
Diffstat (limited to 'sql/sql_show.cc')
-rw-r--r-- | sql/sql_show.cc | 144 |
1 files changed, 110 insertions, 34 deletions
diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 124ce1805db..263f907f277 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -41,6 +41,7 @@ static int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet); static int view_store_create_info(THD *thd, TABLE_LIST *table, String *packet); +static bool schema_table_store_record(THD *thd, TABLE *table); /*************************************************************************** @@ -102,6 +103,7 @@ static struct show_privileges_st sys_privileges[]= {"Create routine","Functions,Procedures","To use CREATE FUNCTION/PROCEDURE"}, {"Create temporary tables","Databases","To use CREATE TEMPORARY TABLE"}, {"Create view", "Tables", "To create new views"}, + {"Create user", "Server Admin", "To create new users"}, {"Delete", "Tables", "To delete existing rows"}, {"Drop", "Databases,Tables", "To drop databases, tables, and views"}, {"Execute", "Functions,Procedures", "To execute stored routines"}, @@ -977,7 +979,7 @@ store_create_info(THD *thd, TABLE_LIST *table_list, String *packet) packet->append(buff, (uint) (end- buff)); } - if (share->max_rows) + if (share->max_rows && !table_list->schema_table) { packet->append(" MAX_ROWS=", 10); end= longlong10_to_str(share->max_rows, buff, 10); @@ -1330,6 +1332,19 @@ static bool show_status_array(THD *thd, const char *wild, pthread_mutex_unlock(&LOCK_active_mi); break; } + case SHOW_SLAVE_RETRIED_TRANS: + { + /* + TODO: in 5.1 with multimaster, have one such counter per line in SHOW + SLAVE STATUS, and have the sum over all lines here. + */ + pthread_mutex_lock(&LOCK_active_mi); + pthread_mutex_lock(&active_mi->rli.data_lock); + end= int10_to_str(active_mi->rli.retried_trans, buff, 10); + pthread_mutex_unlock(&active_mi->rli.data_lock); + pthread_mutex_unlock(&LOCK_active_mi); + break; + } #endif /* HAVE_REPLICATION */ case SHOW_OPENTABLES: end= int10_to_str((long) cached_tables(), buff, 10); @@ -1536,7 +1551,8 @@ static bool show_status_array(THD *thd, const char *wild, table->field[0]->store(name_buffer, strlen(name_buffer), system_charset_info); table->field[1]->store(pos, (uint32) (end - pos), system_charset_info); - table->file->write_row(table->record[0]); + if (schema_table_store_record(thd, table)) + DBUG_RETURN(TRUE); } } } @@ -1592,6 +1608,34 @@ typedef struct st_index_field_values } INDEX_FIELD_VALUES; +/* + Store record to I_S table, convert HEAP table + to MyISAM if necessary + + SYNOPSIS + schema_table_store_record() + thd thread handler + table Information schema table to be updated + + RETURN + 0 success + 1 error +*/ + +static bool schema_table_store_record(THD *thd, TABLE *table) +{ + int error; + if ((error= table->file->write_row(table->record[0]))) + { + if (create_myisam_from_heap(thd, table, + table->pos_in_table_list->schema_table_param, + error, 0)) + return 1; + } + return 0; +} + + void get_index_field_values(LEX *lex, INDEX_FIELD_VALUES *index_field_values) { const char *wild= lex->wild ? lex->wild->ptr() : NullS; @@ -1915,7 +1959,8 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) } } } - table->file->write_row(table->record[0]); + if (schema_table_store_record(thd, table)) + goto err; } else { @@ -1952,13 +1997,13 @@ err: } -void store_schema_shemata(TABLE *table, const char *db_name, +bool store_schema_shemata(THD* thd, TABLE *table, const char *db_name, const char* cs_name) { restore_record(table, s->default_values); table->field[1]->store(db_name, strlen(db_name), system_charset_info); table->field[2]->store(cs_name, strlen(cs_name), system_charset_info); - table->file->write_row(table->record[0]); + return schema_table_store_record(thd, table); } @@ -1987,7 +2032,9 @@ int fill_schema_shemata(THD *thd, TABLE_LIST *tables, COND *cond) { if (with_i_schema) // information schema name is always first in list { - store_schema_shemata(table, file_name, system_charset_info->csname); + if (store_schema_shemata(thd, table, file_name, + system_charset_info->csname)) + DBUG_RETURN(1); with_i_schema= 0; continue; } @@ -2010,8 +2057,9 @@ int fill_schema_shemata(THD *thd, TABLE_LIST *tables, COND *cond) path[length-1]= FN_LIBCHAR; strmov(path+length, MY_DB_OPT_FILE); load_db_opt(thd, path, &create); - store_schema_shemata(table, file_name, - create.default_table_charset->csname); + if (store_schema_shemata(thd, table, file_name, + create.default_table_charset->csname)) + DBUG_RETURN(1); } } DBUG_RETURN(0); @@ -2196,8 +2244,7 @@ static int get_schema_tables_record(THD *thd, struct st_table_list *tables, } } } - table->file->write_row(table->record[0]); - DBUG_RETURN(0); + DBUG_RETURN(schema_table_store_record(thd, table)); } @@ -2375,7 +2422,8 @@ static int get_schema_column_record(THD *thd, struct st_table_list *tables, #endif table->field[17]->store(tmp+1,end == tmp ? 0 : (uint) (end-tmp-1), cs); table->field[18]->store(field->comment.str, field->comment.length, cs); - table->file->write_row(table->record[0]); + if (schema_table_store_record(thd, table)) + DBUG_RETURN(1); } } DBUG_RETURN(0); @@ -2404,7 +2452,8 @@ int fill_schema_charsets(THD *thd, TABLE_LIST *tables, COND *cond) strlen(tmp_cs->comment ? tmp_cs->comment : ""), scs); table->field[3]->store((longlong) tmp_cs->mbmaxlen); - table->file->write_row(table->record[0]); + if (schema_table_store_record(thd, table)) + return 1; } } return 0; @@ -2443,7 +2492,8 @@ int fill_schema_collation(THD *thd, TABLE_LIST *tables, COND *cond) tmp_buff= (tmp_cl->state & MY_CS_COMPILED)? "Yes" : ""; table->field[4]->store(tmp_buff, strlen(tmp_buff), scs); table->field[5]->store((longlong) tmp_cl->strxfrm_multiply); - table->file->write_row(table->record[0]); + if (schema_table_store_record(thd, table)) + return 1; } } } @@ -2472,14 +2522,15 @@ int fill_schema_coll_charset_app(THD *thd, TABLE_LIST *tables, COND *cond) restore_record(table, s->default_values); table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs); table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs); - table->file->write_row(table->record[0]); + if (schema_table_store_record(thd, table)) + return 1; } } return 0; } -void store_schema_proc(THD *thd, TABLE *table, TABLE *proc_table, +bool store_schema_proc(THD *thd, TABLE *table, TABLE *proc_table, const char *wild, bool full_access, const char *sp_user) { String tmp_string; @@ -2493,7 +2544,7 @@ void store_schema_proc(THD *thd, TABLE *table, TABLE *proc_table, if (!full_access) full_access= !strcmp(sp_user, definer); if (!full_access && check_some_routine_access(thd, sp_db, sp_name)) - return; + return 0; if (lex->orig_sql_command == SQLCOM_SHOW_STATUS_PROC && proc_table->field[2]->val_int() == TYPE_ENUM_PROCEDURE || @@ -2542,9 +2593,10 @@ void store_schema_proc(THD *thd, TABLE *table, TABLE *proc_table, get_field(thd->mem_root, proc_table->field[15], &tmp_string); table->field[18]->store(tmp_string.ptr(), tmp_string.length(), cs); table->field[19]->store(definer, strlen(definer), cs); - table->file->write_row(table->record[0]); + return schema_table_store_record(thd, table); } } + return 0; } @@ -2577,9 +2629,19 @@ int fill_schema_proc(THD *thd, TABLE_LIST *tables, COND *cond) res= (res == HA_ERR_END_OF_FILE) ? 0 : 1; goto err; } - store_schema_proc(thd, table, proc_table, wild, full_access, definer); + if (store_schema_proc(thd, table, proc_table, wild, full_access, definer)) + { + res= 1; + goto err; + } while (!proc_table->file->index_next(proc_table->record[0])) - store_schema_proc(thd, table, proc_table, wild, full_access, definer); + { + if (store_schema_proc(thd, table, proc_table, wild, full_access, definer)) + { + res= 1; + goto err; + } + } err: proc_table->file->ha_index_end(); @@ -2669,7 +2731,8 @@ static int get_schema_stat_record(THD *thd, struct st_table_list *tables, else table->field[14]->store("", 0, cs); table->field[14]->set_notnull(); - table->file->write_row(table->record[0]); + if (schema_table_store_record(thd, table)) + DBUG_RETURN(1); } } } @@ -2708,7 +2771,7 @@ static int get_schema_views_record(THD *thd, struct st_table_list *tables, table->field[5]->store("YES", 3, cs); else table->field[5]->store("NO", 2, cs); - table->file->write_row(table->record[0]); + DBUG_RETURN(schema_table_store_record(thd, table)); } } else @@ -2722,9 +2785,9 @@ static int get_schema_views_record(THD *thd, struct st_table_list *tables, } -void store_constraints(TABLE *table, const char*db, const char *tname, - const char *key_name, uint key_len, - const char *con_type, uint con_len) +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) { CHARSET_INFO *cs= system_charset_info; restore_record(table, s->default_values); @@ -2733,7 +2796,7 @@ void store_constraints(TABLE *table, const char*db, const char *tname, table->field[3]->store(db, strlen(db), cs); table->field[4]->store(tname, strlen(tname), cs); table->field[5]->store(con_type, con_len, cs); - table->file->write_row(table->record[0]); + return schema_table_store_record(thd, table); } @@ -2766,11 +2829,17 @@ static int get_schema_constraints_record(THD *thd, struct st_table_list *tables, continue; if (i == primary_key && !strcmp(key_info->name, primary_key_name)) - store_constraints(table, base_name, file_name, key_info->name, - strlen(key_info->name), "PRIMARY KEY", 11); + { + if (store_constraints(thd, table, base_name, file_name, key_info->name, + strlen(key_info->name), "PRIMARY KEY", 11)) + DBUG_RETURN(1); + } else if (key_info->flags & HA_NOSAME) - store_constraints(table, base_name, file_name, key_info->name, - strlen(key_info->name), "UNIQUE", 6); + { + if (store_constraints(thd, table, base_name, file_name, key_info->name, + strlen(key_info->name), "UNIQUE", 6)) + DBUG_RETURN(1); + } } show_table->file->get_foreign_key_list(thd, &f_key_list); @@ -2778,8 +2847,11 @@ static int get_schema_constraints_record(THD *thd, struct st_table_list *tables, List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list); while ((f_key_info=it++)) { - store_constraints(table, base_name, file_name, f_key_info->forein_id->str, - strlen(f_key_info->forein_id->str), "FOREIGN KEY", 11); + if (store_constraints(thd, table, base_name, file_name, + f_key_info->forein_id->str, + strlen(f_key_info->forein_id->str), + "FOREIGN KEY", 11)) + DBUG_RETURN(1); } } DBUG_RETURN(res); @@ -2842,7 +2914,8 @@ static int get_schema_key_column_usage_record(THD *thd, key_part->field->field_name, strlen(key_part->field->field_name), (longlong) f_idx); - table->file->write_row(table->record[0]); + if (schema_table_store_record(thd, table)) + DBUG_RETURN(1); } } } @@ -2868,7 +2941,8 @@ static int get_schema_key_column_usage_record(THD *thd, (longlong) f_idx); table->field[8]->store((longlong) f_idx); table->field[8]->set_notnull(); - table->file->write_row(table->record[0]); + if (schema_table_store_record(thd, table)) + DBUG_RETURN(1); } } } @@ -2893,7 +2967,8 @@ int fill_open_tables(THD *thd, TABLE_LIST *tables, COND *cond) table->field[1]->store(open_list->table, strlen(open_list->table), cs); table->field[2]->store((longlong) open_list->in_use); table->field[3]->store((longlong) open_list->locked); - table->file->write_row(table->record[0]); + if (schema_table_store_record(thd, table)) + DBUG_RETURN(1); } DBUG_RETURN(0); } @@ -3034,6 +3109,7 @@ TABLE *create_schema_table(THD *thd, TABLE_LIST *table_list) TMP_TABLE_ALL_COLUMNS), HA_POS_ERROR, table_list->alias))) DBUG_RETURN(0); + table_list->schema_table_param= tmp_table_param; DBUG_RETURN(table); } |