diff options
author | unknown <sanja@askmonty.org> | 2013-04-20 23:30:21 +0300 |
---|---|---|
committer | unknown <sanja@askmonty.org> | 2013-04-20 23:30:21 +0300 |
commit | 2e830cfbc81c545de135b4fbee751141741a11ab (patch) | |
tree | 6ce8d03cc281bba69a63ef8fa12cd0e7181e811e /sql | |
parent | 7efad6330fc3ca119599d6311dcd251fc8f9fbb5 (diff) | |
download | mariadb-git-2e830cfbc81c545de135b4fbee751141741a11ab.tar.gz |
MDEV-4402 A function to visualize histograms data.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/item_create.cc | 21 | ||||
-rw-r--r-- | sql/item_strfunc.cc | 77 | ||||
-rw-r--r-- | sql/item_strfunc.h | 16 | ||||
-rw-r--r-- | sql/sys_vars.cc | 3 |
4 files changed, 115 insertions, 2 deletions
diff --git a/sql/item_create.cc b/sql/item_create.cc index c1cefed6f8b..ce4dc7ced8f 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -614,6 +614,19 @@ protected: }; +class Create_func_decode_histogram : public Create_func_arg2 +{ +public: + Item *create_2_arg(THD *thd, Item *arg1, Item *arg2); + + static Create_func_decode_histogram s_singleton; + +protected: + Create_func_decode_histogram() {} + virtual ~Create_func_decode_histogram() {} +}; + + class Create_func_concat_ws : public Create_native_func { public: @@ -3231,6 +3244,13 @@ Create_func_concat::create_native(THD *thd, LEX_STRING name, return new (thd->mem_root) Item_func_concat(*item_list); } +Create_func_decode_histogram Create_func_decode_histogram::s_singleton; + +Item * +Create_func_decode_histogram::create_2_arg(THD *thd, Item *arg1, Item *arg2) +{ + return new (thd->mem_root) Item_func_decode_histogram(arg1, arg2); +} Create_func_concat_ws Create_func_concat_ws::s_singleton; @@ -5377,6 +5397,7 @@ static Native_func_registry func_array[] = { { C_STRING_WITH_LEN("DAYOFYEAR") }, BUILDER(Create_func_dayofyear)}, { { C_STRING_WITH_LEN("DECODE") }, BUILDER(Create_func_decode)}, { { C_STRING_WITH_LEN("DEGREES") }, BUILDER(Create_func_degrees)}, + { { C_STRING_WITH_LEN("DECODE_HISTOGRAM") }, BUILDER(Create_func_decode_histogram)}, { { C_STRING_WITH_LEN("DES_DECRYPT") }, BUILDER(Create_func_des_decrypt)}, { { C_STRING_WITH_LEN("DES_ENCRYPT") }, BUILDER(Create_func_des_encrypt)}, { { C_STRING_WITH_LEN("DIMENSION") }, GEOM_BUILDER(Create_func_dimension)}, diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 93569082d74..5cce910758a 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -60,6 +60,7 @@ C_MODE_START C_MODE_END #include "sql_show.h" // append_identifier #include <sql_repl.h> +#include "sql_statistics.h" /** @todo Remove this. It is not safe to use a shared String object. @@ -472,6 +473,82 @@ void Item_func_aes_decrypt::fix_length_and_dec() set_persist_maybe_null(1); } +/////////////////////////////////////////////////////////////////////////////// + + +const char *histogram_types[] = + {"SINGLE_PREC_HB", "DOUBLE_PREC_HB", 0}; +static TYPELIB hystorgam_types_typelib= + { array_elements(histogram_types), + "histogram_types", + histogram_types, NULL}; +const char *representation_by_type[]= {"%.3f", "%.5f"}; + +String *Item_func_decode_histogram::val_str(String *str) +{ + DBUG_ASSERT(fixed == 1); + char buff[STRING_BUFFER_USUAL_SIZE]; + String *res, tmp(buff, sizeof(buff), &my_charset_bin); + int type; + + tmp.length(0); + if (!(res= args[1]->val_str(&tmp)) || + (type= find_type(res->c_ptr_safe(), + &hystorgam_types_typelib, MYF(0))) <= 0) + { + null_value= 1; + return 0; + } + type--; + + tmp.length(0); + if (!(res= args[0]->val_str(&tmp))) + { + null_value= 1; + return 0; + } + if (type == DOUBLE_PREC_HB && res->length() % 2 != 0) + res->length(res->length() - 1); // one byte is unused + + double prev= 0.0; + uint i; + str->length(0); + bool first= true; + const uchar *p= (uchar*)res->c_ptr(); + for (i= 0; i < res->length(); i++) + { + char numbuf[32]; + double val; + switch (type) + { + case SINGLE_PREC_HB: + val= p[i] / ((double)((1 << 8) - 1)); + break; + case DOUBLE_PREC_HB: + val= ((uint16 *)(p + i))[0] / ((double)((1 << 16) - 1)); + i++; + break; + default: + val= 0; + DBUG_ASSERT(0); + } + /* show delta with previous value */ + int size= my_snprintf(numbuf, sizeof(numbuf), + representation_by_type[type], val - prev); + if (first) + first= false; + else + str->append(","); + str->append(numbuf, size); + prev= val; + } + + null_value=0; + return str; +} + + +/////////////////////////////////////////////////////////////////////////////// /** Concatenate args with the following premises: diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index 89d7fa67f6b..169da25e826 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -143,6 +143,22 @@ public: const char *func_name() const { return "concat"; } }; +class Item_func_decode_histogram :public Item_str_func +{ + String tmp_value; +public: + Item_func_decode_histogram(Item *a, Item *b) + :Item_str_func(a, b) {} + String *val_str(String *); + void fix_length_and_dec() + { + collation.set(system_charset_info); + max_length= MAX_BLOB_WIDTH; + set_persist_maybe_null(1); + } + const char *func_name() const { return "decode_histogram"; } +}; + class Item_func_concat_ws :public Item_str_func { String tmp_value; diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index 24009cb5a99..e51fd1cc11c 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -3970,8 +3970,7 @@ static Sys_var_ulong Sys_histogram_size( SESSION_VAR(histogram_size), CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 255), DEFAULT(0), BLOCK_SIZE(1)); -const char *histogram_types[] = - {"SINGLE_PREC_HB", "DOUBLE_PREC_HB", 0}; +extern const char *histogram_types[]; static Sys_var_enum Sys_histogram_type( "histogram_type", "Specifies type of the histograms created by ANALYZE. " |