}
return(table);
-@@ -4343,6 +4343,295 @@
+@@ -4344,6 +4344,295 @@
}
/*********************************************************************//**
Calculates new estimates for table and index statistics. The statistics
are used in query optimization. */
UNIV_INTERN
-@@ -4350,10 +4639,11 @@
+@@ -4351,10 +4640,11 @@
dict_update_statistics(
/*===================*/
dict_table_t* table, /*!< in/out: table */
{
dict_index_t* index;
ulint sum_of_index_sizes = 0;
-@@ -4370,6 +4660,27 @@
+@@ -4371,6 +4661,27 @@
return;
}
/* Find out the sizes of the indexes and how many different values
for the key they approximately have */
-@@ -4434,6 +4745,11 @@
+@@ -4435,6 +4746,11 @@
index = dict_table_get_next_index(index);
} while (index);
index = dict_table_get_first_index(table);
table->stat_n_rows = index->stat_n_diff_key_vals[
-@@ -4451,6 +4767,78 @@
+@@ -4452,6 +4768,78 @@
dict_table_stats_unlock(table, RW_X_LATCH);
}
/**********************************************************************//**
Prints info of a foreign key constraint. */
static
-@@ -4528,7 +4916,8 @@
+@@ -4529,7 +4917,8 @@
ut_ad(mutex_own(&(dict_sys->mutex)));
+ "SYS_FOREIGN_COLS",
+ "SYS_STATS"
};
- /****************************************************************//**
- Compare the name of an index column.
-@@ -343,12 +344,13 @@
+
+ /* If this flag is TRUE, then we will load the cluster index's (and tables')
+@@ -348,12 +349,13 @@
}
if ((status & DICT_TABLE_UPDATE_STATS)
}
return(NULL);
-@@ -582,6 +584,75 @@
+@@ -587,6 +589,75 @@
//#endif /* FOREIGN_NOT_USED */
/********************************************************************//**
static char* internal_innobase_data_file_path = NULL;
-@@ -2439,6 +2440,8 @@
+@@ -2468,6 +2469,8 @@
goto error;
}
/* -------------- Log files ---------------------------*/
/* The default dir for log files is the datadir of MySQL */
-@@ -5247,6 +5250,10 @@
+@@ -5256,6 +5259,10 @@
error = row_insert_for_mysql((byte*) record, prebuilt);
/* Handle duplicate key errors */
if (auto_inc_used) {
ulint err;
-@@ -5583,6 +5590,10 @@
+@@ -5591,6 +5598,10 @@
}
}
innodb_srv_conc_exit_innodb(trx);
error = convert_error_code_to_mysql(error,
-@@ -5636,6 +5647,10 @@
+@@ -5644,6 +5655,10 @@
error = row_update_for_mysql((byte*) record, prebuilt);
innodb_srv_conc_exit_innodb(trx);
error = convert_error_code_to_mysql(
-@@ -5954,6 +5969,11 @@
+@@ -5965,6 +5980,11 @@
case DB_SUCCESS:
error = 0;
table->status = 0;
break;
case DB_RECORD_NOT_FOUND:
error = HA_ERR_KEY_NOT_FOUND;
-@@ -6163,6 +6183,11 @@
+@@ -6197,6 +6217,11 @@
case DB_SUCCESS:
error = 0;
table->status = 0;
break;
case DB_RECORD_NOT_FOUND:
error = HA_ERR_END_OF_FILE;
-@@ -8105,11 +8130,35 @@
+@@ -8150,11 +8175,35 @@
/* In sql_show we call with this flag: update
then statistics so that they are up-to-date */
prebuilt->trx->op_info = "returning various info to MySQL";
}
-@@ -8187,7 +8236,7 @@
+@@ -8239,7 +8288,7 @@
are asked by MySQL to avoid locking. Another reason to
avoid the call is that it uses quite a lot of CPU.
See Bug#38185. */
|| !(flag & HA_STATUS_VARIABLE_EXTRA)) {
/* We do not update delete_length if no
locking is requested so the "old" value can
-@@ -11401,6 +11450,26 @@
+@@ -11512,6 +11561,26 @@
"The number of index pages to sample when calculating statistics (default 8)",
NULL, NULL, 8, 1, ~0ULL, 0);
static MYSQL_SYSVAR_BOOL(adaptive_hash_index, btr_search_enabled,
PLUGIN_VAR_OPCMDARG,
"Enable InnoDB adaptive hash index (enabled by default). "
-@@ -11727,6 +11796,9 @@
+@@ -11844,6 +11913,9 @@
MYSQL_SYSVAR(recovery_update_relay_log),
MYSQL_SYSVAR(rollback_on_timeout),
MYSQL_SYSVAR(stats_on_metadata),
MYSQL_SYSVAR(stats_sample_pages),
MYSQL_SYSVAR(adaptive_hash_index),
MYSQL_SYSVAR(stats_method),
-@@ -11796,7 +11868,10 @@
+@@ -11915,7 +11987,10 @@
i_s_innodb_sys_columns,
i_s_innodb_sys_fields,
i_s_innodb_sys_foreign,
}
#define OK(expr) \
-@@ -3455,6 +3456,221 @@
- STRUCT_FLD(__reserved1, NULL)
+@@ -3511,6 +3512,225 @@
+ STRUCT_FLD(flags, 0UL)
};
+/* Fields of the dynamic table INFORMATION_SCHEMA.innodb_sys_stats */
+
+ /* reserved for dependency checking */
+ /* void* */
-+ STRUCT_FLD(__reserved1, NULL)
++ STRUCT_FLD(__reserved1, NULL),
++
++ /* flags for plugin */
++ /* unsigned long */
++ STRUCT_FLD(flags, 0UL)
+};
+
/***********************************************************************
*/
static ST_FIELD_INFO i_s_innodb_rseg_fields_info[] =
-@@ -3617,3 +3833,347 @@
- /* void* */
- STRUCT_FLD(__reserved1, NULL)
+@@ -3677,3 +3897,349 @@
+ /* unsigned long */
+ STRUCT_FLD(flags, 0UL),
};
+
+/***********************************************************************
+ STRUCT_FLD(version, 0x0100 /* 1.0 */),
+ STRUCT_FLD(status_vars, NULL),
+ STRUCT_FLD(system_vars, NULL),
-+ STRUCT_FLD(__reserved1, NULL)
++ STRUCT_FLD(__reserved1, NULL),
++ STRUCT_FLD(flags, 0UL)
+};
+
+UNIV_INTERN struct st_mysql_plugin i_s_innodb_index_stats =
+ STRUCT_FLD(version, 0x0100 /* 1.0 */),
+ STRUCT_FLD(status_vars, NULL),
+ STRUCT_FLD(system_vars, NULL),
-+ STRUCT_FLD(__reserved1, NULL)
++ STRUCT_FLD(__reserved1, NULL),
++ STRUCT_FLD(flags, 0UL)
+};
--- a/storage/innobase/handler/i_s.h
+++ b/storage/innobase/handler/i_s.h
+#define DICT_HDR_XTRADB_MARK 256 /* Flag to distinguish expansion of XtraDB */
/*-------------------------------------------------------------*/
- /* The field number of the page number field in the sys_indexes table
-@@ -144,11 +148,16 @@
+ /* The field numbers in the SYS_TABLES clustered index */
+@@ -146,11 +150,16 @@
#define DICT_SYS_INDEXES_TYPE_FIELD 6
#define DICT_SYS_INDEXES_NAME_FIELD 4
#include "dict0crea.ic"
--- a/storage/innobase/include/dict0dict.h
+++ b/storage/innobase/include/dict0dict.h
-@@ -1109,10 +1109,18 @@
+@@ -1126,10 +1126,18 @@
dict_update_statistics(
/*===================*/
dict_table_t* table, /*!< in/out: table */
/********************************************************************//**
Reserves the dictionary system mutex for MySQL. */
UNIV_INTERN
-@@ -1227,6 +1235,7 @@
+@@ -1244,6 +1252,7 @@
dict_table_t* sys_columns; /*!< SYS_COLUMNS table */
dict_table_t* sys_indexes; /*!< SYS_INDEXES table */
dict_table_t* sys_fields; /*!< SYS_FIELDS table */
should be called after the indexes for a table have been created.
--- a/storage/innobase/include/srv0srv.h
+++ b/storage/innobase/include/srv0srv.h
-@@ -211,6 +211,9 @@
+@@ -216,6 +216,9 @@
extern ibool srv_innodb_status;
extern unsigned long long srv_stats_sample_pages;
} else {
--- a/storage/innobase/row/row0ins.c
+++ b/storage/innobase/row/row0ins.c
-@@ -2013,6 +2013,8 @@
+@@ -2018,6 +2018,8 @@
}
#ifdef UNIV_DEBUG
/* Drop the index definition and the B-tree. */
--- a/storage/innobase/row/row0mysql.c
+++ b/storage/innobase/row/row0mysql.c
-@@ -921,6 +921,9 @@
+@@ -922,6 +922,9 @@
table->stat_modified_counter = counter + 1;
/* Calculate new statistics if 1 / 16 of table has been modified
since the last time a statistics batch was run, or if
stat_modified_counter > 2 000 000 000 (to avoid wrap-around).
-@@ -931,7 +934,7 @@
+@@ -932,7 +935,7 @@
|| ((ib_int64_t)counter > 16 + table->stat_n_rows / 16)) {
dict_update_statistics(table, FALSE /* update even if stats
}
}
-@@ -2076,6 +2079,71 @@
+@@ -2077,6 +2080,71 @@
}
/*********************************************************************//**
Scans a table create SQL string and adds to the data dictionary
the foreign key constraints declared in the string. This function
should be called after the indexes for a table have been created.
-@@ -3000,7 +3068,7 @@
+@@ -3001,7 +3069,7 @@
dict_table_autoinc_initialize(table, 1);
dict_table_autoinc_unlock(table);
dict_update_statistics(table, FALSE /* update even if stats are
trx_commit_for_mysql(trx);
-@@ -3302,6 +3370,8 @@
+@@ -3312,6 +3380,8 @@
" IF (SQL % NOTFOUND) THEN\n"
" found := 0;\n"
" ELSE\n"
" DELETE FROM SYS_INDEXES\n"
--- a/storage/innobase/row/row0row.c
+++ b/storage/innobase/row/row0row.c
-@@ -373,6 +373,14 @@
+@@ -364,6 +364,14 @@
rec_len = rec_offs_n_fields(offsets);
entry = dtuple_create(heap, rec_len);
dtuple_set_n_fields_cmp(entry,
-@@ -384,6 +392,14 @@
+@@ -375,6 +383,14 @@
for (i = 0; i < rec_len; i++) {
dfield = dtuple_get_nth_field(entry, i);
dfield = dtuple_get_nth_field(entry, i);
--- a/storage/innobase/srv/srv0srv.c
+++ b/storage/innobase/srv/srv0srv.c
-@@ -398,6 +398,9 @@
+@@ -400,6 +400,9 @@
/* When estimating number of different key values in an index, sample
this many index pages */
UNIV_INTERN unsigned long long srv_stats_sample_pages = 8;
UNIV_INTERN ibool srv_use_checksums = TRUE;
--- a/storage/innobase/trx/trx0rec.c
+++ b/storage/innobase/trx/trx0rec.c
-@@ -669,15 +669,27 @@
+@@ -669,14 +669,27 @@
/* Save to the undo log the old values of the columns to be updated. */
if (update) {
+ ulint extended = 0;
-
++
if (trx_undo_left(undo_page, ptr) < 5) {
return(0);
+ && index == UT_LIST_GET_FIRST(dict_sys->sys_stats->indexes)) {
+ for (i = 0; i < upd_get_n_fields(update); i++) {
+ ulint pos = upd_get_nth_field(update, i)->field_no;
-
-- for (i = 0; i < upd_get_n_fields(update); i++) {
++
+ if (pos >= rec_offs_n_fields(offsets)) {
+ extended++;
+ }
+ }
+
+ ptr += mach_write_compressed(ptr, upd_get_n_fields(update) - extended);
-+
+
+- for (i = 0; i < upd_get_n_fields(update); i++) {
+ for (i = 0; i < upd_get_n_fields(update) - extended; i++) {
ulint pos = upd_get_nth_field(update, i)->field_no;
+--- /dev/null
++++ b/mysql-test/r/percona_innodb_use_sys_stats_table.result
+@@ -0,0 +1,3 @@
++show variables like 'innodb_use_sys_stats%';
++Variable_name Value
++innodb_use_sys_stats_table ON
+--- /dev/null
++++ b/mysql-test/t/percona_innodb_use_sys_stats_table-master.opt
+@@ -0,0 +1 @@
++--innodb_use_sys_stats_table
+--- /dev/null
++++ b/mysql-test/t/percona_innodb_use_sys_stats_table.test
+@@ -0,0 +1,2 @@
++--source include/have_innodb.inc
++show variables like 'innodb_use_sys_stats%';