diff options
author | Igor Babaev <igor@askmonty.org> | 2013-03-11 07:44:24 -0700 |
---|---|---|
committer | Igor Babaev <igor@askmonty.org> | 2013-03-11 07:44:24 -0700 |
commit | fc1c8ffdadfd14eb51969ecfde43e3204f10f6f8 (patch) | |
tree | 70ee4b3628cc62a706476d6c7b873fcfc9aa0e10 /sql/sql_statistics.cc | |
parent | 938d47dcdc50ae4f127197ed72fd044b33ea7524 (diff) | |
download | mariadb-git-fc1c8ffdadfd14eb51969ecfde43e3204f10f6f8.tar.gz |
The pilot patch for mwl#253.
Diffstat (limited to 'sql/sql_statistics.cc')
-rw-r--r-- | sql/sql_statistics.cc | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/sql/sql_statistics.cc b/sql/sql_statistics.cc index e34b4b21819..5338632067a 100644 --- a/sql/sql_statistics.cc +++ b/sql/sql_statistics.cc @@ -26,6 +26,7 @@ #include "sql_base.h" #include "key.h" #include "sql_statistics.h" +#include "opt_range.h" #include "my_atomic.h" /* @@ -3054,3 +3055,51 @@ void set_statistics_for_table(THD *thd, TABLE *table) key_info->read_stats->get_avg_frequency(0) > 0.5); } } + + +double get_column_avg_frequency(Field * field) +{ + double res; + TABLE *table= field->table; + Column_statistics *col_stats= table->s->field[field->field_index]->read_stats; + + if (!col_stats) + res= table->stat_records(); + else + res= col_stats->get_avg_frequency(); + return res; +} + + +double get_column_range_cardinality(Field *field, + key_range *min_endp, + key_range *max_endp) +{ + double res; + TABLE *table= field->table; + Column_statistics *col_stats= table->field[field->field_index]->read_stats; + + if (!col_stats) + res= table->stat_records(); + else if (min_endp->length == max_endp->length && + !memcmp(min_endp->key, max_endp->key, min_endp->length)) + { + res= col_stats->get_avg_frequency(); + } + else + { + if (col_stats->min_value && col_stats->max_value) + { + store_key_image_to_rec(field, (uchar *) min_endp->key, min_endp->length); + double min_mp_pos= field->middle_point_pos(col_stats->min_value, + col_stats->max_value); + store_key_image_to_rec(field, (uchar *) max_endp->key, max_endp->length); + double max_mp_pos= field->middle_point_pos(col_stats->min_value, + col_stats->max_value); + res= table->stat_records() * (max_mp_pos - min_mp_pos); + } + else + res= table->stat_records(); + } + return res; +} |