Skip to content

Commit 94033fc

Browse files
montywivuvova
authored andcommitted
MDEV-33151 Add more columns to TABLE_STATISTICS and USER STATS
Columns added to TABLE_STATISTICS - ROWS_INSERTED, ROWS_DELETED, ROWS_UPDATED, KEY_READ_HITS and KEY_READ_MISSES. Columns added to CLIENT_STATISTICS and USER_STATISTICS: - KEY_READ_HITS and KEY_READ_MISSES. User visible changes (except new columns): - CLIENT_STATISTICS and USER_STATISTICS has columns KEY_READ_HITS and KEY_READ_MISSES added after column ROWS_UPDATED before SELECT_COMMANDS. Other changes: - Do not collect table statistics for system tables like index_stats table_stats, performance_schema, information_schema etc as the user has no control of these and the generate noice in the statistics. - All row variables that are part of user_stats are moved to 'struct rows_stats' to make it easy to clear all of them at once. - ha_read_key_misses added to STATUS_VAR Notes: - userstat.result has a change of numbers of rows for handler_read_key. This is because use-stat-tables is now disabled for the test.
1 parent c944518 commit 94033fc

25 files changed

+265
-137
lines changed

mysql-test/main/information_schema_stats.result

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,35 @@ TABLE_SCHEMA TABLE_NAME INDEX_NAME ROWS_READ QUERIES
2020
test just_a_test IND_just_a_test_first_name_last_name 1 1
2121
test just_a_test IND_just_a_test_state 2 1
2222
select * from information_schema.table_statistics where table_schema='test' and table_name='just_a_test';
23-
TABLE_SCHEMA TABLE_NAME ROWS_READ ROWS_CHANGED ROWS_CHANGED_X_INDEXES
24-
test just_a_test 18 5 5
23+
TABLE_SCHEMA TABLE_NAME ROWS_READ ROWS_CHANGED ROWS_CHANGED_X_INDEXES ROWS_INSERTED ROWS_UPDATED ROWS_DELETED KEY_READ_HITS KEY_READ_MISSES
24+
test just_a_test 18 5 5 5 0 0 2 0
2525
alter table just_a_test drop key IND_just_a_test_first_name_last_name;
2626
select * from information_schema.index_statistics where table_schema='test' and table_name='just_a_test';
2727
TABLE_SCHEMA TABLE_NAME INDEX_NAME ROWS_READ QUERIES
2828
test just_a_test IND_just_a_test_state 2 1
2929
select * from information_schema.table_statistics where table_schema='test' and table_name='just_a_test';
30-
TABLE_SCHEMA TABLE_NAME ROWS_READ ROWS_CHANGED ROWS_CHANGED_X_INDEXES
31-
test just_a_test 23 5 5
30+
TABLE_SCHEMA TABLE_NAME ROWS_READ ROWS_CHANGED ROWS_CHANGED_X_INDEXES ROWS_INSERTED ROWS_UPDATED ROWS_DELETED KEY_READ_HITS KEY_READ_MISSES
31+
test just_a_test 23 5 5 5 0 0 2 0
3232
alter table just_a_test drop column state;
3333
select * from information_schema.index_statistics where table_schema='test' and table_name='just_a_test';
3434
TABLE_SCHEMA TABLE_NAME INDEX_NAME ROWS_READ QUERIES
35+
select * from just_a_test force index(primary) where id between 1 and 2;
36+
id first_name last_name address phone email
37+
1 fa la china_a 11111111 fa_la@163.com
38+
2 fb lb china_b 22222222 fb_lb@163.com
39+
select * from just_a_test force index(primary) where id=8;
40+
id first_name last_name address phone email
41+
update just_a_test set first_name="unlucky" where id=5;
42+
delete from just_a_test where id=5;
3543
select * from information_schema.table_statistics where table_schema='test' and table_name='just_a_test';
36-
TABLE_SCHEMA TABLE_NAME ROWS_READ ROWS_CHANGED ROWS_CHANGED_X_INDEXES
37-
test just_a_test 28 5 5
44+
TABLE_SCHEMA TABLE_NAME ROWS_READ ROWS_CHANGED ROWS_CHANGED_X_INDEXES ROWS_INSERTED ROWS_UPDATED ROWS_DELETED KEY_READ_HITS KEY_READ_MISSES
45+
test just_a_test 32 7 7 5 1 1 5 1
3846
select * from information_schema.index_statistics where table_schema='test' and table_name='just_a_test';
3947
TABLE_SCHEMA TABLE_NAME INDEX_NAME ROWS_READ QUERIES
48+
test just_a_test PRIMARY 4 3
4049
drop table just_a_test;
4150
select * from information_schema.table_statistics where table_schema='test' and table_name='just_a_test';
42-
TABLE_SCHEMA TABLE_NAME ROWS_READ ROWS_CHANGED ROWS_CHANGED_X_INDEXES
51+
TABLE_SCHEMA TABLE_NAME ROWS_READ ROWS_CHANGED ROWS_CHANGED_X_INDEXES ROWS_INSERTED ROWS_UPDATED ROWS_DELETED KEY_READ_HITS KEY_READ_MISSES
4352
select * from information_schema.index_statistics where table_schema='test' and table_name='just_a_test';
4453
TABLE_SCHEMA TABLE_NAME INDEX_NAME ROWS_READ QUERIES
4554
create table just_a_test(id int not null primary key,first_name varchar(10),last_name varchar(10),address varchar(100),phone bigint,email varchar(30), state varchar(30),key(first_name,last_name),key(state));
@@ -63,11 +72,11 @@ test just_a_test PRIMARY 4 1
6372
test just_a_test first_name 1 1
6473
test just_a_test state 2 1
6574
select * from information_schema.table_statistics where table_schema='test' and table_name='just_a_test';
66-
TABLE_SCHEMA TABLE_NAME ROWS_READ ROWS_CHANGED ROWS_CHANGED_X_INDEXES
67-
test just_a_test 7 5 15
75+
TABLE_SCHEMA TABLE_NAME ROWS_READ ROWS_CHANGED ROWS_CHANGED_X_INDEXES ROWS_INSERTED ROWS_UPDATED ROWS_DELETED KEY_READ_HITS KEY_READ_MISSES
76+
test just_a_test 7 5 15 5 0 0 3 0
6877
drop table just_a_test;
6978
select * from information_schema.index_statistics where table_schema='test' and table_name='just_a_test';
7079
TABLE_SCHEMA TABLE_NAME INDEX_NAME ROWS_READ QUERIES
7180
select * from information_schema.table_statistics where table_schema='test' and table_name='just_a_test';
72-
TABLE_SCHEMA TABLE_NAME ROWS_READ ROWS_CHANGED ROWS_CHANGED_X_INDEXES
81+
TABLE_SCHEMA TABLE_NAME ROWS_READ ROWS_CHANGED ROWS_CHANGED_X_INDEXES ROWS_INSERTED ROWS_UPDATED ROWS_DELETED KEY_READ_HITS KEY_READ_MISSES
7382
set global userstat=@save_userstat;

