Commit 0f414f63 authored by Monty's avatar Monty Committed by Sergei Golubchik

MDEV-33881 Userstat skips system tables inconsistently

Fixed that no tables from 'mysql' schema are included in userstat.
A beneif of this is that the server is not reading statistics tables
if mysql.proc or other tables in mysql is accessed.
parent ab513b00
--- mysqldump-system.result
+++ mysqldump-system,win.result
@@ -449,9 +449,9 @@
@@ -1861,9 +1861,9 @@
Table Checksum
mysql.roles_mapping 2510045525
mysql.time_zone_transition 3719776009
......@@ -9,10 +9,10 @@
mysql.servers 2079085450
-mysql.func 3241572444
+mysql.func 310494789
mysql.innodb_table_stats 1285726777
mysql.table_stats 2836905944
mysql.innodb_table_stats 1972297402
mysql.table_stats 1911089388
# Opps....
@@ -484,9 +484,9 @@
@@ -1896,9 +1896,9 @@
Table Checksum
mysql.roles_mapping 2510045525
mysql.time_zone_transition 3719776009
......@@ -21,6 +21,6 @@
mysql.servers 2079085450
-mysql.func 3241572444
+mysql.func 310494789
mysql.innodb_table_stats 1285726777
mysql.table_stats 2836905944
mysql.innodb_table_stats 1972297402
mysql.table_stats 1911089388
DROP FUNCTION IF EXISTS metaphon;
This diff is collapsed.
......@@ -39,18 +39,18 @@ ALTER TABLE mysql.roles_mapping ORDER BY Host, User, Role;
# innodb and EITS tables statistics
#
set @save_innodb_stats_persistent= @@innodb_stats_persistent;
create table mysql.tz like mysql.time_zone_transition;
alter table mysql.tz engine=innodb;
insert into mysql.tz select * from mysql.time_zone_transition;
create table test.tz like mysql.time_zone_transition;
alter table test.tz engine=innodb;
insert into test.tz select * from mysql.time_zone_transition;
set global innodb_stats_persistent=1;
set time_zone="+03:00";
SET TIMESTAMP= UNIX_TIMESTAMP('2022-01-07 07:07:00');
ANALYZE TABLE mysql.tz PERSISTENT FOR ALL;
ANALYZE TABLE test.tz PERSISTENT FOR ALL;
# for predictable output in tests
delete from mysql.index_stats where prefix_arity!=1;
delete from mysql.column_stats where column_name!='Time_zone_id';
update mysql.innodb_index_stats set last_update="2020-01-01" where database_name="mysql" and table_name="tz";
update mysql.innodb_table_stats set last_update="2020-01-01" where database_name="mysql" and table_name="tz";
update mysql.innodb_index_stats set last_update="2020-01-01" where database_name="test" and table_name="tz";
update mysql.innodb_table_stats set last_update="2020-01-01" where database_name="test" and table_name="tz";
update mysql.column_stats set histogram=json_replace(histogram, '$.collected_by', replace(json_value(histogram, '$.collected_by'), @@version, 'version'));
set global innodb_stats_persistent= @save_innodb_stats_persistent;
alter table mysql.time_zone_name ORDER BY Name;
......@@ -144,12 +144,12 @@ DROP FUNCTION IF EXISTS metaphon;
DROP SERVER s1;
# EITS && innodb stats
DELETE FROM mysql.column_stats WHERE db_name='mysql' and table_name in ('tz', 'gtid_slave_pos');
DELETE FROM mysql.index_stats WHERE db_name='mysql' and table_name in ('tz', 'gtid_slave_pos');
DELETE FROM mysql.table_stats WHERE db_name='mysql' and table_name in ('tz', 'gtid_slave_pos');
DELETE FROM mysql.innodb_index_stats WHERE database_name='mysql' and table_name in ('tz','gtid_slave_pos');
DELETE FROM mysql.innodb_table_stats WHERE database_name='mysql' and table_name in ('tz','gtid_slave_pos');
drop table mysql.tz;
DELETE FROM mysql.column_stats WHERE db_name='mysql';
DELETE FROM mysql.index_stats WHERE db_name='mysql';
DELETE FROM mysql.table_stats WHERE db_name='mysql';
DELETE FROM mysql.innodb_index_stats WHERE database_name='test';
DELETE FROM mysql.innodb_table_stats WHERE database_name='mysql';
drop table test.tz;
DROP ROLE role_2;
DROP ROLE role_1;
......
......@@ -2145,11 +2145,8 @@ select Host, User from mysql.user limit 0;
Host User
show open tables from mysql;
Database Table In_use Name_locked
mysql column_stats 0 0
mysql general_log 0 0
mysql global_priv 0 0
mysql index_stats 0 0
mysql table_stats 0 0
mysql user 0 0
call proc_1();
show open tables from mysql;
......@@ -2159,11 +2156,8 @@ select Host, User from mysql.user limit 0;
Host User
show open tables from mysql;
Database Table In_use Name_locked
mysql column_stats 0 0
mysql general_log 0 0
mysql global_priv 0 0
mysql index_stats 0 0
mysql table_stats 0 0
mysql user 0 0
call proc_1();
show open tables from mysql;
......@@ -2173,11 +2167,8 @@ select Host, User from mysql.user limit 0;
Host User
show open tables from mysql;
Database Table In_use Name_locked
mysql column_stats 0 0
mysql general_log 0 0
mysql global_priv 0 0
mysql index_stats 0 0
mysql table_stats 0 0
mysql user 0 0
call proc_1();
show open tables from mysql;
......@@ -2187,11 +2178,8 @@ select Host, User from mysql.user limit 0;
Host User
show open tables from mysql;
Database Table In_use Name_locked
mysql column_stats 0 0
mysql general_log 0 0
mysql global_priv 0 0
mysql index_stats 0 0
mysql table_stats 0 0
mysql user 0 0
flush tables;
create function func_1() returns int begin flush tables; return 1; end|
......@@ -2206,11 +2194,8 @@ select Host, User from mysql.user limit 0;
Host User
show open tables from mysql;
Database Table In_use Name_locked
mysql column_stats 0 0
mysql general_log 0 0
mysql global_priv 0 0
mysql index_stats 0 0
mysql table_stats 0 0
mysql user 0 0
prepare abc from "flush tables";
execute abc;
......@@ -2221,11 +2206,8 @@ select Host, User from mysql.user limit 0;
Host User
show open tables from mysql;
Database Table In_use Name_locked
mysql column_stats 0 0
mysql general_log 0 0
mysql global_priv 0 0
mysql index_stats 0 0
mysql table_stats 0 0
mysql user 0 0
execute abc;
show open tables from mysql;
......@@ -2235,11 +2217,8 @@ select Host, User from mysql.user limit 0;
Host User
show open tables from mysql;
Database Table In_use Name_locked
mysql column_stats 0 0
mysql general_log 0 0
mysql global_priv 0 0
mysql index_stats 0 0
mysql table_stats 0 0
mysql user 0 0
execute abc;
show open tables from mysql;
......@@ -2249,11 +2228,8 @@ select Host, User from mysql.user limit 0;
Host User
show open tables from mysql;
Database Table In_use Name_locked
mysql column_stats 0 0
mysql general_log 0 0
mysql global_priv 0 0
mysql index_stats 0 0
mysql table_stats 0 0
mysql user 0 0
flush tables;
deallocate prepare abc;
......
......@@ -240,12 +240,18 @@ set @@global.general_log=@save_general_log;
#
create function f() returns int return (select 1 from performance_schema.threads);
set global userstat= 1;
create table t1 (a int primary key);
insert into t1 values (1),(2);
select * from t1 where a=1;
a
1
select f() from information_schema.table_statistics;
ERROR 21000: Subquery returns more than 1 row
select f() from information_schema.index_statistics;
ERROR 21000: Subquery returns more than 1 row
set global userstat= 0;
drop function f;
drop table t1;
#
# End of 10.2 tests
#
......
......@@ -122,12 +122,16 @@ set @@global.general_log=@save_general_log;
--echo #
create function f() returns int return (select 1 from performance_schema.threads);
set global userstat= 1;
create table t1 (a int primary key);
insert into t1 values (1),(2);
select * from t1 where a=1;
--error ER_SUBQUERY_NO_1_ROW
select f() from information_schema.table_statistics;
--error ER_SUBQUERY_NO_1_ROW
select f() from information_schema.index_statistics;
set global userstat= 0;
drop function f;
drop table t1;
--enable_ps2_protocol
--echo #
......@@ -145,7 +149,9 @@ set global userstat= 1;
create or replace table t1 (a int, key(a)) engine=MyISAM;
insert into t1 values (1),(2),(3),(4);
flush index_statistics;
--disable_ps2_protocol
select a from t1 where a in ( select a from t1 );
--enable_ps2_protocol
show index_statistics;
drop table t1;
set global userstat=@save_userstat;
......
......@@ -2312,7 +2312,8 @@ bool open_table(THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx)
*/
enum enum_mdl_type mdl_type= MDL_BACKUP_DML;
if (table->s->table_category != TABLE_CATEGORY_USER)
if (table->s->table_category != TABLE_CATEGORY_USER &&
table->s->table_category != TABLE_CATEGORY_MYSQL)
mdl_type= MDL_BACKUP_SYS_DML;
else if (table->s->online_backup)
mdl_type= MDL_BACKUP_TRANS_DML;
......
......@@ -324,6 +324,8 @@ TABLE_CATEGORY get_table_category(const Lex_ident_db &db,
name.streq(SLOW_LOG_NAME) ||
name.streq(TRANSACTION_REG_NAME))
return TABLE_CATEGORY_LOG;
return TABLE_CATEGORY_MYSQL;
}
return TABLE_CATEGORY_USER;
......
......@@ -490,6 +490,11 @@ enum enum_table_category
*/
TABLE_CATEGORY_LOG=5,
/**
Other tables in the mysql schema, like global_priv and db
*/
TABLE_CATEGORY_MYSQL= 6,
/*
Types below are read only tables, not affected by FLUSH TABLES or
MDL locks.
......@@ -514,7 +519,7 @@ enum enum_table_category
to I_S tables in the table cache, which should use
this table type.
*/
TABLE_CATEGORY_INFORMATION=6,
TABLE_CATEGORY_INFORMATION=7,
/**
Performance schema tables.
......@@ -536,7 +541,7 @@ enum enum_table_category
The server implementation perform writes.
Performance tables are cached in the table cache.
*/
TABLE_CATEGORY_PERFORMANCE=7
TABLE_CATEGORY_PERFORMANCE=8
};
typedef enum enum_table_category TABLE_CATEGORY;
......
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