diff options
Diffstat (limited to 'sql/item.h')
-rw-r--r-- | sql/item.h | 143 |
1 files changed, 124 insertions, 19 deletions
diff --git a/sql/item.h b/sql/item.h index 2c4943bea6e..429a1d33041 100644 --- a/sql/item.h +++ b/sql/item.h @@ -357,6 +357,35 @@ public: } }; + +/* + This enum is used to report information about monotonicity of function + represented by Item* tree. + Monotonicity is defined only for Item* trees that represent table + partitioning expressions (i.e. have no subselects/user vars/PS parameters + etc etc). An Item* tree is assumed to have the same monotonicity properties + as its correspoinding function F: + + [signed] longlong F(field1, field2, ...) { + put values of field_i into table record buffer; + return item->val_int(); + } + + NOTE + At the moment function monotonicity is not well defined (and so may be + incorrect) for Item trees with parameters/return types that are different + from INT_RESULT, may be NULL, or are unsigned. + It will be possible to address this issue once the related partitioning bugs + (BUG#16002, BUG#15447, BUG#13436) are fixed. +*/ + +typedef enum monotonicity_info +{ + NON_MONOTONIC, /* none of the below holds */ + MONOTONIC_INCREASING, /* F() is unary and (x < y) => (F(x) <= F(y)) */ + MONOTONIC_STRICT_INCREASING /* F() is unary and (x < y) => (F(x) < F(y)) */ +} enum_monotonicity_info; + /*************************************************************************/ class sp_rcontext; @@ -432,6 +461,7 @@ public: FIELD_VARIANCE_ITEM, INSERT_VALUE_ITEM, SUBSELECT_ITEM, ROW_ITEM, CACHE_ITEM, TYPE_HOLDER, PARAM_ITEM, TRIGGER_FIELD_ITEM, DECIMAL_ITEM, + XPATH_NODESET, XPATH_NODESET_CMP, VIEW_FIXER_ITEM}; enum cond_result { COND_UNDEF,COND_OK,COND_TRUE,COND_FALSE }; @@ -506,8 +536,18 @@ public: virtual bool eq(const Item *, bool binary_cmp) const; virtual Item_result result_type() const { return REAL_RESULT; } virtual Item_result cast_to_int_type() const { return result_type(); } + virtual enum_field_types string_field_type() const; virtual enum_field_types field_type() const; virtual enum Type type() const =0; + + /* + Return information about function monotonicity. See comment for + enum_monotonicity_info for details. This function can only be called + after fix_fields() call. + */ + virtual enum_monotonicity_info get_monotonicity_info() const + { return NON_MONOTONIC; } + /* valXXX methods must return NULL or 0 or 0.0 if null_value is set. */ /* Return double precision floating point representation of item. @@ -598,6 +638,7 @@ public: TRUE value is true (not equal to 0) */ virtual bool val_bool(); + virtual String *val_nodeset(String*) { return 0; } /* Helper functions, see item_sum.cc */ String *val_string_from_real(String *str); String *val_string_from_int(String *str); @@ -738,7 +779,7 @@ public: static CHARSET_INFO *default_charset(); virtual CHARSET_INFO *compare_collation() { return NULL; } - virtual bool walk(Item_processor processor, byte *arg) + virtual bool walk(Item_processor processor, bool walk_subquery, byte *arg) { return (this->*processor)(arg); } @@ -783,6 +824,60 @@ public: virtual bool change_context_processor(byte *context) { return 0; } virtual bool reset_query_id_processor(byte *query_id_arg) { return 0; } virtual bool is_expensive_processor(byte *arg) { return 0; } + virtual bool register_field_in_read_map(byte *arg) { return 0; } + /* + Check if a partition function is allowed + SYNOPSIS + check_partition_func_processor() + int_arg Ignored + RETURN VALUE + TRUE Partition function not accepted + FALSE Partition function accepted + + DESCRIPTION + check_partition_func_processor is used to check if a partition function + uses an allowed function. An allowed function will always ensure that + X=Y guarantees that also part_function(X)=part_function(Y) where X is + a set of partition fields and so is Y. The problems comes mainly from + character sets where two equal strings can be quite unequal. E.g. the + german character for double s is equal to 2 s. + + The default is that an item is not allowed + in a partition function. However all mathematical functions, string + manipulation functions, date functions are allowed. Allowed functions + can never depend on server version, they cannot depend on anything + related to the environment. They can also only depend on a set of + fields in the table itself. They cannot depend on other tables and + cannot contain any queries and cannot contain udf's or similar. + If a new Item class is defined and it inherits from a class that is + allowed in a partition function then it is very important to consider + whether this should be inherited to the new class. If not the function + below should be defined in the new Item class. + + The general behaviour is that most integer functions are allowed. + If the partition function contains any multi-byte collations then + the function check_part_func_fields will report an error on the + partition function independent of what functions are used. So the + only character sets allowed are single character collation and + even for those only a limited set of functions are allowed. The + problem with multi-byte collations is that almost every string + function has the ability to change things such that two strings + that are equal will not be equal after manipulated by a string + function. E.g. two strings one contains a double s, there is a + special german character that is equal to two s. Now assume a + string function removes one character at this place, then in + one the double s will be removed and in the other there will + still be one s remaining and the strings are no longer equal + and thus the partition function will not sort equal strings into + the same partitions. + + So the check if a partition function is valid is two steps. First + check that the field types are valid, next check that the partition + function is valid. The current set of partition functions valid + assumes that there are no multi-byte collations amongst the partition + fields. + */ + virtual bool check_partition_func_processor(byte *bool_arg) { return TRUE;} virtual bool subst_argument_checker(byte **arg) { if (*arg) @@ -817,7 +912,7 @@ public: // used in row subselects to get value of elements virtual void bring_value() {} - Field *tmp_table_field_from_field_type(TABLE *table); + Field *tmp_table_field_from_field_type(TABLE *table, bool fixed_length); virtual Item_field *filed_for_view_update() { return 0; } virtual Item *neg_transformer(THD *thd) { return NULL; } @@ -1020,7 +1115,7 @@ inline Item_result Item_splocal::result_type() const class Item_case_expr :public Item_sp_variable { public: - Item_case_expr(int case_expr_id); + Item_case_expr(uint case_expr_id); public: Item *this_item(); @@ -1039,7 +1134,7 @@ public: void print(String *str); private: - int m_case_expr_id; + uint m_case_expr_id; }; /***************************************************************************** @@ -1127,6 +1222,7 @@ public: Item_num() {} /* Remove gcc warning */ virtual Item_num *neg()= 0; Item *safe_charset_converter(CHARSET_INFO *tocs); + bool check_partition_func_processor(byte *int_arg) { return FALSE;} }; #define NO_CACHED_FIELD_INDEX ((uint)(-1)) @@ -1270,6 +1366,10 @@ public: { return field->type(); } + enum_monotonicity_info get_monotonicity_info() const + { + return MONOTONIC_STRICT_INCREASING; + } Field *get_tmp_table_field() { return result_field; } Field *tmp_table_field(TABLE *t_arg) { return result_field; } bool get_date(TIME *ltime,uint fuzzydate); @@ -1280,13 +1380,8 @@ public: Item *get_tmp_table_item(THD *thd); bool collect_item_field_processor(byte * arg); bool find_item_in_field_list_processor(byte *arg); - bool reset_query_id_processor(byte *arg) - { - field->query_id= *((query_id_t *) arg); - if (result_field) - result_field->query_id= field->query_id; - return 0; - } + bool register_field_in_read_map(byte *arg); + bool check_partition_func_processor(byte *int_arg) {return FALSE;} void cleanup(); bool result_as_longlong() { @@ -1337,6 +1432,7 @@ public: bool is_null() { return 1; } void print(String *str) { str->append(STRING_WITH_LEN("NULL")); } Item *safe_charset_converter(CHARSET_INFO *tocs); + bool check_partition_func_processor(byte *int_arg) {return FALSE;} }; class Item_null_result :public Item_null @@ -1349,6 +1445,7 @@ public: { save_in_field(result_field, no_conversions); } + bool check_partition_func_processor(byte *int_arg) {return TRUE;} }; /* Item represents one placeholder ('?') of prepared statement */ @@ -1642,6 +1739,7 @@ public: {} void print(String *str) { str->append(func_name); } Item *safe_charset_converter(CHARSET_INFO *tocs); + bool check_partition_func_processor(byte *int_arg) {return TRUE;} }; @@ -1723,6 +1821,7 @@ public: void print(String *str); // to prevent drop fixed flag (no need parent cleanup call) void cleanup() {} + bool check_partition_func_processor(byte *int_arg) {return FALSE;} }; @@ -1737,6 +1836,7 @@ public: {} Item *safe_charset_converter(CHARSET_INFO *tocs); void print(String *str) { str->append(func_name); } + bool check_partition_func_processor(byte *int_arg) {return TRUE;} }; @@ -1749,6 +1849,7 @@ public: &my_charset_bin) { max_length=19;} enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; } + bool check_partition_func_processor(byte *int_arg) {return TRUE;} }; class Item_empty_string :public Item_string @@ -1771,6 +1872,7 @@ public: unsigned_flag=1; } enum_field_types field_type() const { return int_field_type; } + bool check_partition_func_processor(byte *int_arg) {return TRUE;} }; @@ -1797,6 +1899,7 @@ public: void cleanup() {} bool eq(const Item *item, bool binary_cmp) const; virtual Item *safe_charset_converter(CHARSET_INFO *tocs); + bool check_partition_func_processor(byte *int_arg) {return FALSE;} }; @@ -1916,8 +2019,8 @@ public: { return ref ? (*ref)->real_item() : this; } - bool walk(Item_processor processor, byte *arg) - { return (*ref)->walk(processor, arg); } + bool walk(Item_processor processor, bool walk_subquery, byte *arg) + { return (*ref)->walk(processor, walk_subquery, arg); } void print(String *str); bool result_as_longlong() { @@ -2076,9 +2179,10 @@ public: } Item *clone_item(); virtual Item *real_item() { return ref; } + bool check_partition_func_processor(byte *int_arg) {return TRUE;} }; - +#ifdef MYSQL_SERVER #include "gstream.h" #include "spatial.h" #include "item_sum.h" @@ -2088,8 +2192,9 @@ public: #include "item_strfunc.h" #include "item_geofunc.h" #include "item_timefunc.h" -#include "item_uniq.h" #include "item_subselect.h" +#include "item_xmlfunc.h" +#endif class Item_copy_string :public Item { @@ -2215,9 +2320,9 @@ public: int save_in_field(Field *field_arg, bool no_conversions); table_map used_tables() const { return (table_map)0L; } - bool walk(Item_processor processor, byte *args) + bool walk(Item_processor processor, bool walk_subquery, byte *args) { - return arg->walk(processor, args) || + return arg->walk(processor, walk_subquery, args) || (this->*processor)(args); } @@ -2255,9 +2360,9 @@ public: */ table_map used_tables() const { return RAND_TABLE_BIT; } - bool walk(Item_processor processor, byte *args) + bool walk(Item_processor processor, bool walk_subquery, byte *args) { - return arg->walk(processor, args) || + return arg->walk(processor, walk_subquery, args) || (this->*processor)(args); } }; |