branches/innodb+:

Fix Bug#25640:

Introduce an user visible parameter innodb_stats_sample (default 8,
min 1, max 1000) and use that parameter instead of the
BTR_KEY_VAL_ESTIMATE_N_PAGES macro. Remove this macro.

Approved by:	Heikki
This commit is contained in:
vasil 2008-02-19 14:21:05 +00:00
parent 0ee3946c84
commit 70684a3dc8
4 changed files with 25 additions and 13 deletions

View file

@ -55,10 +55,6 @@ can be released by page reorganize, then it is reorganized */
#define BTR_CUR_PAGE_REORGANIZE_LIMIT (UNIV_PAGE_SIZE / 32)
/* When estimating number of different key values in an index, sample
this many index pages */
#define BTR_KEY_VAL_ESTIMATE_N_PAGES 8
/* The structure of a BLOB part header */
/*--------------------------------------*/
#define BTR_BLOB_HDR_PART_LEN 0 /* BLOB part len on this
@ -3174,7 +3170,7 @@ btr_estimate_number_of_different_key_vals(
/* We sample some pages in the index to get an estimate */
for (i = 0; i < BTR_KEY_VAL_ESTIMATE_N_PAGES; i++) {
for (i = 0; i < srv_stats_sample; i++) {
rec_t* supremum;
mtr_start(&mtr);
@ -3263,7 +3259,7 @@ btr_estimate_number_of_different_key_vals(
}
/* If we saw k borders between different key values on
BTR_KEY_VAL_ESTIMATE_N_PAGES leaf pages, we can estimate how many
srv_stats_sample leaf pages, we can estimate how many
there will be in index->stat_n_leaf_pages */
/* We must take into account that our sample actually represents
@ -3274,26 +3270,26 @@ btr_estimate_number_of_different_key_vals(
index->stat_n_diff_key_vals[j]
= ((n_diff[j]
* (ib_longlong)index->stat_n_leaf_pages
+ BTR_KEY_VAL_ESTIMATE_N_PAGES - 1
+ srv_stats_sample - 1
+ total_external_size
+ not_empty_flag)
/ (BTR_KEY_VAL_ESTIMATE_N_PAGES
/ (srv_stats_sample
+ total_external_size));
/* If the tree is small, smaller than
10 * BTR_KEY_VAL_ESTIMATE_N_PAGES + total_external_size, then
10 * srv_stats_sample + total_external_size, then
the above estimate is ok. For bigger 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 BTR_KEY_VAL_ESTIMATE_N_PAGES
we pick. But still there may be srv_stats_sample
different key values, or even more. Let us try to approximate
that: */
add_on = index->stat_n_leaf_pages
/ (10 * (BTR_KEY_VAL_ESTIMATE_N_PAGES
/ (10 * (srv_stats_sample
+ total_external_size));
if (add_on > BTR_KEY_VAL_ESTIMATE_N_PAGES) {
add_on = BTR_KEY_VAL_ESTIMATE_N_PAGES;
if (add_on > srv_stats_sample) {
add_on = srv_stats_sample;
}
index->stat_n_diff_key_vals[j] += add_on;

View file

@ -8420,6 +8420,12 @@ static MYSQL_SYSVAR_LONG(open_files, innobase_open_files,
"How many files at the maximum InnoDB keeps open at the same time.",
NULL, NULL, 300L, 10L, ~0L, 0);
static MYSQL_SYSVAR_ULONG(stats_sample, srv_stats_sample,
PLUGIN_VAR_OPCMDARG,
"When estimating number of different key values in an index, sample "
"this many index pages",
NULL, NULL, SRV_STATS_SAMPLE_DEFAULT, 1, 1000, 0);
static MYSQL_SYSVAR_ULONG(sync_spin_loops, srv_n_spin_wait_rounds,
PLUGIN_VAR_RQCMDARG,
"Count of spin-loop rounds in InnoDB mutexes",
@ -8486,6 +8492,7 @@ static struct st_mysql_sys_var* innobase_system_variables[]= {
MYSQL_SYSVAR(stats_on_metadata),
MYSQL_SYSVAR(adaptive_hash_index),
MYSQL_SYSVAR(replication_delay),
MYSQL_SYSVAR(stats_sample),
MYSQL_SYSVAR(status_file),
MYSQL_SYSVAR(support_xa),
MYSQL_SYSVAR(sync_spin_loops),

View file

@ -128,6 +128,11 @@ extern ibool srv_innodb_status;
extern ibool srv_stats_on_metadata;
/* When estimating number of different key values in an index, sample
this many index pages */
#define SRV_STATS_SAMPLE_DEFAULT 8
extern ulong srv_stats_sample;
extern ibool srv_use_doublewrite_buf;
extern ibool srv_use_checksums;

View file

@ -291,6 +291,10 @@ UNIV_INTERN ibool srv_innodb_status = FALSE;
UNIV_INTERN ibool srv_stats_on_metadata = TRUE;
/* When estimating number of different key values in an index, sample
this many index pages */
UNIV_INTERN ulong srv_stats_sample = SRV_STATS_SAMPLE_DEFAULT;
UNIV_INTERN ibool srv_use_doublewrite_buf = TRUE;
UNIV_INTERN ibool srv_use_checksums = TRUE;