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