Commit e43791d4 authored by Sergey Vojtovich's avatar Sergey Vojtovich

Cleanup EITS

Moved EITS allocation inside read_statistics_for_tables_if_needed().
Removed redundant is_safe argument.
parent 4bcf5244
...@@ -4245,32 +4245,6 @@ open_and_process_table(THD *thd, TABLE_LIST *tables, uint *counter, uint flags, ...@@ -4245,32 +4245,6 @@ open_and_process_table(THD *thd, TABLE_LIST *tables, uint *counter, uint flags,
goto end; goto end;
} }
if (get_use_stat_tables_mode(thd) > NEVER && tables->table)
{
TABLE_SHARE *table_share= tables->table->s;
if (table_share && table_share->table_category == TABLE_CATEGORY_USER &&
table_share->tmp_table == NO_TMP_TABLE)
{
if (table_share->stats_cb.stats_can_be_read ||
!alloc_statistics_for_table_share(thd, table_share, FALSE))
{
if (table_share->stats_cb.stats_can_be_read)
{
KEY *key_info= table_share->key_info;
KEY *key_info_end= key_info + table_share->keys;
KEY *table_key_info= tables->table->key_info;
for ( ; key_info < key_info_end; key_info++, table_key_info++)
table_key_info->read_stats= key_info->read_stats;
Field **field_ptr= table_share->field;
Field **table_field_ptr= tables->table->field;
for ( ; *field_ptr; field_ptr++, table_field_ptr++)
(*table_field_ptr)->read_stats= (*field_ptr)->read_stats;
tables->table->stats_is_read= table_share->stats_cb.stats_is_read;
}
}
}
}
process_view_routines: process_view_routines:
/* /*
Again we may need cache all routines used by this view and add Again we may need cache all routines used by this view and add
......
...@@ -2216,8 +2216,6 @@ inline bool statistics_for_command_is_needed(THD *thd) ...@@ -2216,8 +2216,6 @@ inline bool statistics_for_command_is_needed(THD *thd)
thd Thread handler thd Thread handler
@param @param
table_share Table share for which the memory for statistical data is allocated table_share Table share for which the memory for statistical data is allocated
@param
is_safe TRUE <-> at any time only one thread can perform the function
@note @note
The function allocates the memory for the statistical data on a table in the The function allocates the memory for the statistical data on a table in the
...@@ -2226,8 +2224,6 @@ inline bool statistics_for_command_is_needed(THD *thd) ...@@ -2226,8 +2224,6 @@ inline bool statistics_for_command_is_needed(THD *thd)
mysql.index_stats. The memory is allocated for the statistics on the table, mysql.index_stats. The memory is allocated for the statistics on the table,
on the tables's columns, and on the table's indexes. The memory is allocated on the tables's columns, and on the table's indexes. The memory is allocated
in the table_share's mem_root. in the table_share's mem_root.
If the parameter is_safe is TRUE then it is guaranteed that at any given time
only one thread is executed the code of the function.
@retval @retval
0 If the memory for all statistical data has been successfully allocated 0 If the memory for all statistical data has been successfully allocated
...@@ -2246,16 +2242,10 @@ inline bool statistics_for_command_is_needed(THD *thd) ...@@ -2246,16 +2242,10 @@ inline bool statistics_for_command_is_needed(THD *thd)
Here the second and the third threads try to allocate the memory for Here the second and the third threads try to allocate the memory for
statistical data at the same time. The precautions are taken to statistical data at the same time. The precautions are taken to
guarantee the correctness of the allocation. guarantee the correctness of the allocation.
@note
Currently the function always is called with the parameter is_safe set
to FALSE.
*/ */
int alloc_statistics_for_table_share(THD* thd, TABLE_SHARE *table_share, static int alloc_statistics_for_table_share(THD* thd, TABLE_SHARE *table_share)
bool is_safe)
{ {
Field **field_ptr; Field **field_ptr;
KEY *key_info, *end; KEY *key_info, *end;
TABLE_STATISTICS_CB *stats_cb= &table_share->stats_cb; TABLE_STATISTICS_CB *stats_cb= &table_share->stats_cb;
...@@ -2268,13 +2258,11 @@ int alloc_statistics_for_table_share(THD* thd, TABLE_SHARE *table_share, ...@@ -2268,13 +2258,11 @@ int alloc_statistics_for_table_share(THD* thd, TABLE_SHARE *table_share,
if (!statistics_for_command_is_needed(thd)) if (!statistics_for_command_is_needed(thd))
DBUG_RETURN(1); DBUG_RETURN(1);
if (!is_safe) mysql_mutex_lock(&table_share->LOCK_share);
mysql_mutex_lock(&table_share->LOCK_share);
if (stats_cb->stats_can_be_read) if (stats_cb->stats_can_be_read)
{ {
if (!is_safe) mysql_mutex_unlock(&table_share->LOCK_share);
mysql_mutex_unlock(&table_share->LOCK_share);
DBUG_RETURN(0); DBUG_RETURN(0);
} }
...@@ -2285,8 +2273,7 @@ int alloc_statistics_for_table_share(THD* thd, TABLE_SHARE *table_share, ...@@ -2285,8 +2273,7 @@ int alloc_statistics_for_table_share(THD* thd, TABLE_SHARE *table_share,
sizeof(Table_statistics)); sizeof(Table_statistics));
if (!table_stats) if (!table_stats)
{ {
if (!is_safe) mysql_mutex_unlock(&table_share->LOCK_share);
mysql_mutex_unlock(&table_share->LOCK_share);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
memset(table_stats, 0, sizeof(Table_statistics)); memset(table_stats, 0, sizeof(Table_statistics));
...@@ -2358,8 +2345,7 @@ int alloc_statistics_for_table_share(THD* thd, TABLE_SHARE *table_share, ...@@ -2358,8 +2345,7 @@ int alloc_statistics_for_table_share(THD* thd, TABLE_SHARE *table_share,
if (column_stats && index_stats && idx_avg_frequency) if (column_stats && index_stats && idx_avg_frequency)
stats_cb->stats_can_be_read= TRUE; stats_cb->stats_can_be_read= TRUE;
if (!is_safe) mysql_mutex_unlock(&table_share->LOCK_share);
mysql_mutex_unlock(&table_share->LOCK_share);
DBUG_RETURN(0); DBUG_RETURN(0);
} }
...@@ -3264,6 +3250,35 @@ int read_statistics_for_tables_if_needed(THD *thd, TABLE_LIST *tables) ...@@ -3264,6 +3250,35 @@ int read_statistics_for_tables_if_needed(THD *thd, TABLE_LIST *tables)
DBUG_ENTER("read_statistics_for_tables_if_needed"); DBUG_ENTER("read_statistics_for_tables_if_needed");
for (TABLE_LIST *tl= tables; tl; tl= tl->next_global)
{
if (get_use_stat_tables_mode(thd) > NEVER && tl->table)
{
TABLE_SHARE *table_share= tl->table->s;
if (table_share && table_share->table_category == TABLE_CATEGORY_USER &&
table_share->tmp_table == NO_TMP_TABLE)
{
if (table_share->stats_cb.stats_can_be_read ||
!alloc_statistics_for_table_share(thd, table_share))
{
if (table_share->stats_cb.stats_can_be_read)
{
KEY *key_info= table_share->key_info;
KEY *key_info_end= key_info + table_share->keys;
KEY *table_key_info= tl->table->key_info;
for ( ; key_info < key_info_end; key_info++, table_key_info++)
table_key_info->read_stats= key_info->read_stats;
Field **field_ptr= table_share->field;
Field **table_field_ptr= tl->table->field;
for ( ; *field_ptr; field_ptr++, table_field_ptr++)
(*table_field_ptr)->read_stats= (*field_ptr)->read_stats;
tl->table->stats_is_read= table_share->stats_cb.stats_is_read;
}
}
}
}
}
DEBUG_SYNC(thd, "statistics_read_start"); DEBUG_SYNC(thd, "statistics_read_start");
if (!statistics_for_tables_is_needed(thd, tables)) if (!statistics_for_tables_is_needed(thd, tables))
......
...@@ -90,8 +90,6 @@ Use_stat_tables_mode get_use_stat_tables_mode(THD *thd) ...@@ -90,8 +90,6 @@ Use_stat_tables_mode get_use_stat_tables_mode(THD *thd)
int read_statistics_for_tables_if_needed(THD *thd, TABLE_LIST *tables); int read_statistics_for_tables_if_needed(THD *thd, TABLE_LIST *tables);
int collect_statistics_for_table(THD *thd, TABLE *table); int collect_statistics_for_table(THD *thd, TABLE *table);
int alloc_statistics_for_table_share(THD* thd, TABLE_SHARE *share,
bool is_safe);
void delete_stat_values_for_table_share(TABLE_SHARE *table_share); void delete_stat_values_for_table_share(TABLE_SHARE *table_share);
int alloc_statistics_for_table(THD *thd, TABLE *table); int alloc_statistics_for_table(THD *thd, TABLE *table);
int update_statistics_for_table(THD *thd, TABLE *table); int update_statistics_for_table(THD *thd, TABLE *table);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment