Skip to content

Commit

Permalink
Code cleanup part #2.
Browse files Browse the repository at this point in the history
  • Loading branch information
spetrunia committed Jan 19, 2022
1 parent 1496a52 commit a0b4a86
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 45 deletions.
59 changes: 18 additions & 41 deletions sql/sql_statistics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1292,8 +1292,7 @@ void Histogram_json::init_for_collection(MEM_ROOT *mem_root,
Histogram_type htype_arg,
ulonglong size_arg)
{
type= htype_arg;
//values_ = (uchar*)alloc_root(mem_root, size_arg);
DBUG_ASSERT(htype_arg == JSON_HB);
size= (uint8) size_arg;
}

Expand All @@ -1302,15 +1301,18 @@ void Histogram_json::init_for_collection(MEM_ROOT *mem_root,
@brief
Parse the histogram from its on-disk representation
@return
false OK
True Error
*/

bool Histogram_json::parse(MEM_ROOT *mem_root, Field *field,
Histogram_type type_arg, const uchar *ptr,
uint size_arg)
{
DBUG_ENTER("Histogram_json::parse");
DBUG_ASSERT(type_arg == JSON_HB);
size = (uint8) size_arg;
type = type_arg;
const char *json = (char *)ptr;
int vt;
std::vector<std::string> hist_buckets_text;
Expand Down Expand Up @@ -1595,6 +1597,7 @@ void Histogram_json::serialize(Field *field)
field->store((char*)json_text, strlen((char*)json_text), &my_charset_bin);
}


int Histogram_json::find_bucket(Field *field, const uchar *endpoint)
{
int low = 0;
Expand Down Expand Up @@ -2061,15 +2064,22 @@ class Histogram_builder_json : public Histogram_builder
}
};


Histogram_base *create_histogram(Histogram_type hist_type)
{
// assumes the caller already checked for invalid histograms
if (hist_type == JSON_HB)
return new Histogram_json;
else
return new Histogram_binary;
switch (hist_type) {
case SINGLE_PREC_HB:
case DOUBLE_PREC_HB:
return new Histogram_binary();
case JSON_HB:
return new Histogram_json();
default:
DBUG_ASSERT(0);
}
return NULL;
}


bool json_get_array_items(const char *json, const char *json_end, int *value_type, std::vector<std::string> &container) {
json_engine_t je;
int vl;
Expand Down Expand Up @@ -2255,16 +2265,6 @@ class Count_distinct_field: public Sql_alloc
return distincts_single_occurence;
}

/*
@brief
Get the size of the histogram in bytes built for table_field
*/
/*
uint get_hist_size()
{
return table_field->collected_stats->histogram.get_size();
}*/

/*
@brief
Get the pointer to the histogram built for table_field
Expand Down Expand Up @@ -2916,27 +2916,6 @@ bool Column_statistics_collected::add()
return err;
}


/*
Create an empty Histogram object from histogram_type.
Note: it is not yet clear whether collection-time histogram should be the same
as lookup-time histogram. At the moment, they are.
*/

Histogram_base * get_histogram_by_type(MEM_ROOT *mem_root, Histogram_type hist_type) {
switch (hist_type) {
case SINGLE_PREC_HB:
case DOUBLE_PREC_HB:
return new Histogram_binary();
case JSON_HB:
return new Histogram_json();
default:
DBUG_ASSERT(0);
}
return NULL;
};

/**
@brief
Get the results of aggregation when collecting the statistics on a column
Expand Down Expand Up @@ -3488,15 +3467,13 @@ int read_statistics_for_table(THD *thd, TABLE *table, TABLE_LIST *stat_tables)

/* Read statistics from the statistical table column_stats */
stat_table= stat_tables[COLUMN_STAT].table;
//ulong total_hist_size= 0;
bool have_histograms= false;
Column_stat column_stat(stat_table, table);
for (field_ptr= table_share->field; *field_ptr; field_ptr++)
{
table_field= *field_ptr;
column_stat.set_key_fields(table_field);
column_stat.get_stat_values();
//total_hist_size+= table_field->read_stats->histogram.get_size();
if (table_field->read_stats->histogram_type_on_disk != INVALID_HISTOGRAM)
have_histograms= true;
}
Expand Down
13 changes: 9 additions & 4 deletions sql/sql_statistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#define SQL_STATISTICS_H

#include <vector>
#include <string>

/*
For COMPLEMENTARY_FOR_QUERIES and PREFERABLY_FOR_QUERIES they are
similar to the COMPLEMENTARY and PREFERABLY respectively except that
Expand Down Expand Up @@ -279,7 +281,7 @@ class Histogram_binary : public Histogram_base

uint get_size() override {return (uint)size;}

bool is_available() override { return get_size() > 0 && (values!=NULL); }
bool is_available() override { return (values!=NULL); }

/*
This function checks that histograms should be usable only when
Expand Down Expand Up @@ -335,13 +337,17 @@ class Histogram_binary : public Histogram_base

/*
An equi-height histogram which stores real values for bucket bounds.
Handles @@histogram_type=JSON_HB
On-disk format is JSON:
(TODO description)
*/

class Histogram_json : public Histogram_base
{
private:
Histogram_type type;
uint8 size; /* Number of elements in the histogram*/
uint8 size; /* Number of elements in the histogram */

/* Collection-time only: collected histogram in the JSON form. */
uchar *json_text;
Expand Down Expand Up @@ -414,7 +420,6 @@ class Table_statistics

/* Array of records per key for index prefixes */
ulonglong *idx_avg_frequency;
//uchar *histograms; /* Sequence of histograms */
};


Expand Down

0 comments on commit a0b4a86

Please sign in to comment.