1
0
mirror of https://github.com/MariaDB/server.git synced 2025-05-05 16:59:35 +03:00
mariadb/mysql-test/suite/sys_vars/t/innodb_stats_traditional_basic.test
Jan Lindström 8bc5eabea8 MDEV-7084: innodb index stats inadequate using constant
innodb_stats_sample_pages

Analysis: If you set the number of analyzed pages 
to very low number compared to actual pages on 
that table/index it randomly pics those pages 
(default 8 pages), this leads to fact that query 
after analyze table returns different results. If 
the index tree is small, smaller than 10 * 
n_sample_pages + total_external_size, then the 
estimate is ok. For bigger index trees it is 
common that we do not see any borders between 
key values in the few pages we pick. But still 
there may be n_sample_pages different key values, 
or even more. And it just tries to 
approximate to n_sample_pages (8).

Fix: (1) Introduced new dynamic configuration variable
innodb_stats_sample_traditional  that retains
the current design. Default false.

(2) If traditional sample is not used we use
n_sample_pages = max(min(srv_stats_sample_pages,
                         index->stat_index_size),
                     log2(index->stat_index_size)*
                          srv_stats_sample_pages);

(3) Introduced new dynamic configuration variable
stat_modified_counter (default = 0) if set
sets lower bound for row updates when statistics is re-estimated.

If user has provided upper bound for how many rows needs to be updated
before we calculate new statistics we use minimum of provided value
and 1/16 of table every 16th round. If no upper bound is provided
(srv_stats_modified_counter = 0, default) then calculate new statistics
if 1 / 16 of table has been modified
since the last time a statistics batch was run.
We calculate statistics at most every 16th round, since we may have
a counter table which is very small and updated very often.
@param t table
@return true if the table has changed too much and stats need to be
recalculated
*/
#define DICT_TABLE_CHANGED_TOO_MUCH(t) \
	((ib_int64_t) (t)->stat_modified_counter > (srv_stats_modified_counter ? \
	ut_min(srv_stats_modified_counter, (16 + (t)->stat_n_rows / 16)) : \
		16 + (t)->stat_n_rows / 16))
2014-11-19 20:27:34 +02:00

66 lines
2.6 KiB
Plaintext

--source include/have_innodb.inc
SET @start_global_value = @@global.innodb_stats_traditional;
SELECT @start_global_value;
#
# exists as global only
#
--echo Valid values are 'ON' and 'OFF'
select @@global.innodb_stats_traditional in (0, 1);
select @@global.innodb_stats_traditional;
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
select @@session.innodb_stats_traditional;
show global variables like 'innodb_stats_traditional';
show session variables like 'innodb_stats_traditional';
select * from information_schema.global_variables where variable_name='innodb_stats_traditional';
select * from information_schema.session_variables where variable_name='innodb_stats_traditional';
#
# show that it's writable
#
set global innodb_stats_traditional='OFF';
select @@global.innodb_stats_traditional;
select * from information_schema.global_variables where variable_name='innodb_stats_traditional';
select * from information_schema.session_variables where variable_name='innodb_stats_traditional';
set @@global.innodb_stats_traditional=1;
select @@global.innodb_stats_traditional;
select * from information_schema.global_variables where variable_name='innodb_stats_traditional';
select * from information_schema.session_variables where variable_name='innodb_stats_traditional';
set global innodb_stats_traditional=0;
select @@global.innodb_stats_traditional;
select * from information_schema.global_variables where variable_name='innodb_stats_traditional';
select * from information_schema.session_variables where variable_name='innodb_stats_traditional';
set @@global.innodb_stats_traditional='ON';
select @@global.innodb_stats_traditional;
select * from information_schema.global_variables where variable_name='innodb_stats_traditional';
select * from information_schema.session_variables where variable_name='innodb_stats_traditional';
--error ER_GLOBAL_VARIABLE
set session innodb_stats_traditional='OFF';
--error ER_GLOBAL_VARIABLE
set @@session.innodb_stats_traditional='ON';
#
# incorrect types
#
--error ER_WRONG_TYPE_FOR_VAR
set global innodb_stats_traditional=1.1;
--error ER_WRONG_TYPE_FOR_VAR
set global innodb_stats_traditional=1e1;
--error ER_WRONG_VALUE_FOR_VAR
set global innodb_stats_traditional=2;
--error ER_WRONG_VALUE_FOR_VAR
set global innodb_stats_traditional=-3;
select @@global.innodb_stats_traditional;
select * from information_schema.global_variables where variable_name='innodb_stats_traditional';
select * from information_schema.session_variables where variable_name='innodb_stats_traditional';
--error ER_WRONG_VALUE_FOR_VAR
set global innodb_stats_traditional='AUTO';
#
# Cleanup
#
SET @@global.innodb_stats_traditional = @start_global_value;
SELECT @@global.innodb_stats_traditional;