MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dict0stats.cc File Reference
#include "univ.i"
#include "btr0btr.h"
#include "btr0cur.h"
#include "dict0dict.h"
#include "dict0mem.h"
#include "dict0stats.h"
#include "data0type.h"
#include "db0err.h"
#include "page0page.h"
#include "pars0pars.h"
#include "pars0types.h"
#include "que0que.h"
#include "rem0cmp.h"
#include "row0sel.h"
#include "row0types.h"
#include "trx0trx.h"
#include "trx0roll.h"
#include "ut0rnd.h"
#include "ut0ut.h"
#include <vector>
#include "mysql_com.h"
Include dependency graph for dict0stats.cc:

Go to the source code of this file.

Macros

#define TABLE_STATS_NAME   "mysql/innodb_table_stats"
#define TABLE_STATS_NAME_PRINT   "mysql.innodb_table_stats"
#define INDEX_STATS_NAME   "mysql/innodb_index_stats"
#define INDEX_STATS_NAME_PRINT   "mysql.innodb_index_stats"
#define DEBUG_PRINTF(fmt,...)   /* noop */
#define N_SAMPLE_PAGES(index)
#define N_DIFF_REQUIRED(index)   (N_SAMPLE_PAGES(index) * 10)
#define INDEX_EQ(i1, i2)
#define PREPARE_PINFO_FOR_TABLE_SAVE(p, t, n)
#define PFX   "n_diff_pfx"
#define PFX_LEN   10

Typedefs

typedef std::vector< ib_uint64_t > boundaries_t

Functions

UNIV_INLINE bool dict_stats_should_ignore_index (const dict_index_t *index)
UNIV_INTERN void dict_stats_update_transient (dict_table_t *table)
UNIV_INLINE __attribute__ ((nonnull)) ulint *dict_stats_scan_page(const rec_t **out_rec
UNIV_INTERN void dict_stats_update_for_index (dict_index_t *index)
UNIV_INTERN dberr_t dict_stats_update (dict_table_t *table, dict_stats_upd_option_t stats_upd_option)
UNIV_INTERN dberr_t dict_stats_drop_index (const char *db_and_table, const char *iname, char *errstr, ulint errstr_sz)
UNIV_INLINE dberr_t dict_stats_delete_from_table_stats (const char *database_name, const char *table_name)
UNIV_INLINE dberr_t dict_stats_delete_from_index_stats (const char *database_name, const char *table_name)
UNIV_INTERN dberr_t dict_stats_drop_table (const char *db_and_table, char *errstr, ulint errstr_sz)
UNIV_INLINE dberr_t dict_stats_rename_in_table_stats (const char *old_dbname_utf8, const char *old_tablename_utf8, const char *new_dbname_utf8, const char *new_tablename_utf8)
UNIV_INLINE dberr_t dict_stats_rename_in_index_stats (const char *old_dbname_utf8, const char *old_tablename_utf8, const char *new_dbname_utf8, const char *new_tablename_utf8)
UNIV_INTERN dberr_t dict_stats_rename_table (const char *old_name, const char *new_name, char *errstr, size_t errstr_sz)

Variables

UNIV_INLINE ulint * offsets1
UNIV_INLINE ulint ulint * offsets2
UNIV_INLINE ulint ulint
dict_index_t
index
UNIV_INLINE ulint ulint
dict_index_t const page_t
page
UNIV_INLINE ulint ulint
dict_index_t const page_t
ulint 
n_prefix
UNIV_INLINE ulint ulint
dict_index_t const page_t
ulint page_scan_method_t 
scan_method
enum  page_scan_method_t { COUNT_ALL_NON_BORING_AND_SKIP_DEL_MARKED, QUIT_ON_FIRST_NON_BORING }

Detailed Description

Code used for calculating and manipulating table statistics.

Created Jan 06, 2010 Vasil Dimov

Definition in file dict0stats.cc.

Macro Definition Documentation

#define INDEX_EQ (   i1,
  i2 
)
Value:
((i1) != NULL \
&& (i2) != NULL \
&& (i1)->id == (i2)->id \
&& strcmp((i1)->name, (i2)->name) == 0)

Definition at line 622 of file dict0stats.cc.

