1
0
mirror of https://github.com/MariaDB/server.git synced 2025-09-11 05:52:26 +03:00

Table definition cache, part 2

The table opening process now works the following way:
- Create common TABLE_SHARE object
- Read the .frm file and unpack it into the TABLE_SHARE object
- Create a TABLE object based on the information in the TABLE_SHARE
  object and open a handler to the table object

Other noteworthy changes:
- In TABLE_SHARE the most common strings are now LEX_STRING's
- Better error message when table is not found
- Variable table_cache is now renamed 'table_open_cache'
- New variable 'table_definition_cache' that is the number of table defintions that will be cached
- strxnmov() calls are now fixed to avoid overflows
- strxnmov() will now always add one end \0 to result
- engine objects are now created with a TABLE_SHARE object instead of a TABLE object.
- After creating a field object one must call field->init(table) before using it

- For a busy system this change will give you:
 - Less memory usage for table object
 - Faster opening of tables (if it's has been in use or is in table definition cache)
 - Allow you to cache many table definitions objects
 - Faster drop of table
This commit is contained in:
monty@mysql.com
2005-11-23 22:45:02 +02:00
parent b167a6679b
commit e42c980967
100 changed files with 3655 additions and 2121 deletions

View File

@@ -175,7 +175,7 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
}
/* We do not allow creation of triggers on temporary tables. */
if (create && find_temporary_table(thd, tables->db, tables->table_name))
if (create && find_temporary_table(thd, tables))
{
my_error(ER_TRG_ON_VIEW_OR_TEMP_TABLE, MYF(0), tables->alias);
DBUG_RETURN(TRUE);
@@ -294,7 +294,7 @@ bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables,
/* Trigger must be in the same schema as target table. */
if (my_strcasecmp(table_alias_charset, table->s->db,
if (my_strcasecmp(table_alias_charset, table->s->db.str,
lex->spname->m_db.str ? lex->spname->m_db.str :
thd->db))
{
@@ -364,17 +364,17 @@ bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables,
sql_create_definition_file() files handles renaming and backup of older
versions
*/
strxnmov(dir_buff, FN_REFLEN, mysql_data_home, "/", tables->db, "/", NullS);
strxnmov(dir_buff, FN_REFLEN-1, mysql_data_home, "/", tables->db, "/", NullS);
dir.length= unpack_filename(dir_buff, dir_buff);
dir.str= dir_buff;
file.length= strxnmov(file_buff, FN_REFLEN, tables->table_name,
file.length= strxnmov(file_buff, FN_REFLEN-1, tables->table_name,
triggers_file_ext, NullS) - file_buff;
file.str= file_buff;
trigname_file.length= strxnmov(trigname_buff, FN_REFLEN,
trigname_file.length= strxnmov(trigname_buff, FN_REFLEN-1,
lex->spname->m_name.str,
trigname_file_ext, NullS) - trigname_buff;
trigname_file.str= trigname_buff;
strxnmov(trigname_path, FN_REFLEN, dir_buff, trigname_buff, NullS);
strxnmov(trigname_path, FN_REFLEN-1, dir_buff, trigname_buff, NullS);
/* Use the filesystem to enforce trigger namespace constraints. */
if (!access(trigname_path, F_OK))
@@ -461,7 +461,7 @@ err_with_cleanup:
static bool rm_trigger_file(char *path, char *db, char *table_name)
{
strxnmov(path, FN_REFLEN, mysql_data_home, "/", db, "/", table_name,
strxnmov(path, FN_REFLEN-1, mysql_data_home, "/", db, "/", table_name,
triggers_file_ext, NullS);
unpack_filename(path, path);
return my_delete(path, MYF(MY_WME));
@@ -485,7 +485,7 @@ static bool rm_trigger_file(char *path, char *db, char *table_name)
static bool rm_trigname_file(char *path, char *db, char *trigger_name)
{
strxnmov(path, FN_REFLEN, mysql_data_home, "/", db, "/", trigger_name,
strxnmov(path, FN_REFLEN-1, mysql_data_home, "/", db, "/", trigger_name,
trigname_file_ext, NullS);
unpack_filename(path, path);
return my_delete(path, MYF(MY_WME));
@@ -548,11 +548,11 @@ bool Table_triggers_list::drop_trigger(THD *thd, TABLE_LIST *tables)
char dir_buff[FN_REFLEN], file_buff[FN_REFLEN];
LEX_STRING dir, file;
strxnmov(dir_buff, FN_REFLEN, mysql_data_home, "/", tables->db,
strxnmov(dir_buff, FN_REFLEN-1, mysql_data_home, "/", tables->db,
"/", NullS);
dir.length= unpack_filename(dir_buff, dir_buff);
dir.str= dir_buff;
file.length= strxnmov(file_buff, FN_REFLEN, tables->table_name,
file.length= strxnmov(file_buff, FN_REFLEN-1, tables->table_name,
triggers_file_ext, NullS) - file_buff;
file.str= file_buff;
@@ -615,7 +615,7 @@ bool Table_triggers_list::prepare_record1_accessors(TABLE *table)
*/
if (!(*old_fld= (*fld)->new_field(&table->mem_root, table)))
return 1;
(*old_fld)->move_field((my_ptrdiff_t)(table->record[1] -
(*old_fld)->move_field_offset((my_ptrdiff_t)(table->record[1] -
table->record[0]));
}
*old_fld= 0;
@@ -670,7 +670,7 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db,
DBUG_ENTER("Table_triggers_list::check_n_load");
strxnmov(path_buff, FN_REFLEN, mysql_data_home, "/", db, "/", table_name,
strxnmov(path_buff, FN_REFLEN-1, mysql_data_home, "/", db, "/", table_name,
triggers_file_ext, NullS);
path.length= unpack_filename(path_buff, path_buff);
path.str= path_buff;
@@ -755,7 +755,7 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db,
sizeof(LEX_STRING))))
DBUG_RETURN(1); // EOM
trg_definer->str= "";
trg_definer->str= (char*) "";
trg_definer->length= 0;
while (it++)
@@ -848,7 +848,7 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db,
schema.
*/
lex.sphead->set_definer("", 0);
lex.sphead->set_definer((char*) "", 0);
/*
Triggers without definer information are executed under the
@@ -998,7 +998,7 @@ static TABLE_LIST *add_table_for_trigger(THD *thd, sp_name *trig)
struct st_trigname trigname;
DBUG_ENTER("add_table_for_trigger");
strxnmov(path_buff, FN_REFLEN, mysql_data_home, "/", db, "/",
strxnmov(path_buff, FN_REFLEN-1, mysql_data_home, "/", db, "/",
trig->m_name.str, trigname_file_ext, NullS);
path.length= unpack_filename(path_buff, path_buff);
path.str= path_buff;
@@ -1145,10 +1145,10 @@ bool Table_triggers_list::process_triggers(THD *thd, trg_event_type event,
{
TABLE_LIST table_list;
bzero((char *) &table_list, sizeof (table_list));
table_list.db= (char *) table->s->db;
table_list.db_length= strlen(table_list.db);
table_list.table_name= (char *) table->s->table_name;
table_list.table_name_length= strlen(table_list.table_name);
table_list.db= (char *) table->s->db.str;
table_list.db_length= table->s->db.length;
table_list.table_name= table->s->table_name.str;
table_list.table_name_length= table->s->table_name.length;
table_list.alias= (char *) table->alias;
table_list.table= table;