MCPcopy Create free account
hub / github.com/MariaDB/server / update_statistics_for_table

Function update_statistics_for_table

sql/sql_statistics.cc:2908–2995  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2906*/
2907
2908int update_statistics_for_table(THD *thd, TABLE *table)
2909{
2910 TABLE_LIST tables[STATISTICS_TABLES];
2911 uint i;
2912 int err;
2913 enum_binlog_format save_binlog_format;
2914 int rc= 0;
2915 TABLE *stat_table;
2916 DBUG_ENTER("update_statistics_for_table");
2917
2918 DEBUG_SYNC(thd, "statistics_update_start");
2919
2920 start_new_trans new_trans(thd);
2921
2922 if (open_stat_tables(thd, tables, TRUE))
2923 {
2924 new_trans.restore_old_transaction();
2925 DBUG_RETURN(0);
2926 }
2927
2928 /*
2929 Ensure that no one is reading statistics while we are writing them
2930 This ensures that statistics is always read consistently
2931 */
2932 mysql_mutex_lock(&table->s->LOCK_statistics);
2933
2934 save_binlog_format= thd->set_current_stmt_binlog_format_stmt();
2935
2936 char statbuf[sizeof(Index_stat)];
2937 static_assert(sizeof(statbuf) >= sizeof(Table_stat), "");
2938 static_assert(sizeof(statbuf) >= sizeof(Column_stat), "");
2939
2940 /* Update the statistical table table_stats */
2941 stat_table= tables[TABLE_STAT].table;
2942 Table_stat &table_stat= *new(statbuf) Table_stat(stat_table, table);
2943 restore_record(stat_table, s->default_values);
2944 table_stat.set_key_fields();
2945 err= table_stat.update_stat();
2946 if (err)
2947 rc= 1;
2948
2949 /* Update the statistical table column_stats */
2950 stat_table= tables[COLUMN_STAT].table;
2951 Column_stat &column_stat= *new(statbuf) Column_stat(stat_table, table);
2952 for (Field **field_ptr= table->field; *field_ptr; field_ptr++)
2953 {
2954 Field *table_field= *field_ptr;
2955 if (!table_field->collected_stats)
2956 continue;
2957 restore_record(stat_table, s->default_values);
2958 column_stat.set_key_fields(table_field);
2959 err= column_stat.update_stat();
2960 if (err && !rc)
2961 rc= 1;
2962 }
2963
2964 /* Update the statistical table index_stats */
2965 stat_table= tables[INDEX_STAT].table;

Callers 1

mysql_admin_tableFunction · 0.85

Calls 10

open_stat_tablesFunction · 0.85
update_statMethod · 0.80
actual_n_key_partsMethod · 0.80
set_key_fieldsMethod · 0.45
is_setMethod · 0.45
extraMethod · 0.45

Tested by

no test coverage detected