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

Function read_statistics_for_table

sql/sql_statistics.cc:3034–3177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3032*/
3033
3034static
3035TABLE_STATISTICS_CB*
3036read_statistics_for_table(THD *thd, TABLE *table,
3037 TABLE_LIST *stat_tables, bool force_reload,
3038 bool want_histograms)
3039{
3040 uint i;
3041 TABLE *stat_table;
3042 Field *table_field;
3043 Field **field_ptr;
3044 KEY *key_info, *key_info_end;
3045 TABLE_SHARE *table_share= table->s;
3046 DBUG_ENTER("read_statistics_for_table");
3047
3048 if (!force_reload && table_share->stats_cb &&
3049 (!want_histograms || !table_share->histograms_exists()))
3050 {
3051 if (table->stats_cb == table_share->stats_cb)
3052 DBUG_RETURN(table->stats_cb); // Use current
3053 table->update_engine_independent_stats(); // Copy table_share->stats_cb
3054 DBUG_RETURN(table->stats_cb);
3055 }
3056
3057 /*
3058 Read data into a new TABLE_STATISTICS_CB object and replace
3059 TABLE_SHARE::stats_cb with this new one once the reading is finished
3060 */
3061 TABLE_STATISTICS_CB *new_stats_cb;
3062 if (!(new_stats_cb= new TABLE_STATISTICS_CB))
3063 DBUG_RETURN(0); /* purecov: inspected */
3064
3065 if (alloc_engine_independent_statistics(thd, table_share, new_stats_cb))
3066 {
3067 /* purecov: begin inspected */
3068 delete new_stats_cb;
3069 DBUG_RETURN(0);
3070 /* purecov: end */
3071 }
3072
3073 /* Don't write warnings for internal field conversions */
3074 Check_level_instant_set check_level_save(thd, CHECK_FIELD_IGNORE);
3075
3076 /* Read statistics from the statistical table table_stats */
3077 Table_statistics *read_stats= new_stats_cb->table_stats;
3078 stat_table= stat_tables[TABLE_STAT].table;
3079 char statbuf[sizeof(Index_stat)];
3080 static_assert(sizeof(statbuf) >= sizeof(Table_stat), "");
3081 static_assert(sizeof(statbuf) >= sizeof(Column_stat), "");
3082 Table_stat &table_stat= *new(statbuf) Table_stat(stat_table, table);
3083 table_stat.set_key_fields();
3084 if (table_stat.get_stat_values(new_stats_cb->table_stats))
3085 new_stats_cb->stats_available|= TABLE_STAT_TABLE;
3086
3087 /* Read statistics from the statistical table column_stats */
3088 stat_table= stat_tables[COLUMN_STAT].table;
3089 Column_stat &column_stat= *new(statbuf) Column_stat(stat_table, table);
3090 Column_statistics *column_statistics= new_stats_cb->table_stats->column_stats;
3091 for (field_ptr= table_share->field;

Callers 1

Calls 8

mark_stats_as_readMethod · 0.80
histograms_existsMethod · 0.45
set_key_fieldsMethod · 0.45
get_stat_valuesMethod · 0.45
get_avg_frequencyMethod · 0.45
set_avg_frequencyMethod · 0.45

Tested by

no test coverage detected