diff options
Diffstat (limited to 'sql/item.h')
-rw-r--r-- | sql/item.h | 458 |
1 files changed, 215 insertions, 243 deletions
diff --git a/sql/item.h b/sql/item.h index 990ca0ec887..5eab1d049f0 100644 --- a/sql/item.h +++ b/sql/item.h @@ -624,6 +624,13 @@ class st_select_lex_unit; class Item_func_not; class Item_splocal; +/* Item::common_flags */ +/* Indicates that name of this Item autogenerated or set by user */ +#define IS_AUTO_GENERATED_NAME 1 +/* Indicates that this item is in CYCLE clause of WITH */ +#define IS_IN_WITH_CYCLE 2 + + /** String_copier that sends Item specific warnings. */ @@ -784,10 +791,11 @@ protected: /** Create a field based on the exact data type handler. */ - Field *create_table_field_from_handler(TABLE *table) + Field *create_table_field_from_handler(MEM_ROOT *root, TABLE *table) { const Type_handler *h= type_handler(); - return h->make_and_init_table_field(&name, Record_addr(maybe_null), + return h->make_and_init_table_field(root, &name, + Record_addr(maybe_null), *this, table); } /** @@ -800,11 +808,12 @@ protected: @retval NULL error @retval !NULL on success */ - Field *tmp_table_field_from_field_type(TABLE *table) + Field *tmp_table_field_from_field_type(MEM_ROOT *root, TABLE *table) { DBUG_ASSERT(is_fixed()); const Type_handler *h= type_handler()->type_handler_for_tmp_table(this); - return h->make_and_init_table_field(&name, Record_addr(maybe_null), + return h->make_and_init_table_field(root, &name, + Record_addr(maybe_null), *this, table); } /** @@ -816,17 +825,20 @@ protected: - does not need to set Field::is_created_from_null_item for the result See create_tmp_field_ex() for details on parameters and return values. */ - Field *create_tmp_field_ex_simple(TABLE *table, + Field *create_tmp_field_ex_simple(MEM_ROOT *root, + TABLE *table, Tmp_field_src *src, const Tmp_field_param *param) { DBUG_ASSERT(!param->make_copy_field()); DBUG_ASSERT(!is_result_field()); DBUG_ASSERT(type() != NULL_ITEM); - return tmp_table_field_from_field_type(table); + return tmp_table_field_from_field_type(root, table); } - Field *create_tmp_field_int(TABLE *table, uint convert_int_length); - Field *tmp_table_field_from_field_type_maybe_null(TABLE *table, + Field *create_tmp_field_int(MEM_ROOT *root, TABLE *table, + uint convert_int_length); + Field *tmp_table_field_from_field_type_maybe_null(MEM_ROOT *root, + TABLE *table, Tmp_field_src *src, const Tmp_field_param *param, bool is_explicit_null); @@ -926,8 +938,9 @@ public: True if any item except Item_sum contains a field. Set during parsing. */ bool with_field; - bool is_autogenerated_name; /* indicate was name of this Item - autogenerated or set by user */ + uint8 common_flags; + bool is_autogenerated_name() + { return (common_flags & IS_AUTO_GENERATED_NAME); } // alloc & destruct is done as start of select on THD::mem_root Item(THD *thd); /* @@ -947,6 +960,11 @@ public: #endif } /*lint -e1509 */ void set_name(THD *thd, const char *str, size_t length, CHARSET_INFO *cs); + void set_name(THD *thd, const LEX_CSTRING &str, + CHARSET_INFO *cs= system_charset_info) + { + set_name(thd, str.str, str.length, cs); + } void set_name_no_truncate(THD *thd, const char *str, uint length, CHARSET_INFO *cs); void init_make_send_field(Send_field *tmp_field, const Type_handler *h); @@ -1110,9 +1128,9 @@ public: { return type_handler()->max_display_length(this); } - TYPELIB *get_typelib() const { return NULL; } + const TYPELIB *get_typelib() const { return NULL; } void set_maybe_null(bool maybe_null_arg) { maybe_null= maybe_null_arg; } - void set_typelib(TYPELIB *typelib) + void set_typelib(const TYPELIB *typelib) { // Non-field Items (e.g. hybrid functions) never have ENUM/SET types yet. DBUG_ASSERT(0); @@ -1459,7 +1477,6 @@ public: { return type_handler()->Item_val_bool(this); } - virtual String *val_raw(String*) { return 0; } bool eval_const_cond() { @@ -1527,8 +1544,7 @@ public: int save_str_value_in_field(Field *field, String *result); virtual Field *get_tmp_table_field() { return 0; } - virtual Field *create_field_for_create_select(TABLE *table); - virtual Field *create_field_for_schema(THD *thd, TABLE *table); + virtual Field *create_field_for_create_select(MEM_ROOT *root, TABLE *table); virtual const char *full_name() const { return name.str ? name.str : "???"; } const char *field_name_or_null() { return real_item()->type() == Item::FIELD_ITEM ? name.str : NULL; } @@ -1807,6 +1823,15 @@ public: virtual bool need_parentheses_in_default() { return false; } virtual void save_in_result_field(bool no_conversions) {} /* + Data type format implied by the CHECK CONSTRAINT, + to be sent to the client in the result set metadata. + */ + virtual bool set_format_by_check_constraint(Send_field_extended_metadata *) + const + { + return false; + } + /* set value of aggregate function in case of no rows for grouping were found */ virtual void no_rows_in_result() {} @@ -2031,6 +2056,44 @@ public: virtual bool check_index_dependence(void *arg) { return 0; } /*============== End of Item processor list ======================*/ + /* + Given a condition P from the WHERE clause or from an ON expression of + the processed SELECT S and a set of join tables from S marked in the + parameter 'allowed'={T} a call of P->find_not_null_fields({T}) has to + find the set fields {F} of the tables from 'allowed' such that: + - each field from {F} is declared as nullable + - each record of table t from {T} that contains NULL as the value for at + at least one field from {F} can be ignored when building the result set + for S + It is assumed here that the condition P is conjunctive and all its column + references belong to T. + + Examples: + CREATE TABLE t1 (a int, b int); + CREATE TABLE t2 (a int, b int); + + SELECT * FROM t1,t2 WHERE t1.a=t2.a and t1.b > 5; + A call of find_not_null_fields() for the whole WHERE condition and {t1,t2} + should find {t1.a,t1.b,t2.a} + + SELECT * FROM t1 LEFT JOIN ON (t1.a=t2.a and t2.a > t2.b); + A call of find_not_null_fields() for the ON expression and {t2} + should find {t2.a,t2.b} + + The function returns TRUE if it succeeds to prove that all records of + a table from {T} can be ignored. Otherwise it always returns FALSE. + + Example: + SELECT * FROM t1,t2 WHERE t1.a=t2.a AND t2.a IS NULL; + A call of find_not_null_fields() for the WHERE condition and {t1,t2} + will return TRUE. + + It is assumed that the implementation of this virtual function saves + the info on the found set of fields in the structures associates with + tables from {T}. + */ + virtual bool find_not_null_fields(table_map allowed) { return false; } + virtual Item *get_copy(THD *thd)=0; bool cache_const_expr_analyzer(uchar **arg); @@ -2095,7 +2158,8 @@ public: const Type_handler *type_handler_long_or_longlong() const { - return Type_handler::type_handler_long_or_longlong(max_char_length()); + return Type_handler::type_handler_long_or_longlong(max_char_length(), + unsigned_flag); } /** @@ -2106,7 +2170,8 @@ public: @retval NULL (on error) @retval a pointer to a newly create Field (on success) */ - virtual Field *create_tmp_field_ex(TABLE *table, + virtual Field *create_tmp_field_ex(MEM_ROOT *root, + TABLE *table, Tmp_field_src *src, const Tmp_field_param *param)= 0; virtual Item_field *field_for_view_update() { return 0; } @@ -2232,14 +2297,6 @@ public: is_expensive_cache= walk(&Item::is_expensive_processor, 0, NULL); return MY_TEST(is_expensive_cache); } - virtual Field::geometry_type get_geometry_type() const - { return Field::GEOM_GEOMETRY; }; - uint uint_geometry_type() const - { return get_geometry_type(); } - void set_geometry_type(uint type) - { - DBUG_ASSERT(0); - } String *check_well_formed_result(String *str, bool send_error= 0); bool eq_by_collation(Item *item, bool binary_cmp, CHARSET_INFO *cs); bool too_big_for_varchar() const @@ -2450,56 +2507,6 @@ public: }; -class Type_geometry_attributes -{ - uint m_geometry_type; - static const uint m_geometry_type_unknown= Field::GEOM_GEOMETRYCOLLECTION + 1; - void copy(const Type_handler *handler, const Type_all_attributes *gattr) - { - // Ignore implicit NULLs - m_geometry_type= handler == &type_handler_geometry ? - gattr->uint_geometry_type() : - m_geometry_type_unknown; - } -public: - Type_geometry_attributes() - :m_geometry_type(m_geometry_type_unknown) - { } - Type_geometry_attributes(const Type_handler *handler, - const Type_all_attributes *gattr) - :m_geometry_type(m_geometry_type_unknown) - { - copy(handler, gattr); - } - void join(const Item *item) - { - // Ignore implicit NULLs - if (m_geometry_type == m_geometry_type_unknown) - copy(item->type_handler(), item); - else if (item->type_handler() == &type_handler_geometry) - { - m_geometry_type= - Field_geom::geometry_type_merge((Field_geom::geometry_type) - m_geometry_type, - (Field_geom::geometry_type) - item->uint_geometry_type()); - } - } - Field::geometry_type get_geometry_type() const - { - return m_geometry_type == m_geometry_type_unknown ? - Field::GEOM_GEOMETRY : - (Field::geometry_type) m_geometry_type; - } - void set_geometry_type(uint type) - { - DBUG_ASSERT(type <= m_geometry_type_unknown); - m_geometry_type= type; - } -}; - - - /** Compare two Items for List<Item>::add_unique() */ @@ -2739,7 +2746,8 @@ protected: } Item_basic_value(THD *thd): Item(thd) {} public: - Field *create_tmp_field_ex(TABLE *table, Tmp_field_src *src, + Field *create_tmp_field_ex(MEM_ROOT *root, + TABLE *table, Tmp_field_src *src, const Tmp_field_param *param) { @@ -2751,7 +2759,8 @@ public: DECLARE c CURSOR FOR SELECT 'test'; OPEN c; */ - return tmp_table_field_from_field_type_maybe_null(table, src, param, + return tmp_table_field_from_field_type_maybe_null(root, + table, src, param, type() == Item::NULL_ITEM); } bool eq(const Item *item, bool binary_cmp) const; @@ -2823,10 +2832,11 @@ public: inline bool const_item() const; - Field *create_tmp_field_ex(TABLE *table, Tmp_field_src *src, + Field *create_tmp_field_ex(MEM_ROOT *root, + TABLE *table, Tmp_field_src *src, const Tmp_field_param *param) { - return create_tmp_field_ex_simple(table, src, param); + return create_tmp_field_ex_simple(root, table, src, param); } inline int save_in_field(Field *field, bool no_conversions); inline bool send(Protocol *protocol, st_value *buffer); @@ -2929,8 +2939,8 @@ public: The inherited implementation would create a column based on result_type(), which is less exact. */ - Field *create_field_for_create_select(TABLE *table) - { return create_table_field_from_handler(table); } + Field *create_field_for_create_select(MEM_ROOT *root, TABLE *table) + { return create_table_field_from_handler(root, table); } bool is_valid_limit_clause_variable_with_error() const { @@ -3119,7 +3129,8 @@ public: return TRUE; } - Field *create_tmp_field_ex(TABLE *table, Tmp_field_src *src, + Field *create_tmp_field_ex(MEM_ROOT *root, + TABLE *table, Tmp_field_src *src, const Tmp_field_param *param) { /* @@ -3127,7 +3138,7 @@ public: DECLARE c CURSOR FOR SELECT NAME_CONST('x','y') FROM t1; OPEN c; */ - return tmp_table_field_from_field_type_maybe_null(table, src, param, + return tmp_table_field_from_field_type_maybe_null(root, table, src, param, type() == Item::NULL_ITEM); } int save_in_field(Field *field, bool no_conversions) @@ -3163,7 +3174,7 @@ public: class Item_num: public Item_literal { public: - Item_num(THD *thd): Item_literal(thd) { collation.set_numeric(); } + Item_num(THD *thd): Item_literal(thd) { collation= DTCollation_numeric(); } Item *safe_charset_converter(THD *thd, CHARSET_INFO *tocs); bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { @@ -3178,6 +3189,11 @@ class st_select_lex; class Item_result_field :public Item_fixed_hybrid /* Item with result field */ { +protected: + Field *create_tmp_field_ex_from_handler(MEM_ROOT *root, TABLE *table, + Tmp_field_src *src, + const Tmp_field_param *param, + const Type_handler *h); public: Field *result_field; /* Save result here */ Item_result_field(THD *thd): Item_fixed_hybrid(thd), result_field(0) {} @@ -3187,8 +3203,13 @@ public: {} ~Item_result_field() {} /* Required with gcc 2.95 */ Field *get_tmp_table_field() { return result_field; } - Field *create_tmp_field_ex(TABLE *table, Tmp_field_src *src, - const Tmp_field_param *param); + Field *create_tmp_field_ex(MEM_ROOT *root, TABLE *table, Tmp_field_src *src, + const Tmp_field_param *param) + { + DBUG_ASSERT(fixed); + const Type_handler *h= type_handler()->type_handler_for_tmp_table(this); + return create_tmp_field_ex_from_handler(root, table, src, param, h); + } void get_tmp_field_src(Tmp_field_src *src, const Tmp_field_param *param); /* This implementation of used_tables() used by Item_avg_field and @@ -3215,14 +3236,14 @@ protected: updated during fix_fields() to values from Field object and life-time of those is shorter than life-time of Item_field. */ - const char *orig_db_name; - const char *orig_table_name; + LEX_CSTRING orig_db_name; + LEX_CSTRING orig_table_name; LEX_CSTRING orig_field_name; public: Name_resolution_context *context; - const char *db_name; - const char *table_name; + LEX_CSTRING db_name; + LEX_CSTRING table_name; LEX_CSTRING field_name; bool alias_name_used; /* true if item was resolved against alias */ /* @@ -3252,10 +3273,10 @@ public: */ bool can_be_depended; Item_ident(THD *thd, Name_resolution_context *context_arg, - const char *db_name_arg, const char *table_name_arg, - const LEX_CSTRING *field_name_arg); + const LEX_CSTRING &db_name_arg, const LEX_CSTRING &table_name_arg, + const LEX_CSTRING &field_name_arg); Item_ident(THD *thd, Item_ident *item); - Item_ident(THD *thd, TABLE_LIST *view_arg, const LEX_CSTRING *field_name_arg); + Item_ident(THD *thd, TABLE_LIST *view_arg, const LEX_CSTRING &field_name_arg); const char *full_name() const; void cleanup(); st_select_lex *get_depended_from() const; @@ -3286,12 +3307,19 @@ public: if any_privileges set to TRUE then here real effective privileges will be stored */ - uint have_privileges; + privilege_t have_privileges; /* field need any privileges (for VIEW creation) */ bool any_privileges; Item_field(THD *thd, Name_resolution_context *context_arg, - const char *db_arg,const char *table_name_arg, - const LEX_CSTRING *field_name_arg); + const LEX_CSTRING &db_arg, const LEX_CSTRING &table_name_arg, + const LEX_CSTRING &field_name_arg); + Item_field(THD *thd, Name_resolution_context *context_arg, + const LEX_CSTRING &field_name_arg) + :Item_field(thd, context_arg, null_clex_str, null_clex_str, field_name_arg) + { } + Item_field(THD *thd, Name_resolution_context *context_arg) + :Item_field(thd, context_arg, null_clex_str, null_clex_str, null_clex_str) + { } /* Constructor needed to process subselect with temporary tables (see Item) */ @@ -3368,12 +3396,13 @@ public: return &type_handler_null; return field->type_handler(); } - Field *create_tmp_field_from_item_field(TABLE *new_table, + Field *create_tmp_field_from_item_field(MEM_ROOT *root, TABLE *new_table, Item_ref *orig_item, const Tmp_field_param *param); - Field *create_tmp_field_ex(TABLE *table, Tmp_field_src *src, + Field *create_tmp_field_ex(MEM_ROOT *root, + TABLE *table, Tmp_field_src *src, const Tmp_field_param *param); - TYPELIB *get_typelib() const { return field->get_typelib(); } + const TYPELIB *get_typelib() const { return field->get_typelib(); } enum_monotonicity_info get_monotonicity_info() const { return MONOTONIC_STRICT_INCREASING; @@ -3425,6 +3454,7 @@ public: bool is_result_field() { return false; } void save_in_result_field(bool no_conversions); Item *get_tmp_table_item(THD *thd); + bool find_not_null_fields(table_map allowed); bool collect_item_field_processor(void * arg); bool add_field_to_set_processor(void * arg); bool find_item_in_field_list_processor(void *arg); @@ -3490,11 +3520,6 @@ public: DBUG_ASSERT(fixed); return field->table->pos_in_table_list->outer_join; } - Field::geometry_type get_geometry_type() const - { - DBUG_ASSERT(field_type() == MYSQL_TYPE_GEOMETRY); - return field->get_geometry_type(); - } bool check_index_dependence(void *arg); friend class Item_default_value; friend class Item_insert_value; @@ -3625,7 +3650,7 @@ public: { return result_field->type(); } - Field *create_tmp_field_ex(TABLE *table, Tmp_field_src *src, + Field *create_tmp_field_ex(MEM_ROOT *root, TABLE *table, Tmp_field_src *src, const Tmp_field_param *param) { DBUG_ASSERT(0); @@ -3672,8 +3697,7 @@ public: class Item_param :public Item_basic_value, private Settable_routine_parameter, public Rewritable_query_parameter, - private Type_handler_hybrid_field_type, - public Type_geometry_attributes + private Type_handler_hybrid_field_type { /* NO_VALUE is a special value meaning that the parameter has not been @@ -3832,12 +3856,6 @@ public: const Type_handler *type_handler() const { return Type_handler_hybrid_field_type::type_handler(); } - Field::geometry_type get_geometry_type() const - { return Type_geometry_attributes::get_geometry_type(); }; - - void set_geometry_type(uint type) - { Type_geometry_attributes::set_geometry_type(type); } - Item_param(THD *thd, const LEX_CSTRING *name_arg, uint pos_in_query_arg, uint len_in_query_arg); @@ -3980,7 +3998,7 @@ public: bool set_limit_clause_param(longlong nr) { - value.set_handler(&type_handler_longlong); + value.set_handler(&type_handler_slonglong); set_int(nr, MY_INT64_NUM_DECIMAL_DIGITS); return !unsigned_flag && value.integer < 0; } @@ -4100,8 +4118,8 @@ public: Item_int(THD *thd, const char *str_arg, size_t length=64); const Type_handler *type_handler() const { return type_handler_long_or_longlong(); } - Field *create_field_for_create_select(TABLE *table) - { return tmp_table_field_from_field_type(table); } + Field *create_field_for_create_select(MEM_ROOT *root, TABLE *table) + { return tmp_table_field_from_field_type(root, table); } const longlong *const_ptr_longlong() const { return &value; } longlong val_int() { return value; } longlong val_int_min() const { return value; } @@ -4295,7 +4313,7 @@ protected: const Metadata metadata) { fix_from_value(dv, metadata); - set_name(thd, str_value.ptr(), str_value.length(), str_value.charset()); + set_name(thd, str_value.lex_cstring(), str_value.charset()); } protected: /* Just create an item and do not fill string representation */ @@ -4342,21 +4360,21 @@ public: fix_and_set_name_from_value(thd, dv, Metadata(&str_value, repertoire)); } // Constructors with an externally provided item name - Item_string(THD *thd, const char *name_par, const char *str, size_t length, + Item_string(THD *thd, const LEX_CSTRING &name_par, const LEX_CSTRING &str, CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE) :Item_literal(thd) { - str_value.set_or_copy_aligned(str, length, cs); + str_value.set_or_copy_aligned(str.str, str.length, cs); fix_from_value(dv, Metadata(&str_value)); - set_name(thd, name_par,safe_strlen(name_par), system_charset_info); + set_name(thd, name_par); } - Item_string(THD *thd, const char *name_par, const char *str, size_t length, + Item_string(THD *thd, const LEX_CSTRING &name_par, const LEX_CSTRING &str, CHARSET_INFO *cs, Derivation dv, uint repertoire) :Item_literal(thd) { - str_value.set_or_copy_aligned(str, length, cs); + str_value.set_or_copy_aligned(str.str, str.length, cs); fix_from_value(dv, Metadata(&str_value, repertoire)); - set_name(thd, name_par, safe_strlen(name_par), system_charset_info); + set_name(thd, name_par); } void print_value(String *to) const { @@ -4431,13 +4449,13 @@ public: class Item_string_with_introducer :public Item_string { public: - Item_string_with_introducer(THD *thd, const char *str, uint length, + Item_string_with_introducer(THD *thd, const LEX_CSTRING &str, CHARSET_INFO *cs): - Item_string(thd, str, length, cs) + Item_string(thd, str.str, str.length, cs) { } - Item_string_with_introducer(THD *thd, const char *name_arg, - const char *str, uint length, CHARSET_INFO *tocs): - Item_string(thd, name_arg, str, length, tocs) + Item_string_with_introducer(THD *thd, const LEX_CSTRING &name_arg, + const LEX_CSTRING &str, CHARSET_INFO *tocs): + Item_string(thd, name_arg, str, tocs) { } virtual bool is_cs_specified() const { @@ -4474,14 +4492,14 @@ public: class Item_static_string_func :public Item_string { - const char *func_name; + const LEX_CSTRING func_name; public: - Item_static_string_func(THD *thd, const char *name_par, const char *str, - uint length, CHARSET_INFO *cs, + Item_static_string_func(THD *thd, const LEX_CSTRING &name_par, + const LEX_CSTRING &str, CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE): - Item_string(thd, NullS, str, length, cs, dv), func_name(name_par) + Item_string(thd, LEX_CSTRING({NullS,0}), str, cs, dv), func_name(name_par) {} - Item_static_string_func(THD *thd, const char *name_par, + Item_static_string_func(THD *thd, const LEX_CSTRING &name_par, const String *str, CHARSET_INFO *tocs, uint *conv_errors, Derivation dv, uint repertoire): @@ -4490,7 +4508,7 @@ public: {} Item *safe_charset_converter(THD *thd, CHARSET_INFO *tocs) { - return const_charset_converter(thd, tocs, true, func_name); + return const_charset_converter(thd, tocs, true, func_name.str); } virtual inline void print(String *str, enum_query_type query_type) @@ -4503,7 +4521,7 @@ public: bool check_vcol_func_processor(void *arg) { // VCOL_TIME_FUNC because the value is not constant, but does not // require fix_fields() to be re-run for every statement. - return mark_unsupported_function(func_name, arg, VCOL_TIME_FUNC); + return mark_unsupported_function(func_name.str, arg, VCOL_TIME_FUNC); } }; @@ -4512,53 +4530,16 @@ public: class Item_partition_func_safe_string: public Item_string { public: - Item_partition_func_safe_string(THD *thd, const char *name_arg, uint length, - CHARSET_INFO *cs= NULL): - Item_string(thd, name_arg, length, cs) - {} - bool check_vcol_func_processor(void *arg) - { - return mark_unsupported_function("safe_string", arg, VCOL_IMPOSSIBLE); - } -}; - - -class Item_return_date_time :public Item_partition_func_safe_string -{ - enum_field_types date_time_field_type; -public: - Item_return_date_time(THD *thd, const char *name_arg, uint length_arg, - enum_field_types field_type_arg, uint dec_arg= 0): - Item_partition_func_safe_string(thd, name_arg, length_arg, &my_charset_bin), - date_time_field_type(field_type_arg) - { decimals= dec_arg; } - const Type_handler *type_handler() const - { - return Type_handler::get_handler_by_field_type(date_time_field_type); - } -}; - - -class Item_blob :public Item_partition_func_safe_string -{ -public: - Item_blob(THD *thd, const char *name_arg, uint length): - Item_partition_func_safe_string(thd, name_arg, (uint) safe_strlen(name_arg), - &my_charset_bin) - { max_length= length; } - enum Type type() const { return TYPE_HOLDER; } - const Type_handler *type_handler() const + Item_partition_func_safe_string(THD *thd, const LEX_CSTRING &name_arg, + uint length, CHARSET_INFO *cs): + Item_string(thd, name_arg, LEX_CSTRING({0,0}), cs) { - return Type_handler::blob_type_handler(max_length); + max_length= length; } - const Type_handler *real_type_handler() const + bool check_vcol_func_processor(void *arg) { - // Should not be called, Item_blob is used for SHOW purposes only. - DBUG_ASSERT(0); - return &type_handler_varchar; + return mark_unsupported_function("safe_string", arg, VCOL_IMPOSSIBLE); } - Field *create_field_for_schema(THD *thd, TABLE *table) - { return tmp_table_field_from_field_type(table); } }; @@ -4571,15 +4552,15 @@ public: class Item_empty_string :public Item_partition_func_safe_string { public: - Item_empty_string(THD *thd, const char *header,uint length, - CHARSET_INFO *cs= NULL): - Item_partition_func_safe_string(thd, "", 0, - cs ? cs : &my_charset_utf8_general_ci) - { - name.str= header; - name.length= strlen(name.str); - max_length= length * collation.collation->mbmaxlen; - } + Item_empty_string(THD *thd, const LEX_CSTRING &header, uint length, + CHARSET_INFO *cs= &my_charset_utf8mb3_general_ci) + :Item_partition_func_safe_string(thd, header, length * cs->mbmaxlen, cs) + { } + Item_empty_string(THD *thd, const char *header, uint length, + CHARSET_INFO *cs= &my_charset_utf8mb3_general_ci) + :Item_partition_func_safe_string(thd, LEX_CSTRING({header, strlen(header)}), + length * cs->mbmaxlen, cs) + { } void make_send_field(THD *thd, Send_field *field); }; @@ -4596,7 +4577,9 @@ public: } const Type_handler *type_handler() const { - return Type_handler::get_handler_by_field_type(int_field_type); + const Type_handler *h= + Type_handler::get_handler_by_field_type(int_field_type); + return unsigned_flag ? h->type_handler_unsigned() : h; } }; @@ -4776,14 +4759,14 @@ public: Item_temporal_literal(THD *thd, const MYSQL_TIME *ltime) :Item_literal(thd) { - collation.set(&my_charset_numeric, DERIVATION_NUMERIC, MY_REPERTOIRE_ASCII); + collation= DTCollation_numeric(); decimals= 0; cached_time= *ltime; } Item_temporal_literal(THD *thd, const MYSQL_TIME *ltime, uint dec_arg): Item_literal(thd) { - collation.set(&my_charset_numeric, DERIVATION_NUMERIC, MY_REPERTOIRE_ASCII); + collation= DTCollation_numeric(); decimals= dec_arg; cached_time= *ltime; } @@ -5173,10 +5156,14 @@ public: Item **ref; bool reference_trough_name; Item_ref(THD *thd, Name_resolution_context *context_arg, - const char *db_arg, const char *table_name_arg, - const LEX_CSTRING *field_name_arg): + const LEX_CSTRING &db_arg, const LEX_CSTRING &table_name_arg, + const LEX_CSTRING &field_name_arg): Item_ident(thd, context_arg, db_arg, table_name_arg, field_name_arg), set_properties_only(0), ref(0), reference_trough_name(1) {} + Item_ref(THD *thd, Name_resolution_context *context_arg, + const LEX_CSTRING &field_name_arg) + :Item_ref(thd, context_arg, null_clex_str, null_clex_str, field_name_arg) + { } /* This constructor is used in two scenarios: A) *item = NULL @@ -5192,10 +5179,10 @@ public: with Bar, and if we have a more broader set of problems like this. */ Item_ref(THD *thd, Name_resolution_context *context_arg, Item **item, - const char *table_name_arg, const LEX_CSTRING *field_name_arg, + const LEX_CSTRING &table_name_arg, const LEX_CSTRING &field_name_arg, bool alias_name_used_arg= FALSE); Item_ref(THD *thd, TABLE_LIST *view_arg, Item **item, - const LEX_CSTRING *field_name_arg, bool alias_name_used_arg= FALSE); + const LEX_CSTRING &field_name_arg, bool alias_name_used_arg= FALSE); /* Constructor need to process subselect with temporary tables (see Item) */ Item_ref(THD *thd, Item_ref *item) @@ -5242,7 +5229,7 @@ public: Field *get_tmp_table_field() { return result_field ? result_field : (*ref)->get_tmp_table_field(); } Item *get_tmp_table_item(THD *thd); - Field *create_tmp_field_ex(TABLE *table, Tmp_field_src *src, + Field *create_tmp_field_ex(MEM_ROOT *root, TABLE *table, Tmp_field_src *src, const Tmp_field_param *param); Item* propagate_equal_fields(THD *, const Context &, COND_EQUAL *); table_map used_tables() const; @@ -5271,6 +5258,10 @@ public: { return depended_from ? 0 : (*ref)->not_null_tables(); } + bool find_not_null_fields(table_map allowed) + { + return depended_from ? false : (*ref)->find_not_null_fields(allowed); + } void save_in_result_field(bool no_conversions) { (*ref)->save_in_field(result_field, no_conversions); @@ -5279,7 +5270,7 @@ public: { return ref ? (*ref)->real_item() : this; } - TYPELIB *get_typelib() const + const TYPELIB *get_typelib() const { return ref ? (*ref)->get_typelib() : NULL; } @@ -5412,8 +5403,8 @@ class Item_direct_ref :public Item_ref { public: Item_direct_ref(THD *thd, Name_resolution_context *context_arg, Item **item, - const char *table_name_arg, - const LEX_CSTRING *field_name_arg, + const LEX_CSTRING &table_name_arg, + const LEX_CSTRING &field_name_arg, bool alias_name_used_arg= FALSE): Item_ref(thd, context_arg, item, table_name_arg, field_name_arg, alias_name_used_arg) @@ -5421,7 +5412,7 @@ public: /* Constructor need to process subselect with temporary tables (see Item) */ Item_direct_ref(THD *thd, Item_direct_ref *item) : Item_ref(thd, item) {} Item_direct_ref(THD *thd, TABLE_LIST *view_arg, Item **item, - const LEX_CSTRING *field_name_arg, + const LEX_CSTRING &field_name_arg, bool alias_name_used_arg= FALSE): Item_ref(thd, view_arg, item, field_name_arg, alias_name_used_arg) @@ -5461,7 +5452,7 @@ class Item_direct_ref_to_ident :public Item_direct_ref public: Item_direct_ref_to_ident(THD *thd, Item_ident *item): Item_direct_ref(thd, item->context, (Item**)&item, item->table_name, - &item->field_name, FALSE) + item->field_name, FALSE) { ident= item; ref= (Item**)&ident; @@ -5653,8 +5644,8 @@ class Item_direct_view_ref :public Item_direct_ref public: Item_direct_view_ref(THD *thd, Name_resolution_context *context_arg, Item **item, - const char *table_name_arg, - LEX_CSTRING *field_name_arg, + LEX_CSTRING &table_name_arg, + LEX_CSTRING &field_name_arg, TABLE_LIST *view_arg): Item_direct_ref(thd, context_arg, item, table_name_arg, field_name_arg), item_equal(0), view(view_arg), @@ -5836,7 +5827,7 @@ public: Item_outer_ref(THD *thd, Name_resolution_context *context_arg, Item_field *outer_field_arg): Item_direct_ref(thd, context_arg, 0, outer_field_arg->table_name, - &outer_field_arg->field_name), + outer_field_arg->field_name), outer_ref(outer_field_arg), in_sum_func(0), found_in_select_list(0), found_in_group_by(0) { @@ -5845,7 +5836,7 @@ public: fixed= 0; /* reset flag set in set_properties() */ } Item_outer_ref(THD *thd, Name_resolution_context *context_arg, Item **item, - const char *table_name_arg, LEX_CSTRING *field_name_arg, + const LEX_CSTRING &table_name_arg, LEX_CSTRING &field_name_arg, bool alias_name_used_arg): Item_direct_ref(thd, context_arg, item, table_name_arg, field_name_arg, alias_name_used_arg), @@ -5886,8 +5877,8 @@ protected: public: Item_ref_null_helper(THD *thd, Name_resolution_context *context_arg, Item_in_subselect* master, Item **item, - const char *table_name_arg, - const LEX_CSTRING *field_name_arg): + const LEX_CSTRING &table_name_arg, + const LEX_CSTRING &field_name_arg): Item_ref(thd, context_arg, item, table_name_arg, field_name_arg), owner(master) {} void save_val(Field *to); @@ -5931,14 +5922,11 @@ public: }; #ifdef MYSQL_SERVER -#include "gstream.h" -#include "spatial.h" #include "item_sum.h" #include "item_func.h" #include "item_row.h" #include "item_cmpfunc.h" #include "item_strfunc.h" -#include "item_geofunc.h" #include "item_timefunc.h" #include "item_subselect.h" #include "item_xmlfunc.h" @@ -6015,7 +6003,7 @@ public: const Type_handler *type_handler() const { return Type_handler_hybrid_field_type::type_handler(); } - Field *create_tmp_field_ex(TABLE *table, Tmp_field_src *src, + Field *create_tmp_field_ex(MEM_ROOT *root, TABLE *table, Tmp_field_src *src, const Tmp_field_param *param) { DBUG_ASSERT(0); @@ -6255,16 +6243,13 @@ class Item_default_value : public Item_field public: Item *arg; Item_default_value(THD *thd, Name_resolution_context *context_arg) - :Item_field(thd, context_arg, (const char *)NULL, (const char *)NULL, - &null_clex_str), + :Item_field(thd, context_arg), arg(NULL) {} Item_default_value(THD *thd, Name_resolution_context *context_arg, Item *a) - :Item_field(thd, context_arg, (const char *)NULL, (const char *)NULL, - &null_clex_str), + :Item_field(thd, context_arg), arg(a) {} Item_default_value(THD *thd, Name_resolution_context *context_arg, Field *a) - :Item_field(thd, context_arg, (const char *)NULL, (const char *)NULL, - &null_clex_str), + :Item_field(thd, context_arg), arg(NULL) {} enum Type type() const { return DEFAULT_VALUE_ITEM; } bool eq(const Item *item, bool binary_cmp) const; @@ -6351,8 +6336,7 @@ class Item_insert_value : public Item_field public: Item *arg; Item_insert_value(THD *thd, Name_resolution_context *context_arg, Item *a) - :Item_field(thd, context_arg, (const char *)NULL, (const char *)NULL, - &null_clex_str), + :Item_field(thd, context_arg), arg(a) {} bool eq(const Item *item, bool binary_cmp) const; bool fix_fields(THD *, Item **); @@ -6413,10 +6397,9 @@ public: Item_trigger_field(THD *thd, Name_resolution_context *context_arg, row_version_type row_ver_arg, - const LEX_CSTRING *field_name_arg, - ulong priv, const bool ro) - :Item_field(thd, context_arg, - (const char *)NULL, (const char *)NULL, field_name_arg), + const LEX_CSTRING &field_name_arg, + privilege_t priv, const bool ro) + :Item_field(thd, context_arg, field_name_arg), row_version(row_ver_arg), field_idx((uint)-1), original_privilege(priv), want_privilege(priv), table_grants(NULL), read_only (ro) {} @@ -6457,8 +6440,8 @@ private: want_privilege and cleanup() is responsible for restoring of original want_privilege once parameter's value is updated). */ - ulong original_privilege; - ulong want_privilege; + privilege_t original_privilege; + privilege_t want_privilege; GRANT_INFO *table_grants; /* Trigger field is read-only unless it belongs to the NEW row in a @@ -6538,10 +6521,10 @@ public: const Type_handler *type_handler() const { return Type_handler_hybrid_field_type::type_handler(); } - Field *create_tmp_field_ex(TABLE *table, Tmp_field_src *src, + Field *create_tmp_field_ex(MEM_ROOT *root, TABLE *table, Tmp_field_src *src, const Tmp_field_param *param) { - return create_tmp_field_ex_simple(table, src, param); + return create_tmp_field_ex_simple(root, table, src, param); } virtual void keep_array() {} @@ -6641,8 +6624,6 @@ class Item_cache_int: public Item_cache protected: longlong value; public: - Item_cache_int(THD *thd): Item_cache(thd, &type_handler_longlong), - value(0) {} Item_cache_int(THD *thd, const Type_handler *handler): Item_cache(thd, handler), value(0) {} @@ -7039,11 +7020,10 @@ public: single SP/PS execution. */ class Item_type_holder: public Item, - public Type_handler_hybrid_field_type, - public Type_geometry_attributes + public Type_handler_hybrid_field_type { protected: - TYPELIB *enum_set_typelib; + const TYPELIB *enum_set_typelib; public: Item_type_holder(THD *thd, Item *item) :Item(thd, item), @@ -7060,12 +7040,12 @@ public: bool maybe_null_arg) :Item(thd), Type_handler_hybrid_field_type(handler), - Type_geometry_attributes(handler, attr), enum_set_typelib(attr->get_typelib()) { name= item->name; Type_std_attributes::set(*attr); maybe_null= maybe_null_arg; + common_flags= item->common_flags; } const Type_handler *type_handler() const @@ -7079,27 +7059,19 @@ public: } enum Type type() const { return TYPE_HOLDER; } - TYPELIB *get_typelib() const { return enum_set_typelib; } + const TYPELIB *get_typelib() const { return enum_set_typelib; } double val_real(); longlong val_int(); my_decimal *val_decimal(my_decimal *); String *val_str(String*); bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); - Field *create_tmp_field_ex(TABLE *table, Tmp_field_src *src, + Field *create_tmp_field_ex(MEM_ROOT *root, TABLE *table, Tmp_field_src *src, const Tmp_field_param *param) { return Item_type_holder::real_type_handler()-> - make_and_init_table_field(&name, Record_addr(maybe_null), + make_and_init_table_field(root, &name, Record_addr(maybe_null), *this, table); } - Field::geometry_type get_geometry_type() const - { - return Type_geometry_attributes::get_geometry_type(); - } - void set_geometry_type(uint type) - { - Type_geometry_attributes::set_geometry_type(type); - } Item* get_copy(THD *thd) { return 0; } }; |