Commit 8aef7f2b authored by Varun Gupta's avatar Varun Gupta

MDEV-17778: Alter table leads to a truncation warning with ANALYZE command

Alter statement changed the THD structure by setting the value to FIELD_CHECK_WARN
and then not resetting it back. This led ANALYZE to throw a warning which previously
it didn't.
parent a7251634
Branches unavailable
Tags unavailable
No related merge requests found
...@@ -2469,3 +2469,24 @@ DROP TABLE t1; ...@@ -2469,3 +2469,24 @@ DROP TABLE t1;
# #
# End of 10.2 tests # End of 10.2 tests
# #
#
# MDEV-17778: Alter table leads to a truncation warning with ANALYZE command
#
set @save_use_stat_tables= @@use_stat_tables;
set @save_optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;
set @@optimizer_use_condition_selectivity=4;
set @@use_stat_tables=PREFERABLY;
create table t1 (a int)engine=InnoDB;
insert into t1 values (1),(1),(2),(3);
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status OK
alter table t1 change a b int;
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status OK
set @@use_stat_tables= @save_use_stat_tables;
set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
drop table t1;
...@@ -2021,3 +2021,22 @@ DROP TABLE t1; ...@@ -2021,3 +2021,22 @@ DROP TABLE t1;
--echo # --echo #
--echo # End of 10.2 tests --echo # End of 10.2 tests
--echo # --echo #
--echo #
--echo # MDEV-17778: Alter table leads to a truncation warning with ANALYZE command
--echo #
set @save_use_stat_tables= @@use_stat_tables;
set @save_optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity;
set @@optimizer_use_condition_selectivity=4;
set @@use_stat_tables=PREFERABLY;
create table t1 (a int)engine=InnoDB;
insert into t1 values (1),(1),(2),(3);
analyze table t1;
alter table t1 change a b int;
analyze table t1;
set @@use_stat_tables= @save_use_stat_tables;
set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
drop table t1;
...@@ -1150,7 +1150,6 @@ alter table t1 change column a a int; ...@@ -1150,7 +1150,6 @@ alter table t1 change column a a int;
analyze table t1; analyze table t1;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.t1 analyze status Engine-independent statistics collected test.t1 analyze status Engine-independent statistics collected
test.t1 analyze Note Data truncated for column 'avg_frequency' at row 1
test.t1 analyze status OK test.t1 analyze status OK
flush table t1; flush table t1;
explain extended select * from t1 where a between 5 and 7; explain extended select * from t1 where a between 5 and 7;
......
...@@ -1086,9 +1086,6 @@ test t2 idx4 3 1.1304 ...@@ -1086,9 +1086,6 @@ test t2 idx4 3 1.1304
ANALYZE TABLE t2 PERSISTENT FOR COLUMNS() INDEXES ALL; ANALYZE TABLE t2 PERSISTENT FOR COLUMNS() INDEXES ALL;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.t2 analyze status Engine-independent statistics collected test.t2 analyze status Engine-independent statistics collected
test.t2 analyze Note Data truncated for column 'avg_frequency' at row 1
test.t2 analyze Note Data truncated for column 'avg_frequency' at row 1
test.t2 analyze Note Data truncated for column 'avg_frequency' at row 1
test.t2 analyze status OK test.t2 analyze status OK
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
...@@ -1149,11 +1146,6 @@ test t2 idx4 4 1.0000 ...@@ -1149,11 +1146,6 @@ 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 Engine-independent statistics collected test.t2 analyze status Engine-independent statistics collected
test.t2 analyze Note Data truncated for column 'avg_length' at row 1
test.t2 analyze Note Data truncated for column 'avg_frequency' at row 1
test.t2 analyze Note Data truncated for column 'avg_frequency' at row 1
test.t2 analyze Note Data truncated for column 'avg_frequency' at row 1
test.t2 analyze Note Data truncated for column 'avg_frequency' at row 1
test.t2 analyze status OK test.t2 analyze status OK
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
...@@ -1179,8 +1171,6 @@ test t2 idx3 1 8.5000 ...@@ -1179,8 +1171,6 @@ test t2 idx3 1 8.5000
ANALYZE TABLE t2 PERSISTENT FOR COLUMNS() INDEXES ALL; ANALYZE TABLE t2 PERSISTENT FOR COLUMNS() INDEXES ALL;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.t2 analyze status Engine-independent statistics collected test.t2 analyze status Engine-independent statistics collected
test.t2 analyze Note Data truncated for column 'avg_frequency' at row 1
test.t2 analyze Note Data truncated for column 'avg_frequency' at row 1
test.t2 analyze status OK test.t2 analyze status OK
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
......
...@@ -696,8 +696,6 @@ Warning 1264 Out of range value for column 'b' at row 1 ...@@ -696,8 +696,6 @@ Warning 1264 Out of range value for column 'b' at row 1
SELECT * FROM t WHERE c = '0'; SELECT * FROM t WHERE c = '0';
a b c a b c
1 127 0 1 127 0
Warnings:
Warning 1264 Out of range value for column 'b' at row 1
DROP TABLE t; DROP TABLE t;
# #
# Bug#21688115 VIRTUAL COLUMN COMPUTATION SAVE_IN_FIELD() # Bug#21688115 VIRTUAL COLUMN COMPUTATION SAVE_IN_FIELD()
......
...@@ -7401,11 +7401,6 @@ static bool mysql_inplace_alter_table(THD *thd, ...@@ -7401,11 +7401,6 @@ static bool mysql_inplace_alter_table(THD *thd,
bool reopen_tables= false; bool reopen_tables= false;
bool res; bool res;
/*
Set the truncated column values of thd as warning
for alter table.
*/
thd->count_cuted_fields = CHECK_FIELD_WARN;
DBUG_ENTER("mysql_inplace_alter_table"); DBUG_ENTER("mysql_inplace_alter_table");
/* /*
...@@ -9694,9 +9689,16 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db, ...@@ -9694,9 +9689,16 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db,
if (use_inplace) if (use_inplace)
{ {
table->s->frm_image= &frm; table->s->frm_image= &frm;
enum_check_fields save_count_cuted_fields= thd->count_cuted_fields;
/*
Set the truncated column values of thd as warning
for alter table.
*/
thd->count_cuted_fields = CHECK_FIELD_WARN;
int res= mysql_inplace_alter_table(thd, table_list, table, altered_table, int res= mysql_inplace_alter_table(thd, table_list, table, altered_table,
&ha_alter_info, inplace_supported, &ha_alter_info, inplace_supported,
&target_mdl_request, &alter_ctx); &target_mdl_request, &alter_ctx);
thd->count_cuted_fields= save_count_cuted_fields;
my_free(const_cast<uchar*>(frm.str)); my_free(const_cast<uchar*>(frm.str));
if (res) if (res)
......
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