Skip to content

Commit e25abdd

Browse files
MDEV-31740 InnoDB statistics column length validation failed
When there's a column length mismatch in the InnoDB statistics tables (innodb_table_stats or innodb_index_stats), consecutive access of statistics table throws error message and uses transient statistics. This change makes it easier for users to understand and resolve the issue when the statistics tables have been modified or corrupted.
1 parent d891d23 commit e25abdd

File tree

7 files changed

+40
-10
lines changed

7 files changed

+40
-10
lines changed

mysql-test/main/mysql_upgrade.result

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2518,7 +2518,8 @@ name dl
25182518
# Check that mysql_upgrade can be run on mysqldump
25192519
# of mysql schema from previous versions
25202520
#
2521-
call mtr.add_suppression("innodb_(table|index)_stats has length mismatch in the column name table_name");
2521+
call mtr.add_suppression("InnoDB: Fetch of persistent statistics requested for table `mysql`\\.`gtid_slave_pos` but the required system tables mysql\\.innodb_table_stats and mysql\\.innodb_index_stats are not present or have unexpected structure");
2522+
call mtr.add_suppression("InnoDB: Unexpected length of mysql\\.innodb_table_stats\\.table_name");
25222523
call mtr.add_suppression("Column count of mysql.proc is wrong. Expected 21, found 20.");
25232524
#
25242525
# Upgrade from version 5.5

mysql-test/main/mysql_upgrade.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,8 @@ SELECT * FROM mysql.plugin WHERE name='unix_socket';
526526
--echo #
527527

528528
# The warning appears during mysql_upgrade, before the schema becomes consistent
529-
call mtr.add_suppression("innodb_(table|index)_stats has length mismatch in the column name table_name");
529+
call mtr.add_suppression("InnoDB: Fetch of persistent statistics requested for table `mysql`\\.`gtid_slave_pos` but the required system tables mysql\\.innodb_table_stats and mysql\\.innodb_index_stats are not present or have unexpected structure");
530+
call mtr.add_suppression("InnoDB: Unexpected length of mysql\\.innodb_table_stats\\.table_name");
530531
# This comes from opening 10.6 sys.host_summary view that uses sys.format_time function,
531532
# on still inconsistent mysql.proc, in older versions
532533
call mtr.add_suppression("Column count of mysql.proc is wrong. Expected 21, found 20.");

mysql-test/suite/innodb/r/innodb_stats.result

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,3 +530,16 @@ INDEX_TYPE BTREE
530530
COMMENT
531531
INDEX_COMMENT
532532
IGNORED NO
533+
#
534+
# MDEV-31740 InnoDB statistics column length validation failed
535+
#
536+
call mtr.add_suppression("InnoDB: Unexpected length of mysql\\.innodb_table_stats\\.last_update");
537+
ALTER TABLE mysql.innodb_table_stats MODIFY LAST_UPDATE DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP() ON UPDATE CURRENT_TIMESTAMP();
538+
CREATE TABLE t (a INT KEY)Engine=InnoDB STATS_PERSISTENT=1;
539+
FOUND 1 /InnoDB: Unexpected length of mysql\.innodb_table_stats\.last_update/ in mysqld.1.err
540+
ALTER TABLE mysql.innodb_table_stats MODIFY last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP() ON UPDATE CURRENT_TIMESTAMP();
541+
CREATE TABLE t2(a INT KEY)ENGINE=InnoDB STATS_PERSISTENT= 1;
542+
SELECT table_name FROM mysql.innodb_table_stats;
543+
table_name
544+
t2
545+
DROP TABLE t, t2;

mysql-test/suite/innodb/r/innodb_stats_create_on_corrupted.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
call mtr.add_suppression("InnoDB: Table .*innodb_index_stats.* not found");
22
call mtr.add_suppression("InnoDB: Fetch of persistent statistics requested for table .*");
3-
call mtr.add_suppression("InnoDB: Table mysql\\.innodb_index_stats has length mismatch in the column name stat_description\\. Please run mariadb-upgrade");
3+
call mtr.add_suppression("InnoDB: Unexpected length of mysql\\.innodb_index_stats\\.stat_description");
44
call mtr.add_suppression("InnoDB: Column stat_description in table mysql\\.innodb_index_stats is VARCHAR");
55
ALTER TABLE mysql.innodb_index_stats RENAME TO mysql.innodb_index_stats_;
66
CREATE TABLE test_ps_create_on_corrupted

mysql-test/suite/innodb/t/innodb_stats.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#
44

55
-- source include/have_innodb.inc
6+
-- source include/not_embedded.inc
67

78
-- disable_warnings
89
-- disable_query_log
@@ -63,3 +64,17 @@ CREATE TABLE test_innodb_stats (
6364
-- disable_query_log
6465
DROP TABLE test_innodb_stats;
6566
set @@use_stat_tables= @save_use_stat_tables;
67+
--enable_query_log
68+
--echo #
69+
--echo # MDEV-31740 InnoDB statistics column length validation failed
70+
--echo #
71+
call mtr.add_suppression("InnoDB: Unexpected length of mysql\\.innodb_table_stats\\.last_update");
72+
ALTER TABLE mysql.innodb_table_stats MODIFY LAST_UPDATE DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP() ON UPDATE CURRENT_TIMESTAMP();
73+
CREATE TABLE t (a INT KEY)Engine=InnoDB STATS_PERSISTENT=1;
74+
let SEARCH_FILE=$MYSQLTEST_VARDIR/log/mysqld.1.err;
75+
let SEARCH_PATTERN=InnoDB: Unexpected length of mysql\\.innodb_table_stats\\.last_update;
76+
--source include/search_pattern_in_file.inc
77+
ALTER TABLE mysql.innodb_table_stats MODIFY last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP() ON UPDATE CURRENT_TIMESTAMP();
78+
CREATE TABLE t2(a INT KEY)ENGINE=InnoDB STATS_PERSISTENT= 1;
79+
SELECT table_name FROM mysql.innodb_table_stats;
80+
DROP TABLE t, t2;

mysql-test/suite/innodb/t/innodb_stats_create_on_corrupted.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
call mtr.add_suppression("InnoDB: Table .*innodb_index_stats.* not found");
1414
call mtr.add_suppression("InnoDB: Fetch of persistent statistics requested for table .*");
15-
call mtr.add_suppression("InnoDB: Table mysql\\.innodb_index_stats has length mismatch in the column name stat_description\\. Please run mariadb-upgrade");
15+
call mtr.add_suppression("InnoDB: Unexpected length of mysql\\.innodb_index_stats\\.stat_description");
1616
call mtr.add_suppression("InnoDB: Column stat_description in table mysql\\.innodb_index_stats is VARCHAR");
1717

1818
-- vertical_results

storage/innobase/dict/dict0stats.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -430,12 +430,12 @@ dict_table_schema_check(
430430

431431
/* check length for exact match */
432432
if (req_schema->columns[i].len != table->cols[j].len) {
433-
sql_print_warning("InnoDB: Table %s has"
434-
" length mismatch in the"
435-
" column name %s."
436-
" Please run mariadb-upgrade",
437-
req_schema->table_name_sql,
438-
req_schema->columns[i].name);
433+
snprintf(errstr, errstr_sz,
434+
"Unexpected length of %s.%s. Please run "
435+
"mariadb-upgrade or ALTER TABLE",
436+
req_schema->table_name_sql,
437+
req_schema->columns[i].name);
438+
return DB_ERROR;
439439
}
440440

441441
/*

0 commit comments

Comments
 (0)