Skip to content

Commit

Permalink
Code cleanups part #3
Browse files Browse the repository at this point in the history
  • Loading branch information
spetrunia committed Jan 19, 2022
1 parent 859c14f commit 899dfb0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
12 changes: 7 additions & 5 deletions sql/sql_statistics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1967,7 +1967,7 @@ class Stat_table_write_iter

class Histogram_builder
{
public:
protected:
Field *column; /* table field for which the histogram is built */
uint col_length; /* size of this field */
ha_rows records; /* number of records the histogram is built for */
Expand All @@ -1982,6 +1982,7 @@ class Histogram_builder
/* number of distinct values that occured only once */
ulonglong count_distinct_single_occurence;

public:
Histogram_builder(Field *col, uint col_len, ha_rows rows)
: column(col), col_length(col_len), records(rows)
{
Expand Down Expand Up @@ -2934,7 +2935,8 @@ bool Column_statistics_collected::add()
*/

inline
void Column_statistics_collected::finish(MEM_ROOT *mem_root, ha_rows rows, double sample_fraction)
void Column_statistics_collected::finish(MEM_ROOT *mem_root, ha_rows rows,
double sample_fraction)
{
double val;

Expand Down Expand Up @@ -3486,7 +3488,7 @@ int read_statistics_for_table(THD *thd, TABLE *table, TABLE_LIST *stat_tables)
if (table_field->read_stats->histogram_type_on_disk != INVALID_HISTOGRAM)
have_histograms= true;
}
table_share->stats_cb.total_hist_size= have_histograms? 1:0; // total_hist_size
table_share->stats_cb.have_histograms= have_histograms;

/* Read statistics from the statistical table index_stats */
stat_table= stat_tables[INDEX_STAT].table;
Expand Down Expand Up @@ -3626,7 +3628,7 @@ int read_histograms_for_table(THD *thd, TABLE *table, TABLE_LIST *stat_tables)
{
TABLE_STATISTICS_CB *stats_cb= &table->s->stats_cb;
DBUG_ENTER("read_histograms_for_table");

if (stats_cb->start_histograms_load())
{
Column_stat column_stat(stat_tables[COLUMN_STAT].table, table);
Expand Down Expand Up @@ -4547,7 +4549,7 @@ double Histogram_binary::range_selectivity(Field *field,
}

/*
Check whether the table is one of the persistent statistical tables.
Check whether the table is one of the persistent statistical tables.
*/
bool is_stat_table(const LEX_CSTRING *db, LEX_CSTRING *table)
{
Expand Down
13 changes: 5 additions & 8 deletions sql/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -681,22 +681,19 @@ class TABLE_STATISTICS_CB
Table_statistics *table_stats; /* Structure to access the statistical data */

/*
Total size of all histograms. A value of 0 means historams are not present,
and histograms_are_ready() can finish sooner.
Currently we just set it to 1 when we expect to load histograms.
histogram-todo: rename this or even remove?
Whether the table has histograms.
(If the table has none, histograms_are_ready() can finish sooner)
*/
ulong total_hist_size;
bool have_histograms;

bool histograms_are_ready() const
{
return !total_hist_size || hist_state.is_ready();
return !have_histograms || hist_state.is_ready();
}

bool start_histograms_load()
{
return total_hist_size && hist_state.start_load();
return have_histograms && hist_state.start_load();
}

void end_histograms_load() { hist_state.end_load(); }
Expand Down

0 comments on commit 899dfb0

Please sign in to comment.