MySQL  8.0.27
Source Code Documentation
opt_statistics.h File Reference
#include <sys/types.h>
#include "my_inttypes.h"

Go to the source code of this file.

Typedefs

typedef float rec_per_key_t
 

Functions

rec_per_key_t guess_rec_per_key (const TABLE *const table, const KEY *const key, uint used_keyparts)
 Guesstimate for "records per key" when index statistics is not available. More...
 

Typedef Documentation

◆ rec_per_key_t

typedef float rec_per_key_t

Function Documentation

◆ guess_rec_per_key()

rec_per_key_t guess_rec_per_key ( const TABLE *const  table,
const KEY *const  key,
uint  used_keyparts 
)

Guesstimate for "records per key" when index statistics is not available.

Parameters
tablethe table
keythe index
used_keypartsthe number of key part that should be included in the estimate
Returns
estimated records per key value

Guesstimate for "records per key" when index statistics is not available.

Assume that the first key part matches 1% of the file and that the whole key matches 10 (duplicates) or 1 (unique) records. For small tables, ensure there are at least ten different key values. Assume also that more key matches proportionally more records. This gives the formula:

records = a - (x-1)/(c-1)*(a-b)

where

b = records matched by whole key a = records matched by first key part (1% of all records?) c = number of key parts in key x = used key parts (1 <= x <= c)