mirror of
https://github.com/MariaDB/server.git
synced 2025-12-24 11:21:21 +03:00
Added procedures to delete records by keys from statistical tables.
Now when a table is dropped the statistics on the table is removed from the statistical tables. If the table is altered in such a way that a column is dropped or the type of the column is changed then statistics on the column is removed from the table column_stat. It also triggers removal of the statistics on the indexes who use this column as its component. Added procedures that changes the names of the tables or columns in the statistical tables for. These procedures are used when tables/columns are renamed. Also partly re-factored the code that introduced the persistent statistical tables. Added test cases into statistics.test to cover the new code.
This commit is contained in:
@@ -1878,6 +1878,17 @@ bool mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists,
|
||||
}
|
||||
}
|
||||
|
||||
if (!in_bootstrap)
|
||||
{
|
||||
for (table= tables; table; table= table->next_local)
|
||||
{
|
||||
LEX_STRING db_name= { table->db, table->db_length };
|
||||
LEX_STRING table_name= { table->table_name, table->table_name_length };
|
||||
if (table->open_type == OT_BASE_ONLY || !find_temporary_table(thd, table))
|
||||
(void) delete_statistics_for_table(thd, &db_name, &table_name);
|
||||
}
|
||||
}
|
||||
|
||||
mysql_ha_rm_tables(thd, tables);
|
||||
|
||||
if (!drop_temporary)
|
||||
@@ -1888,6 +1899,7 @@ bool mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists,
|
||||
MYSQL_OPEN_SKIP_TEMPORARY))
|
||||
DBUG_RETURN(true);
|
||||
for (table= tables; table; table= table->next_local)
|
||||
|
||||
tdc_remove_table(thd, TDC_RT_REMOVE_ALL, table->db, table->table_name,
|
||||
false);
|
||||
}
|
||||
@@ -5084,6 +5096,21 @@ mysql_compare_tables(TABLE *table,
|
||||
thd->calloc(sizeof(void*) * table->s->keys)) == NULL)
|
||||
DBUG_RETURN(1);
|
||||
|
||||
tmp_new_field_it.init(tmp_alter_info.create_list);
|
||||
for (i= 0, f_ptr= table->field, tmp_new_field= tmp_new_field_it++;
|
||||
(field= *f_ptr);
|
||||
i++, f_ptr++, tmp_new_field= tmp_new_field_it++)
|
||||
{
|
||||
if (field->is_equal(tmp_new_field) == IS_EQUAL_NO &&
|
||||
table->s->tmp_table == NO_TMP_TABLE)
|
||||
(void) delete_statistics_for_column(thd, table, field);
|
||||
else if (my_strcasecmp(system_charset_info,
|
||||
field->field_name,
|
||||
tmp_new_field->field_name))
|
||||
(void) rename_column_in_stat_tables(thd, table, field,
|
||||
tmp_new_field->field_name);
|
||||
}
|
||||
|
||||
/*
|
||||
Use transformed info to evaluate possibility of in-place ALTER TABLE
|
||||
but use the preserved field to persist modifications.
|
||||
@@ -5144,7 +5171,12 @@ mysql_compare_tables(TABLE *table,
|
||||
if (my_strcasecmp(system_charset_info,
|
||||
field->field_name,
|
||||
tmp_new_field->field_name))
|
||||
field->flags|= FIELD_IS_RENAMED;
|
||||
{
|
||||
field->flags|= FIELD_IS_RENAMED;
|
||||
if (table->s->tmp_table == NO_TMP_TABLE)
|
||||
rename_column_in_stat_tables(thd, table, field,
|
||||
tmp_new_field->field_name);
|
||||
}
|
||||
|
||||
/* Evaluate changes bitmap and send to check_if_incompatible_data() */
|
||||
if (!(tmp= field->is_equal(tmp_new_field)))
|
||||
@@ -5247,6 +5279,8 @@ mysql_compare_tables(TABLE *table,
|
||||
field= table->field[key_part->fieldnr];
|
||||
field->flags|= FIELD_IN_ADD_INDEX;
|
||||
}
|
||||
if (table->s->tmp_table == NO_TMP_TABLE)
|
||||
(void) delete_statistics_for_index(thd, table, table_key);
|
||||
DBUG_PRINT("info", ("index changed: '%s'", table_key->name));
|
||||
}
|
||||
/*end of for (; table_key < table_key_end;) */
|
||||
@@ -5504,6 +5538,8 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
|
||||
}
|
||||
if (drop)
|
||||
{
|
||||
if (table->s->tmp_table == NO_TMP_TABLE)
|
||||
(void) delete_statistics_for_column(thd, table, field);
|
||||
drop_it.remove();
|
||||
/*
|
||||
ALTER TABLE DROP COLUMN always changes table data even in cases
|
||||
@@ -5656,12 +5692,15 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
|
||||
}
|
||||
if (drop)
|
||||
{
|
||||
if (table->s->tmp_table == NO_TMP_TABLE)
|
||||
(void) delete_statistics_for_index(thd, table, key_info);
|
||||
drop_it.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
KEY_PART_INFO *key_part= key_info->key_part;
|
||||
key_parts.empty();
|
||||
bool delete_index_stat= FALSE;
|
||||
for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
|
||||
{
|
||||
if (!key_part->field)
|
||||
@@ -5684,7 +5723,10 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
|
||||
break;
|
||||
}
|
||||
if (!cfield)
|
||||
{
|
||||
delete_index_stat= TRUE;
|
||||
continue; // Field is removed
|
||||
}
|
||||
key_part_length= key_part->length;
|
||||
if (cfield->field) // Not new field
|
||||
{
|
||||
@@ -5726,6 +5768,8 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
|
||||
strlen(cfield->field_name),
|
||||
key_part_length));
|
||||
}
|
||||
if (delete_index_stat && table->s->tmp_table == NO_TMP_TABLE)
|
||||
(void) delete_statistics_for_index(thd, table, key_info);
|
||||
if (key_parts.elements)
|
||||
{
|
||||
KEY_CREATE_INFO key_create_info;
|
||||
@@ -5905,6 +5949,9 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
|
||||
enum ha_extra_function extra_func= thd->locked_tables_mode
|
||||
? HA_EXTRA_NOT_USED
|
||||
: HA_EXTRA_FORCE_REOPEN;
|
||||
LEX_STRING old_db_name= { table_list->db, table_list->db_length };
|
||||
LEX_STRING old_table_name= { table_list->table_name,
|
||||
table_list->table_name_length };
|
||||
DBUG_ENTER("mysql_alter_table");
|
||||
|
||||
/*
|
||||
@@ -6209,6 +6256,12 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
|
||||
else
|
||||
{
|
||||
*fn_ext(new_name)=0;
|
||||
|
||||
LEX_STRING new_db_name= { new_db, strlen(new_db) };
|
||||
LEX_STRING new_table_name= { new_alias, strlen(new_alias) };
|
||||
(void) rename_table_in_stat_tables(thd, &old_db_name, &old_table_name,
|
||||
&new_db_name, &new_table_name);
|
||||
|
||||
if (mysql_rename_table(old_db_type,db,table_name,new_db,new_alias, 0))
|
||||
error= -1;
|
||||
else if (Table_triggers_list::change_table_name(thd, db,
|
||||
@@ -6920,6 +6973,15 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
|
||||
table is renamed and the SE is also changed, then an intermediate table
|
||||
is created and the additional call will not take place.
|
||||
*/
|
||||
|
||||
if (new_name != table_name || new_db != db)
|
||||
{
|
||||
LEX_STRING new_db_name= { new_db, strlen(new_db) };
|
||||
LEX_STRING new_table_name= { new_name, strlen(new_name) };
|
||||
(void) rename_table_in_stat_tables(thd, &old_db_name, &old_table_name,
|
||||
&new_db_name, &new_table_name);
|
||||
}
|
||||
|
||||
if (need_copy_table == ALTER_TABLE_METADATA_ONLY)
|
||||
{
|
||||
DBUG_ASSERT(new_db_type == old_db_type);
|
||||
|
||||
Reference in New Issue
Block a user