#define N_SAMPLE_PAGES (   index)
Value:
((index)->table->stats_sample_pages != 0 ? \
(index)->table->stats_sample_pages : \
srv_stats_persistent_sample_pages)

Definition at line 129 of file dict0stats.cc.

#define PREPARE_PINFO_FOR_TABLE_SAVE (   p,
  t,
  n 
)
Value:
do { \
pars_info_add_str_literal((p), "database_name", db_utf8); \
pars_info_add_str_literal((p), "table_name", table_utf8); \
pars_info_add_int4_literal((p), "last_update", (n)); \
pars_info_add_ull_literal((p), "n_rows", (t)->stat_n_rows); \
pars_info_add_ull_literal((p), "clustered_index_size", \
(t)->stat_clustered_index_size); \
pars_info_add_ull_literal((p), "sum_of_other_index_sizes", \
(t)->stat_sum_of_other_index_sizes); \
} while(false);

Function Documentation

static __attribute__ ( (nonnull)  ) const

Scan a page, reading records from left to right and counting the number of distinct records on that page (looking only at the first n_prefix columns). If scan_method is QUIT_ON_FIRST_NON_BORING then the function will return as soon as it finds a record that does not match its neighbor to the right, which means that in the case of QUIT_ON_FIRST_NON_BORING the returned n_diff can either be 0 (empty page), 1 (the whole page has all keys equal) or 2 (the function found a non-boring record and returned).

Returns
offsets1 or offsets2 (the offsets of *out_rec), or NULL if the page is empty and does not contain user records.

Drop any indexes that we were not able to free previously due to open table handles.

Releases the mlocks and other objects stored in an mtr memo. They are released in the order opposite to which they were pushed to the memo.

< in/out: mini-transaction

Definition at line 108 of file mtr0mtr.cc.

Here is the call graph for this function:

UNIV_INLINE dberr_t dict_stats_delete_from_index_stats ( const char *  database_name,
const char *  table_name 
)

Executes DELETE FROM mysql.innodb_index_stats WHERE database_name = '...' AND table_name = '...'; Creates its own transaction and commits it.

Returns
DB_SUCCESS or error code
Parameters
database_namein: database name, e.g. 'db'
table_namein: table name, e.g. 'table'

Definition at line 3259 of file dict0stats.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INLINE dberr_t dict_stats_delete_from_table_stats ( const char *  database_name,
const char *  table_name 
)

Executes DELETE FROM mysql.innodb_table_stats WHERE database_name = '...' AND table_name = '...'; Creates its own transaction and commits it.

Returns
DB_SUCCESS or error code
Parameters
database_namein: database name, e.g. 'db'
table_namein: table name, e.g. 'table'

Definition at line 3221 of file dict0stats.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN dberr_t dict_stats_drop_index ( const char *  db_and_table,
const char *  iname,
char *  errstr,
ulint  errstr_sz 
)

Removes the information for a particular index's stats from the persistent storage if it exists and if there is data stored for this index. This function creates its own trx and commits it. A note from Marko why we cannot edit user and sys_* tables in one trx: marko: The problem is that ibuf merges should be disabled while we are rolling back dict transactions. marko: If ibuf merges are not disabled, we need to scan the *.ibd files. But we shouldn't open *.ibd files before we have rolled back dict transactions and opened the SYS_* records for the *.ibd files.

Returns
DB_SUCCESS or error code
Parameters
db_and_tablein: db and table, e.g. 'db/table'
inamein: index name
errstrout: error message if != DB_SUCCESS is returned
errstr_szin: size of the errstr buffer

Definition at line 3134 of file dict0stats.cc.

Here is the call graph for this function:

UNIV_INTERN dberr_t dict_stats_drop_table ( const char *  db_and_table,
char *  errstr,
ulint  errstr_sz 
)

Removes the statistics for a table and all of its indexes from the persistent statistics storage if it exists and if there is data stored for the table. This function creates its own transaction and commits it.

Returns
DB_SUCCESS or error code
Parameters
db_and_tablein: db and table, e.g. 'db/table'
errstrout: error message if != DB_SUCCESS is returned
errstr_szin: size of errstr buffer