mysql-test/main/information_schema_stats.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ insert into just_a_test values(1,'fa','la','china_a',11111111,'fa_la@163.com','C
1010
(3,'fc','lc','china_c',33333333,'fc_lc@163.com','California'),
1111
(4,'fd','ld','china_d',44444444,'fd_ld@163.com','Utah'),
1212
(5,'fe','le','china_e',55555555,'fe_le@163.com','Arizona');
13+
1314
alter table just_a_test add primary key (id);
1415
alter table just_a_test add key IND_just_a_test_first_name_last_name(first_name,last_name);
1516
alter table just_a_test add key IND_just_a_test_state(state);
@@ -23,6 +24,10 @@ select * from information_schema.index_statistics where table_schema='test' and
2324
select * from information_schema.table_statistics where table_schema='test' and table_name='just_a_test';
2425
alter table just_a_test drop column state;
2526
select * from information_schema.index_statistics where table_schema='test' and table_name='just_a_test';
27+
select * from just_a_test force index(primary) where id between 1 and 2;
28+
select * from just_a_test force index(primary) where id=8;
29+
update just_a_test set first_name="unlucky" where id=5;
30+
delete from just_a_test where id=5;
2631
select * from information_schema.table_statistics where table_schema='test' and table_name='just_a_test';
2732
select * from information_schema.index_statistics where table_schema='test' and table_name='just_a_test';
2833
drop table just_a_test;

mysql-test/main/lowercase_table5.result

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ a
126126
3
127127
4
128128
SELECT * FROM INFORMATION_SCHEMA.TABLE_STATISTICS ORDER BY BINARY TABLE_NAME;
129-
TABLE_SCHEMA TABLE_NAME ROWS_READ ROWS_CHANGED ROWS_CHANGED_X_INDEXES
130-
test T1 4 4 4
131-
test t1 4 4 4
129+
TABLE_SCHEMA TABLE_NAME ROWS_READ ROWS_CHANGED ROWS_CHANGED_X_INDEXES ROWS_INSERTED ROWS_UPDATED ROWS_DELETED KEY_READ_HITS KEY_READ_MISSES
130+
test T1 4 4 4 4 0 0 0 0
131+
test t1 4 4 4 4 0 0 0 0
132132
SELECT * FROM INFORMATION_SCHEMA.INDEX_STATISTICS ORDER BY BINARY TABLE_NAME;
133133
TABLE_SCHEMA TABLE_NAME INDEX_NAME ROWS_READ QUERIES
134134
test T1 a 4 1

mysql-test/main/sp.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7629,7 +7629,7 @@ SELECT 1;
76297629
DROP PROCEDURE sp;
76307630
CREATE PROCEDURE sp() SET STATEMENT SQL_SELECT_LIMIT=0 FOR SHOW USER_STATISTICS;
76317631
CALL sp;
7632-
User Total_connections Concurrent_connections Connected_time Busy_time Cpu_time Bytes_received Bytes_sent Binlog_bytes_written Rows_read Rows_sent Rows_deleted Rows_inserted Rows_updated Select_commands Update_commands Other_commands Commit_transactions Rollback_transactions Denied_connections Lost_connections Access_denied Empty_queries Total_ssl_connections Max_statement_time_exceeded
7632+
User Total_connections Concurrent_connections Connected_time Busy_time Cpu_time Bytes_received Bytes_sent Binlog_bytes_written Rows_read Rows_sent Rows_deleted Rows_inserted Rows_updated Key_read_hits Key_read_misses Select_commands Update_commands Other_commands Commit_transactions Rollback_transactions Denied_connections Lost_connections Access_denied Empty_queries Total_ssl_connections Max_statement_time_exceeded
76337633
SELECT 1;
76347634
1
76357635
1

mysql-test/main/subselect.result

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7126,9 +7126,10 @@ MIN(b)
71267126
NULL
71277127
# The following shows that t2 was indeed scanned with a full scan.
71287128
show table_statistics;
7129-
Table_schema Table_name Rows_read Rows_changed Rows_changed_x_#indexes
7130-
test t1 2 0 0
7131-
test t2 3 0 0
7129+
Table_schema Table_name Rows_read Rows_changed Rows_changed_x_#indexes Rows_inserted Rows_updated Rows_deleted Key_read_hits Key_read_misses
7130+
test t1 2 0 0 0 0 0 0 0
7131+
test t2 3 0 0 0 0 0 1 0
7132+
test t3 0 0 0 0 0 0 0 1
71327133
show index_statistics;
71337134
Table_schema Table_name Index_name Rows_read Queries
71347135
test t2 b 1 1

mysql-test/main/subselect_no_exists_to_in.result

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7128,9 +7128,10 @@ MIN(b)
71287128
NULL
71297129
# The following shows that t2 was indeed scanned with a full scan.
71307130
show table_statistics;
7131-
Table_schema Table_name Rows_read Rows_changed Rows_changed_x_#indexes
7132-
test t1 2 0 0
7133-
test t2 3 0 0
7131+
Table_schema Table_name Rows_read Rows_changed Rows_changed_x_#indexes Rows_inserted Rows_updated Rows_deleted Key_read_hits Key_read_misses
7132+
test t1 2 0 0 0 0 0 0 0
7133+
test t2 3 0 0 0 0 0 1 0
7134+
test t3 0 0 0 0 0 0 0 1
71347135
show index_statistics;
71357136
Table_schema Table_name Index_name Rows_read Queries
71367137
test t2 b 1 1

mysql-test/main/subselect_no_mat.result

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7124,9 +7124,10 @@ MIN(b)
71247124
NULL
71257125
# The following shows that t2 was indeed scanned with a full scan.
71267126
show table_statistics;
7127-
Table_schema Table_name Rows_read Rows_changed Rows_changed_x_#indexes
7128-
test t1 2 0 0
7129-
test t2 3 0 0
7127+
Table_schema Table_name Rows_read Rows_changed Rows_changed_x_#indexes Rows_inserted Rows_updated Rows_deleted Key_read_hits Key_read_misses
7128+
test t1 2 0 0 0 0 0 0 0
7129+
test t2 3 0 0 0 0 0 1 0
7130+
test t3 0 0 0 0 0 0 0 1
71307131
show index_statistics;
71317132
Table_schema Table_name Index_name Rows_read Queries
71327133
test t2 b 1 1

mysql-test/main/subselect_no_opts.result

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7121,9 +7121,10 @@ MIN(b)
71217121
NULL
71227122
# The following shows that t2 was indeed scanned with a full scan.
71237123
show table_statistics;
7124-
Table_schema Table_name Rows_read Rows_changed Rows_changed_x_#indexes
7125-
test t1 2 0 0
7126-
test t2 3 0 0
7124+
Table_schema Table_name Rows_read Rows_changed Rows_changed_x_#indexes Rows_inserted Rows_updated Rows_deleted Key_read_hits Key_read_misses
7125+
test t1 2 0 0 0 0 0 0 0
7126+
test t2 3 0 0 0 0 0 1 0
7127+
test t3 0 0 0 0 0 0 0 1
71277128
show index_statistics;
71287129
Table_schema Table_name Index_name Rows_read Queries
71297130
test t2 b 1 1

mysql-test/main/subselect_no_scache.result

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7132,9 +7132,10 @@ MIN(b)
71327132
NULL
71337133
# The following shows that t2 was indeed scanned with a full scan.
71347134
show table_statistics;
7135-
Table_schema Table_name Rows_read Rows_changed Rows_changed_x_#indexes
7136-
test t1 2 0 0
7137-
test t2 3 0 0
7135+
Table_schema Table_name Rows_read Rows_changed Rows_changed_x_#indexes Rows_inserted Rows_updated Rows_deleted Key_read_hits Key_read_misses
7136+
test t1 2 0 0 0 0 0 0 0
7137+
test t2 3 0 0 0 0 0 1 0
7138+
test t3 0 0 0 0 0 0 0 1
71387139
show index_statistics;
71397140
Table_schema Table_name Index_name Rows_read Queries
71407141
test t2 b 1 1

mysql-test/main/subselect_no_semijoin.result

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7121,9 +7121,10 @@ MIN(b)
71217121
NULL
71227122
# The following shows that t2 was indeed scanned with a full scan.
71237123
show table_statistics;
7124-
Table_schema Table_name Rows_read Rows_changed Rows_changed_x_#indexes
7125-
test t1 2 0 0
7126-
test t2 3 0 0
7124+
Table_schema Table_name Rows_read Rows_changed Rows_changed_x_#indexes Rows_inserted Rows_updated Rows_deleted Key_read_hits Key_read_misses
7125+
test t1 2 0 0 0 0 0 0 0
7126+
test t2 3 0 0 0 0 0 1 0
7127+
test t3 0 0 0 0 0 0 0 1
71277128
show index_statistics;
71287129
Table_schema Table_name Index_name Rows_read Queries
71297130
test t2 b 1 1

0 commit comments

Comments
 (0)