diff options
author | Igor Babaev <igor@askmonty.org> | 2012-01-04 17:51:53 -0800 |
---|---|---|
committer | Igor Babaev <igor@askmonty.org> | 2012-01-04 17:51:53 -0800 |
commit | e8497370b9557e77c0a791f89712a6ae8505f925 (patch) | |
tree | e67d66f7fe58cd216be1c18b8a99f39160909026 /sql/field.h | |
parent | cd55894a52b5b2bf4a740eb0f39d91d7a82f673c (diff) | |
download | mariadb-git-e8497370b9557e77c0a791f89712a6ae8505f925.tar.gz |
The main patch for the MWL#248 back-ported from
lp:~igorb-seattle/mysql-server/mysql-azalea-wl4777.
Diffstat (limited to 'sql/field.h')
-rw-r--r-- | sql/field.h | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/sql/field.h b/sql/field.h index 933bbe2c018..04b7baac89a 100644 --- a/sql/field.h +++ b/sql/field.h @@ -33,6 +33,7 @@ class Send_field; class Protocol; class Create_field; class Relay_log_info; +class Count_distinct_field; struct ha_field_option_struct; struct st_cache_field; @@ -183,6 +184,57 @@ public: */ bool is_created_from_null_item; + bool is_stat_field; /* TRUE in Field objects created for column min/max values */ + + /* Statistical data on a column */ + class Column_statistics + { + public: + /* + Bitmap indicating what statistical characteristics + are available for the column + */ + uint32 column_stat_nulls; + + /* Minimum value for the column */ + Field *min_value; + /* Maximum value for the column */ + Field *max_value; + /* + The ratio Z/N, where N is the total number of rows, + Z is the number of nulls in the column + */ + double nulls_ratio; + /* + Average number of bytes occupied by the representation of a + value of the column in memory buffers such as join buffer. + CHAR values are stripped of trailing spaces. + Flexible values are stripped of their length prefixes. + */ + double avg_length; + /* + The ratio N/D, where N is the number of rows with null value + in the column, D the number of distinct values among them + */ + double avg_frequency; + }; + + /* + This structure is used for statistical data on the column + that has been read from the statistical table column_stat + */ + Column_statistics read_stat; + /* + This structure is used for statistical data on the column that + is collected by the function collect_statistics_for_table + */ + Column_statistics write_stat; + + /* These members are used only when collecting statistics on the column */ + ha_rows nulls; + ulonglong column_total_length; + Count_distinct_field *count_distinct; + /* This is additional data provided for any computed(virtual) field. In particular it includes a pointer to the item by which this field @@ -284,6 +336,26 @@ public: virtual uint32 data_length() { return pack_length(); } virtual uint32 sort_length() const { return pack_length(); } + /* + Get the number bytes occupied by the value in the field. + CHAR values are stripped of trailing spaces. + Flexible values are stripped of their length. + */ + virtual uint32 value_length() + { + uint len; + if (!zero_pack() && + (type() == MYSQL_TYPE_STRING && + (len= pack_length()) >= 4 && len < 256)) + { + uchar *str, *end; + for (str= ptr, end= str+len; end > str && end[-1] == ' '; end--); + len=(uint) (end-str); + return len; + } + return data_length(); + } + /** Get the maximum size of the data in packed format. @@ -325,6 +397,36 @@ public: { return cmp(a, b); } virtual int key_cmp(const uchar *str, uint length) { return cmp(ptr,str); } + /* + Update the value m of the 'min_val' field with the current value v + of this field if force_update is set to TRUE or if v < m. + Return TRUE if the value has been updated. + */ + virtual bool update_min(Field *min_val, bool force_update) + { + bool update_fl= force_update || cmp(ptr, min_val->ptr) < 0; + if (update_fl) + { + min_val->set_notnull(); + memcpy(min_val->ptr, ptr, pack_length()); + } + return update_fl; + } + /* + Update the value m of the 'max_val' field with the current value v + of this field if force_update is set to TRUE or if v > m. + Return TRUE if the value has been updated. + */ + virtual bool update_max(Field *max_val, bool force_update) + { + bool update_fl= force_update || cmp(ptr, max_val->ptr) > 0; + if (update_fl) + { + max_val->set_notnull(); + memcpy(max_val->ptr, ptr, pack_length()); + } + return update_fl; + } virtual uint decimals() const { return 0; } /* Caller beware: sql_type can change str.Ptr, so check @@ -396,6 +498,8 @@ public: uchar *new_ptr, uchar *new_null_ptr, uint new_null_bit); Field *clone(MEM_ROOT *mem_root, struct st_table *new_table); + Field *clone(MEM_ROOT *mem_root, TABLE *new_table, my_ptrdiff_t diff, + bool stat_flag= FALSE); inline void move_field(uchar *ptr_arg,uchar *null_ptr_arg,uchar null_bit_arg) { ptr=ptr_arg; null_ptr=null_ptr_arg; null_bit=null_bit_arg; @@ -1785,6 +1889,10 @@ public: int cmp_binary(const uchar *a,const uchar *b, uint32 max_length=~0L); int key_cmp(const uchar *,const uchar*); int key_cmp(const uchar *str, uint length); + /* Never update the value of min_val for a blob field */ + bool update_min(Field *min_val, bool force_update) { return FALSE; } + /* Never update the value of max_val for a blob field */ + bool update_max(Field *max_val, bool force_update) { return FALSE; } uint32 key_length() const { return 0; } void sort_string(uchar *buff,uint length); uint32 pack_length() const @@ -1802,6 +1910,7 @@ public: { return (uint32) (packlength); } uint row_pack_length() { return pack_length_no_ptr(); } uint32 sort_length() const; + uint32 value_length() { return get_length(); } virtual uint32 max_data_length() const { return (uint32) (((ulonglong) 1 << (packlength*8)) -1); @@ -2059,6 +2168,28 @@ public: { return cmp_binary((uchar *) a, (uchar *) b); } int key_cmp(const uchar *str, uint length); int cmp_offset(uint row_offset); + bool update_min(Field *min_val, bool force_update) + { + longlong val= val_int(); + bool update_fl= force_update || val < min_val->val_int(); + if (update_fl) + { + min_val->set_notnull(); + min_val->store(val, FALSE); + } + return update_fl; + } + bool update_max(Field *max_val, bool force_update) + { + longlong val= val_int(); + bool update_fl= force_update || val > max_val->val_int(); + if (update_fl) + { + max_val->set_notnull(); + max_val->store(val, FALSE); + } + return update_fl; + } void get_image(uchar *buff, uint length, CHARSET_INFO *cs) { get_key_image(buff, length, itRAW); } void set_image(const uchar *buff,uint length, CHARSET_INFO *cs) |