Definition at line 3296 of file dict0stats.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INLINE dberr_t dict_stats_rename_in_index_stats ( const char *  old_dbname_utf8,
const char *  old_tablename_utf8,
const char *  new_dbname_utf8,
const char *  new_tablename_utf8 
)

Executes UPDATE mysql.innodb_index_stats SET database_name = '...', table_name = '...' WHERE database_name = '...' AND table_name = '...'; Creates its own transaction and commits it.

Returns
DB_SUCCESS or error code
Parameters
old_dbname_utf8in: database name, e.g. 'olddb'
old_tablename_utf8in: table name, e.g. 'oldtable'
new_dbname_utf8in: database name, e.g. 'newdb'
new_tablename_utf8in: table name, e.g. 'newtable'

Definition at line 3421 of file dict0stats.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INLINE dberr_t dict_stats_rename_in_table_stats ( const char *  old_dbname_utf8,
const char *  old_tablename_utf8,
const char *  new_dbname_utf8,
const char *  new_tablename_utf8 
)

Executes UPDATE mysql.innodb_table_stats SET database_name = '...', table_name = '...' WHERE database_name = '...' AND table_name = '...'; Creates its own transaction and commits it.

Returns
DB_SUCCESS or error code
Parameters
old_dbname_utf8in: database name, e.g. 'olddb'
old_tablename_utf8in: table name, e.g. 'oldtable'
new_dbname_utf8in: database name, e.g. 'newdb'
new_tablename_utf8in: table name, e.g. 'newtable'

Definition at line 3375 of file dict0stats.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN dberr_t dict_stats_rename_table ( const char *  old_name,
const char *  new_name,
char *  errstr,
size_t  errstr_sz 
)

Renames a table in InnoDB persistent stats storage. This function creates its own transaction and commits it.

Returns
DB_SUCCESS or error code
Parameters
old_namein: old name, e.g. 'db/table'
new_namein: new name, e.g. 'db/table'
errstrout: error string if != DB_SUCCESS is returned
errstr_szin: errstr size

Definition at line 3464 of file dict0stats.cc.

Here is the call graph for this function:

UNIV_INLINE bool dict_stats_should_ignore_index ( const dict_index_t index)

Checks whether an index should be ignored in stats manipulations: stats fetch stats recalc stats save

Returns
true if exists and all tables are ok
Parameters
indexin: index

Definition at line 154 of file dict0stats.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN dberr_t dict_stats_update ( dict_table_t table,
dict_stats_upd_option_t  stats_upd_option 
)

Calculates new estimates for table and index statistics. The statistics are used in query optimization.

Returns
DB_SUCCESS or error code
Parameters
tablein/out: table
stats_upd_optionin: whether to (re) calc the stats or to fetch them from the persistent statistics storage

Definition at line 2894 of file dict0stats.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN void dict_stats_update_for_index ( dict_index_t index)

Fetches or calculates new estimates for index statistics.

Parameters
indexin/out: index

Definition at line 2846 of file dict0stats.cc.

Here is the call graph for this function:

UNIV_INTERN void dict_stats_update_transient ( dict_table_t table)

Calculates new estimates for table and index statistics. This function is relatively quick and is used to calculate transient statistics that are not saved on disk. This was the only way to calculate statistics before the Persistent Statistics feature was introduced.

Parameters
tablein/out: table

Definition at line 834 of file dict0stats.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

UNIV_INLINE ulint ulint dict_index_t* index

in: index of the page

Definition at line 1266 of file dict0stats.cc.

UNIV_INLINE ulint ulint dict_index_t const page_t ulint n_prefix

in: look at the first n_prefix columns

Definition at line 1266 of file dict0stats.cc.

UNIV_INLINE ulint* offsets1

< out: record, or NULL out: rec_get_offsets() working space (must be big enough)

Definition at line 1266 of file dict0stats.cc.

UNIV_INLINE ulint ulint* offsets2

out: rec_get_offsets() working space (must be big enough)

Definition at line 1266 of file dict0stats.cc.

UNIV_INLINE ulint ulint dict_index_t const page_t* page

in: the page to scan

Definition at line 1266 of file dict0stats.cc.

UNIV_INLINE ulint ulint dict_index_t const page_t ulint page_scan_method_t scan_method

in: scan to the end of the page or not

Definition at line 1266 of file dict0stats.cc.