1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00

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))
This commit is contained in:
Jan Lindström
2014-11-19 20:27:34 +02:00
parent 6ea41f1e84
commit 8bc5eabea8
14 changed files with 360 additions and 16 deletions

View File

@ -0,0 +1,92 @@
SET @start_global_value = @@global.innodb_stats_traditional;
SELECT @start_global_value;
@start_global_value
0
Valid values are 'ON' and 'OFF'
select @@global.innodb_stats_traditional in (0, 1);
@@global.innodb_stats_traditional in (0, 1)
1
select @@global.innodb_stats_traditional;
@@global.innodb_stats_traditional
0
select @@session.innodb_stats_traditional;
ERROR HY000: Variable 'innodb_stats_traditional' is a GLOBAL variable
show global variables like 'innodb_stats_traditional';
Variable_name Value
innodb_stats_traditional OFF
show session variables like 'innodb_stats_traditional';
Variable_name Value
innodb_stats_traditional OFF
select * from information_schema.global_variables where variable_name='innodb_stats_traditional';
VARIABLE_NAME VARIABLE_VALUE
INNODB_STATS_TRADITIONAL OFF
select * from information_schema.session_variables where variable_name='innodb_stats_traditional';
VARIABLE_NAME VARIABLE_VALUE
INNODB_STATS_TRADITIONAL OFF
set global innodb_stats_traditional='OFF';
select @@global.innodb_stats_traditional;
@@global.innodb_stats_traditional
0
select * from information_schema.global_variables where variable_name='innodb_stats_traditional';
VARIABLE_NAME VARIABLE_VALUE
INNODB_STATS_TRADITIONAL OFF
select * from information_schema.session_variables where variable_name='innodb_stats_traditional';
VARIABLE_NAME VARIABLE_VALUE
INNODB_STATS_TRADITIONAL OFF
set @@global.innodb_stats_traditional=1;
select @@global.innodb_stats_traditional;
@@global.innodb_stats_traditional
1
select * from information_schema.global_variables where variable_name='innodb_stats_traditional';
VARIABLE_NAME VARIABLE_VALUE
INNODB_STATS_TRADITIONAL ON
select * from information_schema.session_variables where variable_name='innodb_stats_traditional';
VARIABLE_NAME VARIABLE_VALUE
INNODB_STATS_TRADITIONAL ON
set global innodb_stats_traditional=0;
select @@global.innodb_stats_traditional;
@@global.innodb_stats_traditional
0
select * from information_schema.global_variables where variable_name='innodb_stats_traditional';
VARIABLE_NAME VARIABLE_VALUE
INNODB_STATS_TRADITIONAL OFF
select * from information_schema.session_variables where variable_name='innodb_stats_traditional';
VARIABLE_NAME VARIABLE_VALUE
INNODB_STATS_TRADITIONAL OFF
set @@global.innodb_stats_traditional='ON';
select @@global.innodb_stats_traditional;
@@global.innodb_stats_traditional
1
select * from information_schema.global_variables where variable_name='innodb_stats_traditional';
VARIABLE_NAME VARIABLE_VALUE
INNODB_STATS_TRADITIONAL ON
select * from information_schema.session_variables where variable_name='innodb_stats_traditional';
VARIABLE_NAME VARIABLE_VALUE
INNODB_STATS_TRADITIONAL ON
set session innodb_stats_traditional='OFF';
ERROR HY000: Variable 'innodb_stats_traditional' is a GLOBAL variable and should be set with SET GLOBAL
set @@session.innodb_stats_traditional='ON';
ERROR HY000: Variable 'innodb_stats_traditional' is a GLOBAL variable and should be set with SET GLOBAL
set global innodb_stats_traditional=1.1;
ERROR 42000: Incorrect argument type to variable 'innodb_stats_traditional'
set global innodb_stats_traditional=1e1;
ERROR 42000: Incorrect argument type to variable 'innodb_stats_traditional'
set global innodb_stats_traditional=2;
ERROR 42000: Variable 'innodb_stats_traditional' can't be set to the value of '2'
set global innodb_stats_traditional=-3;
ERROR 42000: Variable 'innodb_stats_traditional' can't be set to the value of '-3'
select @@global.innodb_stats_traditional;
@@global.innodb_stats_traditional
1
select * from information_schema.global_variables where variable_name='innodb_stats_traditional';
VARIABLE_NAME VARIABLE_VALUE
INNODB_STATS_TRADITIONAL ON
select * from information_schema.session_variables where variable_name='innodb_stats_traditional';
VARIABLE_NAME VARIABLE_VALUE
INNODB_STATS_TRADITIONAL ON
set global innodb_stats_traditional='AUTO';
ERROR 42000: Variable 'innodb_stats_traditional' can't be set to the value of 'AUTO'
SET @@global.innodb_stats_traditional = @start_global_value;
SELECT @@global.innodb_stats_traditional;
@@global.innodb_stats_traditional
0