mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
dict0mem.c, dict0dict.c, row0mysql.c, dict0mem.h:
Do less statistics calculations for tables dict0mem.h, row0mysql.c: Make calculation of new statistics less frequent, because the statistics in 3.23.44 involves many random disk reads innobase/include/dict0mem.h: Do less statistics calculations for tables innobase/row/row0mysql.c: Do less statistics calculations for tables innobase/dict/dict0dict.c: Do less statistics calculations for tables innobase/dict/dict0mem.c: Do less statistics calculations for tables
This commit is contained in:
@ -455,7 +455,7 @@ dict_table_get(
|
|||||||
mutex_exit(&(dict_sys->mutex));
|
mutex_exit(&(dict_sys->mutex));
|
||||||
|
|
||||||
if (table != NULL) {
|
if (table != NULL) {
|
||||||
if (table->stat_last_estimate_counter == (ulint)(-1)) {
|
if (!table->stat_initialized) {
|
||||||
dict_update_statistics(table);
|
dict_update_statistics(table);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2578,6 +2578,8 @@ dict_update_statistics_low(
|
|||||||
ulint size;
|
ulint size;
|
||||||
ulint sum_of_index_sizes = 0;
|
ulint sum_of_index_sizes = 0;
|
||||||
|
|
||||||
|
printf("Updating statistics for table %s\n", table->name);
|
||||||
|
|
||||||
/* Find out the sizes of the indexes and how many different values
|
/* Find out the sizes of the indexes and how many different values
|
||||||
for the key they approximately have */
|
for the key they approximately have */
|
||||||
|
|
||||||
@ -2612,9 +2614,11 @@ dict_update_statistics_low(
|
|||||||
table->stat_clustered_index_size = index->stat_index_size;
|
table->stat_clustered_index_size = index->stat_index_size;
|
||||||
|
|
||||||
table->stat_sum_of_other_index_sizes = sum_of_index_sizes
|
table->stat_sum_of_other_index_sizes = sum_of_index_sizes
|
||||||
- index->stat_index_size;
|
- index->stat_index_size;
|
||||||
|
|
||||||
table->stat_last_estimate_counter = table->stat_modif_counter;
|
table->stat_initialized = TRUE;
|
||||||
|
|
||||||
|
table->stat_modified_counter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
|
@ -73,9 +73,9 @@ dict_mem_table_create(
|
|||||||
|
|
||||||
table->does_not_fit_in_memory = FALSE;
|
table->does_not_fit_in_memory = FALSE;
|
||||||
|
|
||||||
table->stat_last_estimate_counter = (ulint)(-1);
|
table->stat_initialized = FALSE;
|
||||||
|
|
||||||
table->stat_modif_counter = 0;
|
table->stat_modified_counter = 0;
|
||||||
|
|
||||||
mutex_create(&(table->autoinc_mutex));
|
mutex_create(&(table->autoinc_mutex));
|
||||||
mutex_set_level(&(table->autoinc_mutex), SYNC_DICT_AUTOINC_MUTEX);
|
mutex_set_level(&(table->autoinc_mutex), SYNC_DICT_AUTOINC_MUTEX);
|
||||||
|
@ -348,20 +348,20 @@ struct dict_table_struct{
|
|||||||
database pages */
|
database pages */
|
||||||
ulint stat_sum_of_other_index_sizes;
|
ulint stat_sum_of_other_index_sizes;
|
||||||
/* other indexes in database pages */
|
/* other indexes in database pages */
|
||||||
ulint stat_last_estimate_counter;
|
ibool stat_initialized; /* TRUE if statistics have
|
||||||
/* when the estimates were last time
|
been calculated the first time
|
||||||
calculated; a value (ulint)-1 denotes that
|
after database startup or table creation */
|
||||||
they have not yet been calculated for this
|
ulint stat_modified_counter;
|
||||||
table (or the counter has wrapped over) */
|
|
||||||
ulint stat_modif_counter;
|
|
||||||
/* when a row is inserted, updated, or deleted,
|
/* when a row is inserted, updated, or deleted,
|
||||||
we add the row length to this number; we
|
we add the row length to this number; we
|
||||||
calculate new estimates for the stat_...
|
calculate new estimates for the stat_...
|
||||||
values for the table and the indexes at an
|
values for the table and the indexes at an
|
||||||
interval of DICT_STAT_CALCULATE_INTERVAL,
|
interval of 2 GB or when about 1 / 16 of table
|
||||||
but for small tables more often, also
|
has been modified; also
|
||||||
when the estimate operation is called
|
when the estimate operation is called
|
||||||
for MySQL SHOW TABLE STATUS; this counter
|
for MySQL SHOW TABLE STATUS; the counter is
|
||||||
|
reset to zero at statistics calculation;
|
||||||
|
this counter
|
||||||
is not protected by any latch, because this
|
is not protected by any latch, because this
|
||||||
is only used for heuristics */
|
is only used for heuristics */
|
||||||
/*----------------------*/
|
/*----------------------*/
|
||||||
@ -377,10 +377,6 @@ struct dict_table_struct{
|
|||||||
ulint magic_n;/* magic number */
|
ulint magic_n;/* magic number */
|
||||||
};
|
};
|
||||||
#define DICT_TABLE_MAGIC_N 76333786
|
#define DICT_TABLE_MAGIC_N 76333786
|
||||||
|
|
||||||
/* Statistics are calculated at least with this interval; see the struct
|
|
||||||
above */
|
|
||||||
#define DICT_STAT_CALCULATE_INTERVAL (UNIV_PAGE_SIZE * 8)
|
|
||||||
|
|
||||||
/* Data structure for a stored procedure */
|
/* Data structure for a stored procedure */
|
||||||
struct dict_proc_struct{
|
struct dict_proc_struct{
|
||||||
|
@ -432,19 +432,24 @@ row_update_statistics_if_needed(
|
|||||||
row_prebuilt_t* prebuilt) /* in: prebuilt struct */
|
row_prebuilt_t* prebuilt) /* in: prebuilt struct */
|
||||||
{
|
{
|
||||||
ulint counter;
|
ulint counter;
|
||||||
ulint old_counter;
|
|
||||||
|
|
||||||
counter = prebuilt->table->stat_modif_counter;
|
counter = prebuilt->table->stat_modified_counter;
|
||||||
|
|
||||||
counter += prebuilt->mysql_row_len;
|
/* Since the physical size of an InnoDB row is bigger than the
|
||||||
prebuilt->table->stat_modif_counter = counter;
|
MySQL row len, we put a safety factor 2 below */
|
||||||
|
|
||||||
old_counter = prebuilt->table->stat_last_estimate_counter;
|
counter += 2 * prebuilt->mysql_row_len;
|
||||||
|
|
||||||
if (counter - old_counter >= DICT_STAT_CALCULATE_INTERVAL
|
prebuilt->table->stat_modified_counter = counter;
|
||||||
|| counter - old_counter >=
|
|
||||||
(UNIV_PAGE_SIZE
|
/* Calculate new statistics if 1 / 16 of table has been modified
|
||||||
* prebuilt->table->stat_clustered_index_size / 2)) {
|
since the last time a statistics batch was run, or if
|
||||||
|
stat_modified_counter > 2 000 000 000 (to avoid wrap-around) */
|
||||||
|
|
||||||
|
if (counter > 2000000000
|
||||||
|
|| ((ib_longlong)counter >
|
||||||
|
(UNIV_PAGE_SIZE * prebuilt->table->stat_clustered_index_size)
|
||||||
|
/ 16)) {
|
||||||
|
|
||||||
dict_update_statistics(prebuilt->table);
|
dict_update_statistics(prebuilt->table);
|
||||||
}
|
}
|
||||||
@ -1019,6 +1024,26 @@ row_create_table_for_mysql(
|
|||||||
os_event_set(srv_lock_timeout_thread_event);
|
os_event_set(srv_lock_timeout_thread_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
keywordlen = ut_strlen("innodb_mem_validate");
|
||||||
|
|
||||||
|
if (namelen >= keywordlen
|
||||||
|
&& 0 == ut_memcmp(table->name + namelen - keywordlen,
|
||||||
|
"innodb_mem_validate", keywordlen)) {
|
||||||
|
|
||||||
|
/* We define here a debugging feature intended for
|
||||||
|
developers */
|
||||||
|
|
||||||
|
printf("Validating InnoDB memory:\n"
|
||||||
|
"to use this feature you must compile InnoDB with\n"
|
||||||
|
"UNIV_MEM_DEBUG defined in univ.i and the server must be\n"
|
||||||
|
"quiet because allocation from a mem heap is not protected\n"
|
||||||
|
"by any semaphore.\n");
|
||||||
|
|
||||||
|
ut_a(mem_validate());
|
||||||
|
|
||||||
|
printf("Memory validated\n");
|
||||||
|
}
|
||||||
|
|
||||||
/* Serialize data dictionary operations with dictionary mutex:
|
/* Serialize data dictionary operations with dictionary mutex:
|
||||||
no deadlocks can occur then in these operations */
|
no deadlocks can occur then in these operations */
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user