Commit e06cc1ad authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-4758 10.0-monty tree: ALTER TABLE CHANGE COLUMN doesn't drop EITS stats

add missing rename_column_in_stat_tables(), delete_statistics_for_column(),
delete_statistics_for_index(), rename_table_in_stat_tables() calls.
parent c3e3c780
...@@ -1072,9 +1072,19 @@ test t2 idx4 4 1.0000 ...@@ -1072,9 +1072,19 @@ test t2 idx4 4 1.0000
ALTER TABLE t2 CHANGE COLUMN b b varchar(32); ALTER TABLE t2 CHANGE COLUMN b b varchar(32);
SELECT * FROM mysql.index_stats ORDER BY index_name, prefix_arity, table_name; SELECT * FROM mysql.index_stats ORDER BY index_name, prefix_arity, table_name;
db_name table_name index_name prefix_arity avg_frequency db_name table_name index_name prefix_arity avg_frequency
test t2 PRIMARY 1 1.0000
test t2 PRIMARY 2 1.0000
test t2 idx2 1 7.0000 test t2 idx2 1 7.0000
test t2 idx2 2 2.3846 test t2 idx2 2 2.3846
test t2 idx2 3 1.0000
test t2 idx2 4 1.0000
test t2 idx3 1 8.5000 test t2 idx3 1 8.5000
test t2 idx3 2 1.0000
test t2 idx3 3 1.0000
test t2 idx4 1 6.2000
test t2 idx4 2 1.7222
test t2 idx4 3 1.1154
test t2 idx4 4 1.0000
ANALYZE TABLE t2 PERSISTENT FOR COLUMNS ALL INDEXES ALL; ANALYZE TABLE t2 PERSISTENT FOR COLUMNS ALL INDEXES ALL;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.t2 analyze status OK test.t2 analyze status OK
...@@ -1131,13 +1141,13 @@ test t2 f 1 5 0.2000 1.0000 6.4000 ...@@ -1131,13 +1141,13 @@ test t2 f 1 5 0.2000 1.0000 6.4000
SELECT * FROM mysql.index_stats; SELECT * FROM mysql.index_stats;
db_name table_name index_name prefix_arity avg_frequency db_name table_name index_name prefix_arity avg_frequency
test t2 idx3 1 8.5000 test t2 idx3 1 8.5000
test t2 idx3 2 1.0000
test t2 idx2 3 1.0000
test t2 idx2 1 7.0000 test t2 idx2 1 7.0000
test t2 idx2 2 2.3846 test t2 idx2 2 2.3846
test t2 idx4 3 1.0000 test t2 idx2 3 1.0000
test t2 idx4 1 6.2000 test t2 idx4 1 6.2000
test t2 idx4 2 2.2308 test t2 idx4 2 2.2308
test t2 idx4 3 1.0000
test t2 idx3 2 1.0000
test t2 PRIMARY 1 1.0000 test t2 PRIMARY 1 1.0000
ANALYZE TABLE t1; ANALYZE TABLE t1;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
...@@ -1157,17 +1167,17 @@ test t1 f 1 5 0.2000 1.0000 6.4000 ...@@ -1157,17 +1167,17 @@ test t1 f 1 5 0.2000 1.0000 6.4000
test t1 b NULL NULL 0.2000 17.1250 NULL test t1 b NULL NULL 0.2000 17.1250 NULL
SELECT * FROM mysql.index_stats; SELECT * FROM mysql.index_stats;
db_name table_name index_name prefix_arity avg_frequency db_name table_name index_name prefix_arity avg_frequency
test t2 idx3 1 8.5000
test t2 idx3 2 1.0000
test t2 idx2 3 1.0000
test t2 idx2 1 7.0000
test t2 idx2 2 2.3846
test t1 idx2 1 7.0000 test t1 idx2 1 7.0000
test t2 idx3 1 8.5000
test t1 idx3 1 8.5000 test t1 idx3 1 8.5000
test t1 PRIMARY 1 1.0000 test t1 PRIMARY 1 1.0000
test t2 idx4 3 1.0000 test t2 idx2 1 7.0000
test t2 idx2 2 2.3846
test t2 idx2 3 1.0000
test t2 idx4 1 6.2000 test t2 idx4 1 6.2000
test t2 idx4 2 2.2308 test t2 idx4 2 2.2308
test t2 idx4 3 1.0000
test t2 idx3 2 1.0000
test t2 PRIMARY 1 1.0000 test t2 PRIMARY 1 1.0000
test t1 idx2 2 2.3846 test t1 idx2 2 2.3846
test t1 idx1 1 NULL test t1 idx1 1 NULL
......
...@@ -2990,7 +2990,10 @@ int rename_column_in_stat_tables(THD *thd, TABLE *tab, Field *col, ...@@ -2990,7 +2990,10 @@ int rename_column_in_stat_tables(THD *thd, TABLE *tab, Field *col,
int rc= 0; int rc= 0;
DBUG_ENTER("rename_column_in_stat_tables"); DBUG_ENTER("rename_column_in_stat_tables");
if (tab->s->tmp_table != NO_TMP_TABLE)
DBUG_RETURN(0);
if (open_single_stat_table(thd, &tables, &stat_table_name[1], if (open_single_stat_table(thd, &tables, &stat_table_name[1],
&open_tables_backup, TRUE)) &open_tables_backup, TRUE))
{ {
......
...@@ -93,6 +93,17 @@ void set_statistics_for_table(THD *thd, TABLE *table); ...@@ -93,6 +93,17 @@ void set_statistics_for_table(THD *thd, TABLE *table);
class Columns_statistics; class Columns_statistics;
class Index_statistics; class Index_statistics;
static inline
int rename_table_in_stat_tables(THD *thd, const char *db, const char *tab,
const char *new_db, const char *new_tab)
{
LEX_STRING od= { const_cast<char*>(db), strlen(db) };
LEX_STRING ot= { const_cast<char*>(tab), strlen(tab) };
LEX_STRING nd= { const_cast<char*>(new_db), strlen(new_db) };
LEX_STRING nt= { const_cast<char*>(new_tab), strlen(new_tab) };
return rename_table_in_stat_tables(thd, &od, &ot, &nd, &nt);
}
/* Statistical data on a table */ /* Statistical data on a table */
......
...@@ -5432,6 +5432,27 @@ static bool fill_alter_inplace_info(THD *thd, ...@@ -5432,6 +5432,27 @@ static bool fill_alter_inplace_info(THD *thd,
case IS_EQUAL_NO: case IS_EQUAL_NO:
/* New column type is incompatible with old one. */ /* New column type is incompatible with old one. */
ha_alter_info->handler_flags|= Alter_inplace_info::ALTER_COLUMN_TYPE; ha_alter_info->handler_flags|= Alter_inplace_info::ALTER_COLUMN_TYPE;
if (table->s->tmp_table == NO_TMP_TABLE)
{
delete_statistics_for_column(thd, table, field);
KEY *key_info= table->key_info;
for (uint i=0; i < table->s->keys; i++, key_info++)
{
if (field->part_of_key.is_set(i))
{
uint key_parts= table->actual_n_key_parts(key_info);
for (uint j= 0; j < key_parts; j++)
{
if (key_info->key_part[j].fieldnr-1 == field->field_index)
{
delete_statistics_for_index(thd, table, key_info,
j >= key_info->user_defined_key_parts);
break;
}
}
}
}
}
break; break;
case IS_EQUAL_YES: case IS_EQUAL_YES:
/* /*
...@@ -5464,6 +5485,8 @@ static bool fill_alter_inplace_info(THD *thd, ...@@ -5464,6 +5485,8 @@ static bool fill_alter_inplace_info(THD *thd,
{ {
field->flags|= FIELD_IS_RENAMED; field->flags|= FIELD_IS_RENAMED;
ha_alter_info->handler_flags|= Alter_inplace_info::ALTER_COLUMN_NAME; ha_alter_info->handler_flags|= Alter_inplace_info::ALTER_COLUMN_NAME;
rename_column_in_stat_tables(thd, table, field,
new_field->field_name);
} }
/* Check that NULL behavior is same for old and new fields */ /* Check that NULL behavior is same for old and new fields */
...@@ -6352,6 +6375,8 @@ static bool mysql_inplace_alter_table(THD *thd, ...@@ -6352,6 +6375,8 @@ static bool mysql_inplace_alter_table(THD *thd,
alter_ctx->db, alter_ctx->alias, 0); alter_ctx->db, alter_ctx->alias, 0);
DBUG_RETURN(true); DBUG_RETURN(true);
} }
rename_table_in_stat_tables(thd, alter_ctx->db,alter_ctx->alias,
alter_ctx->new_db, alter_ctx->new_alias);
} }
DBUG_RETURN(false); DBUG_RETURN(false);
...@@ -8205,21 +8230,25 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, ...@@ -8205,21 +8230,25 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
} }
// Check if we renamed the table and if so update trigger files. // Check if we renamed the table and if so update trigger files.
if (alter_ctx.is_table_renamed() && if (alter_ctx.is_table_renamed())
Table_triggers_list::change_table_name(thd,
alter_ctx.db,
alter_ctx.alias,
alter_ctx.table_name,
alter_ctx.new_db,
alter_ctx.new_alias))
{ {
// Rename succeeded, delete the new table. if (Table_triggers_list::change_table_name(thd,
(void) quick_rm_table(thd, new_db_type, alter_ctx.db,
alter_ctx.new_db, alter_ctx.new_alias, 0); alter_ctx.alias,
// Restore the backup of the original table to the old name. alter_ctx.table_name,
(void) mysql_rename_table(old_db_type, alter_ctx.db, backup_name, alter_ctx.new_db,
alter_ctx.db, alter_ctx.alias, FN_FROM_IS_TMP); alter_ctx.new_alias))
goto err_with_mdl; {
// Rename succeeded, delete the new table.
(void) quick_rm_table(thd, new_db_type,
alter_ctx.new_db, alter_ctx.new_alias, 0);
// Restore the backup of the original table to the old name.
(void) mysql_rename_table(old_db_type, alter_ctx.db, backup_name,
alter_ctx.db, alter_ctx.alias, FN_FROM_IS_TMP);
goto err_with_mdl;
}
rename_table_in_stat_tables(thd, alter_ctx.db,alter_ctx.alias,
alter_ctx.new_db, alter_ctx.new_alias);
} }
// ALTER TABLE succeeded, delete the backup of the old table. // ALTER TABLE succeeded, delete the backup of the old table.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment