Skip to content

Commit a0b4a86

Browse files
committed
Code cleanup part #2.
1 parent 1496a52 commit a0b4a86

File tree

2 files changed

+27
-45
lines changed

2 files changed

+27
-45
lines changed

sql/sql_statistics.cc

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,8 +1292,7 @@ void Histogram_json::init_for_collection(MEM_ROOT *mem_root,
12921292
Histogram_type htype_arg,
12931293
ulonglong size_arg)
12941294
{
1295-
type= htype_arg;
1296-
//values_ = (uchar*)alloc_root(mem_root, size_arg);
1295+
DBUG_ASSERT(htype_arg == JSON_HB);
12971296
size= (uint8) size_arg;
12981297
}
12991298

@@ -1302,15 +1301,18 @@ void Histogram_json::init_for_collection(MEM_ROOT *mem_root,
13021301
@brief
13031302
Parse the histogram from its on-disk representation
13041303
1304+
@return
1305+
false OK
1306+
True Error
13051307
*/
13061308

13071309
bool Histogram_json::parse(MEM_ROOT *mem_root, Field *field,
13081310
Histogram_type type_arg, const uchar *ptr,
13091311
uint size_arg)
13101312
{
13111313
DBUG_ENTER("Histogram_json::parse");
1314+
DBUG_ASSERT(type_arg == JSON_HB);
13121315
size = (uint8) size_arg;
1313-
type = type_arg;
13141316
const char *json = (char *)ptr;
13151317
int vt;
13161318
std::vector<std::string> hist_buckets_text;
@@ -1595,6 +1597,7 @@ void Histogram_json::serialize(Field *field)
15951597
field->store((char*)json_text, strlen((char*)json_text), &my_charset_bin);
15961598
}
15971599

1600+
15981601
int Histogram_json::find_bucket(Field *field, const uchar *endpoint)
15991602
{
16001603
int low = 0;
@@ -2061,15 +2064,22 @@ class Histogram_builder_json : public Histogram_builder
20612064
}
20622065
};
20632066

2067+
20642068
Histogram_base *create_histogram(Histogram_type hist_type)
20652069
{
2066-
// assumes the caller already checked for invalid histograms
2067-
if (hist_type == JSON_HB)
2068-
return new Histogram_json;
2069-
else
2070-
return new Histogram_binary;
2070+
switch (hist_type) {
2071+
case SINGLE_PREC_HB:
2072+
case DOUBLE_PREC_HB:
2073+
return new Histogram_binary();
2074+
case JSON_HB:
2075+
return new Histogram_json();
2076+
default:
2077+
DBUG_ASSERT(0);
2078+
}
2079+
return NULL;
20712080
}
20722081

2082+
20732083
bool json_get_array_items(const char *json, const char *json_end, int *value_type, std::vector<std::string> &container) {
20742084
json_engine_t je;
20752085
int vl;
@@ -2255,16 +2265,6 @@ class Count_distinct_field: public Sql_alloc
22552265
return distincts_single_occurence;
22562266
}
22572267

2258-
/*
2259-
@brief
2260-
Get the size of the histogram in bytes built for table_field
2261-
*/
2262-
/*
2263-
uint get_hist_size()
2264-
{
2265-
return table_field->collected_stats->histogram.get_size();
2266-
}*/
2267-
22682268
/*
22692269
@brief
22702270
Get the pointer to the histogram built for table_field
@@ -2916,27 +2916,6 @@ bool Column_statistics_collected::add()
29162916
return err;
29172917
}
29182918

2919-
2920-
/*
2921-
Create an empty Histogram object from histogram_type.
2922-
2923-
Note: it is not yet clear whether collection-time histogram should be the same
2924-
as lookup-time histogram. At the moment, they are.
2925-
*/
2926-
2927-
Histogram_base * get_histogram_by_type(MEM_ROOT *mem_root, Histogram_type hist_type) {
2928-
switch (hist_type) {
2929-
case SINGLE_PREC_HB:
2930-
case DOUBLE_PREC_HB:
2931-
return new Histogram_binary();
2932-
case JSON_HB:
2933-
return new Histogram_json();
2934-
default:
2935-
DBUG_ASSERT(0);
2936-
}
2937-
return NULL;
2938-
};
2939-
29402919
/**
29412920
@brief
29422921
Get the results of aggregation when collecting the statistics on a column
@@ -3488,15 +3467,13 @@ int read_statistics_for_table(THD *thd, TABLE *table, TABLE_LIST *stat_tables)
34883467

34893468
/* Read statistics from the statistical table column_stats */
34903469
stat_table= stat_tables[COLUMN_STAT].table;
3491-
//ulong total_hist_size= 0;
34923470
bool have_histograms= false;
34933471
Column_stat column_stat(stat_table, table);
34943472
for (field_ptr= table_share->field; *field_ptr; field_ptr++)
34953473
{
34963474
table_field= *field_ptr;
34973475
column_stat.set_key_fields(table_field);
34983476
column_stat.get_stat_values();
3499-
//total_hist_size+= table_field->read_stats->histogram.get_size();
35003477
if (table_field->read_stats->histogram_type_on_disk != INVALID_HISTOGRAM)
35013478
have_histograms= true;
35023479
}

sql/sql_statistics.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#define SQL_STATISTICS_H
1818

1919
#include <vector>
20+
#include <string>
21+
2022
/*
2123
For COMPLEMENTARY_FOR_QUERIES and PREFERABLY_FOR_QUERIES they are
2224
similar to the COMPLEMENTARY and PREFERABLY respectively except that
@@ -279,7 +281,7 @@ class Histogram_binary : public Histogram_base
279281

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

282-
bool is_available() override { return get_size() > 0 && (values!=NULL); }
284+
bool is_available() override { return (values!=NULL); }
283285

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

336338
/*
337339
An equi-height histogram which stores real values for bucket bounds.
340+
341+
Handles @@histogram_type=JSON_HB
342+
343+
On-disk format is JSON:
344+
(TODO description)
338345
*/
339346

340347
class Histogram_json : public Histogram_base
341348
{
342349
private:
343-
Histogram_type type;
344-
uint8 size; /* Number of elements in the histogram*/
350+
uint8 size; /* Number of elements in the histogram */
345351

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

415421
/* Array of records per key for index prefixes */
416422
ulonglong *idx_avg_frequency;
417-
//uchar *histograms; /* Sequence of histograms */
418423
};
419424

420425

0 commit comments

Comments
 (0)