diff options
author | Monty <monty@mariadb.org> | 2020-09-02 03:13:32 +0300 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2021-05-19 22:27:28 +0200 |
commit | 6079b46d8d371262882d1bbe7ebeec23b2f83075 (patch) | |
tree | ad649946b27e58e5b451b6bbd470d14d1c161189 /sql | |
parent | 7ca4e381f7af59dad07aebc5dc4f467b235ab962 (diff) | |
download | mariadb-git-6079b46d8d371262882d1bbe7ebeec23b2f83075.tar.gz |
Split item->flags into base_flags and with_flags
This was done to simplify copying of with_* flags
Other things:
- Changed Flags to C++ enums, which enables gdb to print
out bit values for the flags. This also enables compiler
errors if one tries to manipulate a non existing bit in
a variable.
- Added set_maybe_null() as a shortcut as setting the
MAYBE_NULL flags was used in a LOT of places.
- Renamed PARAM flag to SP_VAR to ensure it's not confused with persistent
statement parameters.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/item.cc | 95 | ||||
-rw-r--r-- | sql/item.h | 213 | ||||
-rw-r--r-- | sql/item_cmpfunc.cc | 60 | ||||
-rw-r--r-- | sql/item_cmpfunc.h | 10 | ||||
-rw-r--r-- | sql/item_func.cc | 52 | ||||
-rw-r--r-- | sql/item_func.h | 76 | ||||
-rw-r--r-- | sql/item_geofunc.cc | 6 | ||||
-rw-r--r-- | sql/item_geofunc.h | 58 | ||||
-rw-r--r-- | sql/item_jsonfunc.cc | 38 | ||||
-rw-r--r-- | sql/item_jsonfunc.h | 2 | ||||
-rw-r--r-- | sql/item_row.cc | 12 | ||||
-rw-r--r-- | sql/item_strfunc.cc | 40 | ||||
-rw-r--r-- | sql/item_strfunc.h | 48 | ||||
-rw-r--r-- | sql/item_subselect.cc | 16 | ||||
-rw-r--r-- | sql/item_sum.cc | 50 | ||||
-rw-r--r-- | sql/item_sum.h | 13 | ||||
-rw-r--r-- | sql/item_timefunc.cc | 22 | ||||
-rw-r--r-- | sql/item_timefunc.h | 44 | ||||
-rw-r--r-- | sql/item_vers.h | 2 | ||||
-rw-r--r-- | sql/item_windowfunc.cc | 11 | ||||
-rw-r--r-- | sql/item_xmlfunc.h | 4 | ||||
-rw-r--r-- | sql/opt_subselect.cc | 4 | ||||
-rw-r--r-- | sql/sp_head.cc | 4 | ||||
-rw-r--r-- | sql/sql_admin.cc | 8 | ||||
-rw-r--r-- | sql/sql_analyse.cc | 6 | ||||
-rw-r--r-- | sql/sql_class.cc | 24 | ||||
-rw-r--r-- | sql/sql_cte.cc | 4 | ||||
-rw-r--r-- | sql/sql_select.cc | 15 | ||||
-rw-r--r-- | sql/sql_show.cc | 10 | ||||
-rw-r--r-- | sql/sql_table.cc | 4 | ||||
-rw-r--r-- | sql/sql_type.cc | 13 | ||||
-rw-r--r-- | sql/sql_view.cc | 4 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 4 | ||||
-rw-r--r-- | sql/table.cc | 2 |
34 files changed, 518 insertions, 456 deletions
diff --git a/sql/item.cc b/sql/item.cc index d4e41b0ca21..34957a15aaf 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -413,7 +413,8 @@ Item::Item(THD *thd): name(null_clex_str), orig_name(0), is_expensive_cache(-1) { DBUG_ASSERT(thd); - flags= ITEM_FLAG_FIXED | ITEM_FLAG_IS_AUTOGENERATED_NAME; + base_flags= item_base_t::FIXED | item_base_t::IS_AUTOGENERATED_NAME; + with_flags= item_with_t::NONE; null_value= 0; marker= 0; @@ -445,7 +446,8 @@ Item::Item(): name(null_clex_str), orig_name(0), is_expensive_cache(-1) { DBUG_ASSERT(my_progname == NULL); // before main() - flags= ITEM_FLAG_FIXED | ITEM_FLAG_IS_AUTOGENERATED_NAME; + base_flags= item_base_t::FIXED | item_base_t::IS_AUTOGENERATED_NAME; + with_flags= item_with_t::NONE; null_value= 0; marker= 0; join_tab_idx= MAX_TABLES; @@ -473,13 +475,13 @@ Item::Item(THD *thd, Item *item): str_value(item->str_value), name(item->name), orig_name(item->orig_name), + base_flags(item->base_flags & ~item_base_t::FIXED), + with_flags(item->with_flags), marker(item->marker), null_value(item->null_value), is_expensive_cache(-1), join_tab_idx(item->join_tab_idx) { - flags= item->flags & (item_flags_t) ~ITEM_FLAG_FIXED; - next= thd->free_list; // Put in free list thd->free_list= this; } @@ -1599,9 +1601,10 @@ bool Item_sp_variable::fix_fields_from_item(THD *thd, Item **, const Item *it) max_length= it->max_length; decimals= it->decimals; unsigned_flag= it->unsigned_flag; - flags|= ITEM_FLAG_WITH_PARAM | ITEM_FLAG_FIXED; + base_flags|= item_base_t::FIXED; + with_flags|= item_with_t::SP_VAR; if (thd->lex->current_select && thd->lex->current_select->master_unit()->item) - thd->lex->current_select->master_unit()->item->flags|= ITEM_FLAG_WITH_PARAM; + thd->lex->current_select->master_unit()->item->with_flags|= item_with_t::SP_VAR; collation.set(it->collation.collation, it->collation.derivation); return FALSE; @@ -1723,7 +1726,7 @@ Item_splocal::Item_splocal(THD *thd, m_var_idx(sp_var_idx), m_type(handler == &type_handler_row ? ROW_ITEM : CONST_ITEM) { - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); } @@ -2086,7 +2089,7 @@ Item_name_const::Item_name_const(THD *thd, Item *name_arg, Item *val): StringBuffer<128> name_buffer; String *name_str; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); if (name_item->basic_const_item() && (name_str= name_item->val_str(&name_buffer))) // Can't have a NULL name set_name(thd, name_str); @@ -2140,7 +2143,7 @@ bool Item_name_const::fix_fields(THD *thd, Item **ref) max_length= value_item->max_length; decimals= value_item->decimals; unsigned_flag= value_item->unsigned_flag; - flags|= ITEM_FLAG_FIXED; + base_flags|= item_base_t::FIXED; return FALSE; } @@ -2959,7 +2962,7 @@ Item_field::Item_field(THD *thd, Field *f) */ orig_table_name= table_name; orig_field_name= field_name; - flags|= ITEM_FLAG_WITH_FIELD; + with_flags|= item_with_t::FIELD; } @@ -3009,7 +3012,7 @@ Item_field::Item_field(THD *thd, Name_resolution_context *context_arg, name= orig_field_name; } set_field(f); - flags|= ITEM_FLAG_WITH_FIELD; + with_flags|= item_with_t::FIELD; } @@ -3025,7 +3028,7 @@ Item_field::Item_field(THD *thd, Name_resolution_context *context_arg, collation.set(DERIVATION_IMPLICIT); if (select && select->parsing_place != IN_HAVING) select->select_n_where_fields++; - flags|= ITEM_FLAG_WITH_FIELD; + with_flags|= item_with_t::FIELD; } /** @@ -3040,7 +3043,7 @@ Item_field::Item_field(THD *thd, Item_field *item) any_privileges(item->any_privileges) { collation.set(DERIVATION_IMPLICIT); - flags|= ITEM_FLAG_WITH_FIELD; + with_flags|= item_with_t::FIELD; } @@ -3065,7 +3068,7 @@ void Item_field::set_field(Field *field_par) db_name= field_par->table->s->db; alias_name_used= field_par->table->alias_name_used; - flags|= ITEM_FLAG_FIXED; + base_flags|= item_base_t::FIXED; if (field->table->s->tmp_table == SYSTEM_TMP_TABLE) any_privileges= 0; } @@ -3959,7 +3962,7 @@ Item_param::Item_param(THD *thd, const LEX_CSTRING *name_arg, before mysql_stmt_execute(), so we assuming that it can be NULL until value is set. */ - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); } @@ -3991,7 +3994,7 @@ void Item_param::sync_clones() { Item_param *c= *c_ptr; /* Scalar-type members: */ - c->copy_flags(this, ITEM_FLAG_MAYBE_NULL); + c->copy_flags(this, item_base_t::MAYBE_NULL); c->null_value= null_value; c->Type_std_attributes::operator=(*this); c->Type_handler_hybrid_field_type::operator=(*this); @@ -4043,7 +4046,7 @@ void Item_param::set_int(longlong i, uint32 max_length_arg) collation= DTCollation_numeric(); max_length= max_length_arg; decimals= 0; - flags&= (item_flags_t) ~ITEM_FLAG_MAYBE_NULL; + base_flags&= ~item_base_t::MAYBE_NULL; null_value= 0; DBUG_VOID_RETURN; } @@ -4057,7 +4060,7 @@ void Item_param::set_double(double d) collation= DTCollation_numeric(); max_length= DBL_DIG + 8; decimals= NOT_FIXED_DEC; - flags&= (item_flags_t) ~ITEM_FLAG_MAYBE_NULL; + base_flags&= ~item_base_t::MAYBE_NULL; null_value= 0; DBUG_VOID_RETURN; } @@ -4089,7 +4092,7 @@ void Item_param::set_decimal(const char *str, ulong length) max_length= my_decimal_precision_to_length_no_truncation(value.m_decimal.precision(), decimals, unsigned_flag); - flags&= (item_flags_t) ~ITEM_FLAG_MAYBE_NULL; + base_flags&= ~item_base_t::MAYBE_NULL; null_value= 0; DBUG_VOID_RETURN; } @@ -4106,7 +4109,7 @@ void Item_param::set_decimal(const my_decimal *dv, bool unsigned_arg) unsigned_flag= unsigned_arg; max_length= my_decimal_precision_to_length(value.m_decimal.intg + decimals, decimals, unsigned_flag); - flags&= (item_flags_t) ~ITEM_FLAG_MAYBE_NULL; + base_flags&= ~item_base_t::MAYBE_NULL; null_value= 0; } @@ -4117,7 +4120,7 @@ void Item_param::fix_temporal(uint32 max_length_arg, uint decimals_arg) collation= DTCollation_numeric(); max_length= max_length_arg; decimals= decimals_arg; - flags&= (item_flags_t) ~ITEM_FLAG_MAYBE_NULL; + base_flags&= ~item_base_t::MAYBE_NULL; null_value= 0; } @@ -4127,7 +4130,7 @@ void Item_param::set_time(const MYSQL_TIME *tm, { DBUG_ASSERT(value.type_handler()->cmp_type() == TIME_RESULT); value.time= *tm; - flags&= (item_flags_t) ~ITEM_FLAG_MAYBE_NULL; + base_flags&= ~item_base_t::MAYBE_NULL; null_value= 0; fix_temporal(max_length_arg, decimals_arg); } @@ -4162,7 +4165,7 @@ void Item_param::set_time(MYSQL_TIME *tm, timestamp_type time_type, &str, time_type, NULL, NULL, NULL); set_zero_time(&value.time, time_type); } - flags&= (item_flags_t) ~ITEM_FLAG_MAYBE_NULL; + base_flags&= ~item_base_t::MAYBE_NULL; null_value= 0; fix_temporal(max_length_arg, tm->second_part > 0 ? TIME_SECOND_PART_DIGITS : 0); @@ -4199,7 +4202,7 @@ bool Item_param::set_str(const char *str, ulong length, state= SHORT_DATA_VALUE; collation.set(tocs, DERIVATION_COERCIBLE); max_length= length; - flags&= (item_flags_t) ~ITEM_FLAG_MAYBE_NULL; + base_flags&= ~item_base_t::MAYBE_NULL; null_value= 0; /* max_length and decimals are set after charset conversion */ /* sic: str may be not null-terminated, don't add DBUG_PRINT here */ @@ -4234,7 +4237,7 @@ bool Item_param::set_longdata(const char *str, ulong length) if (value.m_string.append(str, length, &my_charset_bin)) DBUG_RETURN(TRUE); state= LONG_DATA_VALUE; - flags&= (item_flags_t) ~ITEM_FLAG_MAYBE_NULL; + base_flags&= ~item_base_t::MAYBE_NULL; null_value= 0; DBUG_RETURN(FALSE); @@ -4335,7 +4338,7 @@ void Item_param::reset() value.m_string.set_charset(&my_charset_bin); collation.set(&my_charset_bin, DERIVATION_COERCIBLE); state= NO_VALUE; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); null_value= 0; DBUG_VOID_RETURN; } @@ -4794,7 +4797,7 @@ Item_param::set_param_type_and_swap_value(Item_param *src) Type_std_attributes::set(src); set_handler(src->type_handler()); - copy_flags(src, ITEM_FLAG_MAYBE_NULL); + copy_flags(src, item_base_t::MAYBE_NULL); null_value= src->null_value; state= src->state; @@ -5629,7 +5632,7 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference) set_if_bigger(thd->lex->in_sum_func->max_arg_level, select->nest_level); set_field(*from_field); - flags|= ITEM_FLAG_FIXED; + base_flags|= item_base_t::FIXED; mark_as_dependent(thd, last_checked_context->select_lex, context->select_lex, this, ((ref_type == REF_ITEM || @@ -6049,7 +6052,7 @@ bool Item_field::fix_fields(THD *thd, Item **reference) } } #endif - flags|= ITEM_FLAG_FIXED; + base_flags|= item_base_t::FIXED; if (field->vcol_info) fix_session_vcol_expr_for_read(thd, field, field->vcol_info); if (thd->variables.sql_mode & MODE_ONLY_FULL_GROUP_BY && @@ -8072,20 +8075,10 @@ void Item_ref::set_properties() We have to remember if we refer to a sum function, to ensure that split_sum_func() doesn't try to change the reference. */ - /* Reset flags if called from update_ref() */ - flags&= ~ (ITEM_FLAG_WITH_SUM_FUNC | - ITEM_FLAG_WITH_PARAM | - ITEM_FLAG_WITH_WINDOW_FUNC | - ITEM_FLAG_WITH_SUBQUERY | - ITEM_FLAG_WITH_FIELD); - - flags|= (ITEM_FLAG_FIXED | - ((*ref)->flags & (ITEM_FLAG_MAYBE_NULL | - ITEM_FLAG_WITH_SUM_FUNC | - ITEM_FLAG_WITH_PARAM | - ITEM_FLAG_WITH_WINDOW_FUNC | - ITEM_FLAG_WITH_SUBQUERY | - ITEM_FLAG_WITH_FIELD))); + with_flags= (*ref)->with_flags; + base_flags|= (item_base_t::FIXED | + ((*ref)->base_flags & item_base_t::MAYBE_NULL)); + if (alias_name_used) return; if ((*ref)->type() == FIELD_ITEM) @@ -8563,14 +8556,10 @@ Item_cache_wrapper::Item_cache_wrapper(THD *thd, Item *item_arg): DBUG_ASSERT(orig_item->fixed()); Type_std_attributes::set(orig_item); - flags|= ITEM_FLAG_FIXED | - (orig_item->flags & - (ITEM_FLAG_MAYBE_NULL | - ITEM_FLAG_WITH_SUM_FUNC | - ITEM_FLAG_WITH_SUBQUERY | - ITEM_FLAG_WITH_PARAM | - ITEM_FLAG_WITH_FIELD)); - + base_flags|= (item_base_t::FIXED | + (orig_item->base_flags & item_base_t::MAYBE_NULL)); + with_flags|= orig_item->with_flags; + name= item_arg->name; if ((expr_value= orig_item->get_cache(thd))) @@ -9029,7 +9018,7 @@ bool Item_direct_view_ref::fix_fields(THD *thd, Item **reference) if (Item_direct_ref::fix_fields(thd, reference)) return TRUE; if (view->table && view->table->maybe_null) - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); set_null_ref_table(); return FALSE; } @@ -9789,7 +9778,7 @@ bool Item_trigger_field::fix_fields(THD *thd, Item **items) field= (row_version == OLD_ROW) ? triggers->old_field[field_idx] : triggers->new_field[field_idx]; set_field(field); - flags|= ITEM_FLAG_FIXED; + base_flags|= item_base_t::FIXED; return FALSE; } diff --git a/sql/item.h b/sql/item.h index fef5b2d2e04..3c985d1f3bf 100644 --- a/sql/item.h +++ b/sql/item.h @@ -726,28 +726,92 @@ public: #define STOP_PTR ((void *) 1) -/* Bits used in Item.flags */ -/* If item may be null */ -#define ITEM_FLAG_MAYBE_NULL_SHIFT 0 -#define ITEM_FLAG_MAYBE_NULL (1<<ITEM_FLAG_MAYBE_NULL_SHIFT) -/* If used in GROUP BY list of a query with ROLLUP */ -#define ITEM_FLAG_IN_ROLLUP (1<<1) -/* If Item contains an SP parameter */ -#define ITEM_FLAG_WITH_PARAM (1<<2) -/* If item contains a window func */ -#define ITEM_FLAG_WITH_WINDOW_FUNC (1<<3) -/* True if any item except Item_sum contains a field. Set during parsing. */ -#define ITEM_FLAG_WITH_FIELD (1<<4) -/* If item was fixed with fix_fields */ -#define ITEM_FLAG_FIXED (1<<5) -/* Indicates that name of this Item autogenerated or set by user */ -#define ITEM_FLAG_IS_AUTOGENERATED_NAME (1 << 6) -/* Indicates that this item is in CYCLE clause of WITH */ -#define ITEM_FLAG_IS_IN_WITH_CYCLE (1<<7) -/* True if item contains a sum func */ -#define ITEM_FLAG_WITH_SUM_FUNC (1<< 8) -/* True if item containts a sub query */ -#define ITEM_FLAG_WITH_SUBQUERY (1<< 9) +/* Base flags (including IN) for an item */ + +typedef uint8 item_flags_t; + +enum class item_base_t : item_flags_t +{ + NONE= 0, +#define ITEM_FLAGS_MAYBE_NULL_SHIFT 0 // Must match MAYBE_NULL + MAYBE_NULL= (1<<0), // May be NULL. + IN_ROLLUP= (1<<1), // Appears in GROUP BY list + // of a query with ROLLUP. + FIXED= (1<<2), // Was fixed with fix_fields(). + IS_AUTOGENERATED_NAME= (1<<3), // The name if this Item was + // generated or set by the user. + IS_IN_WITH_CYCLE= (1<<4) // This item is in CYCLE clause + // of WITH. +}; + + +/* Flags that tells us what kind of items the item contains */ + +enum class item_with_t : item_flags_t +{ + NONE= 0, + SP_VAR= (1<<0), // If Item contains a stored procedure variable + WINDOW_FUNC= (1<<1), // If item contains a window func + FIELD= (1<<2), // If any item except Item_sum contains a field. + SUM_FUNC= (1<<3), // If item contains a sum func + SUBQUERY= (1<<4) // If item containts a sub query +}; + + +/* Make operations in item_base_t and item_with_t work like 'int' */ +static inline item_base_t operator&(const item_base_t a, const item_base_t b) +{ + return (item_base_t) (((item_flags_t) a) & ((item_flags_t) b)); +} + +static inline item_base_t & operator&=(item_base_t &a, item_base_t b) +{ + a= (item_base_t) (((item_flags_t) a) & (item_flags_t) b); + return a; +} + +static inline item_base_t operator|(const item_base_t a, const item_base_t b) +{ + return (item_base_t) (((item_flags_t) a) | ((item_flags_t) b)); +} + +static inline item_base_t & operator|=(item_base_t &a, item_base_t b) +{ + a= (item_base_t) (((item_flags_t) a) | (item_flags_t) b); + return a; +} + +static inline item_base_t operator~(const item_base_t a) +{ + return (item_base_t) ~(item_flags_t) a; +} + +static inline item_with_t operator&(const item_with_t a, const item_with_t b) +{ + return (item_with_t) (((item_flags_t) a) & ((item_flags_t) b)); +} + +static inline item_with_t & operator&=(item_with_t &a, item_with_t b) +{ + a= (item_with_t) (((item_flags_t) a) & (item_flags_t) b); + return a; +} + +static inline item_with_t operator|(const item_with_t a, const item_with_t b) +{ + return (item_with_t) (((item_flags_t) a) | ((item_flags_t) b)); +} + +static inline item_with_t & operator|=(item_with_t &a, item_with_t b) +{ + a= (item_with_t) (((item_flags_t) a) | (item_flags_t) b); + return a; +} + +static inline item_with_t operator~(const item_with_t a) +{ + return (item_with_t) ~(item_flags_t) a; +} class Item :public Value_source, @@ -941,8 +1005,8 @@ public: const char *orig_name; /* All common bool variables for an Item is stored here */ - typedef uint16 item_flags_t; - item_flags_t flags; + item_base_t base_flags; + item_with_t with_flags; /* Marker is used in some functions to temporary mark an item */ int16 marker; @@ -967,19 +1031,40 @@ public: */ uint8 join_tab_idx; - inline bool maybe_null() const { return (flags & ITEM_FLAG_MAYBE_NULL); } - inline bool in_rollup() const { return (flags & ITEM_FLAG_IN_ROLLUP); } - inline bool with_param() const { return (flags & ITEM_FLAG_WITH_PARAM); } - inline bool with_window_func() const { return (flags & ITEM_FLAG_WITH_WINDOW_FUNC); } - inline bool with_field() const { return (flags & ITEM_FLAG_WITH_FIELD); } - inline bool fixed() const { return (flags & ITEM_FLAG_FIXED); } - inline bool is_autogenerated_name() const { return (flags & ITEM_FLAG_IS_AUTOGENERATED_NAME); } - inline bool is_in_with_cycle() const { return (flags & ITEM_FLAG_IS_IN_WITH_CYCLE); } - inline bool with_sum_func() const { return (flags & ITEM_FLAG_WITH_SUM_FUNC); } - inline bool with_subquery() const { return (flags & ITEM_FLAG_WITH_SUBQUERY); } - inline void copy_flags(const Item *org, item_flags_t mask) - { - flags= (item_flags_t) ((flags & ~mask) | (org->flags & mask)); + inline bool maybe_null() const + { return (bool) (base_flags & item_base_t::MAYBE_NULL); } + inline bool in_rollup() const + { return (bool) (base_flags & item_base_t::IN_ROLLUP); } + inline bool fixed() const + { return (bool) (base_flags & item_base_t::FIXED); } + inline bool is_autogenerated_name() const + { return (bool) (base_flags & item_base_t::IS_AUTOGENERATED_NAME); } + inline bool is_in_with_cycle() const + { return (bool) (base_flags & item_base_t::IS_IN_WITH_CYCLE); } + + inline bool with_sp_var() const + { return (bool) (with_flags & item_with_t::SP_VAR); } + inline bool with_window_func() const + { return (bool) (with_flags & item_with_t::WINDOW_FUNC); } + inline bool with_field() const + { return (bool) (with_flags & item_with_t::FIELD); } + inline bool with_sum_func() const + { return (bool) (with_flags & item_with_t::SUM_FUNC); } + inline bool with_subquery() const + { return (bool) (with_flags & item_with_t::SUBQUERY); } + inline void copy_flags(const Item *org, item_base_t mask) + { + base_flags= (item_base_t) (((item_flags_t) base_flags & + ~(item_flags_t) mask) | + ((item_flags_t) org->base_flags & + (item_flags_t) mask)); + } + inline void copy_flags(const Item *org, item_with_t mask) + { + with_flags= (item_with_t) (((item_flags_t) with_flags & + ~(item_flags_t) mask) | + ((item_flags_t) org->with_flags & + (item_flags_t) mask)); } // alloc & destruct is done as start of select on THD::mem_root @@ -1017,7 +1102,7 @@ public: void share_name_with(const Item *item) { name= item->name; - copy_flags(item, ITEM_FLAG_IS_AUTOGENERATED_NAME); + copy_flags(item, item_base_t::IS_AUTOGENERATED_NAME); } virtual void cleanup(); virtual void make_send_field(THD *thd, Send_field *field); @@ -1178,19 +1263,26 @@ public: { return type_handler()->max_display_length(this); } - const TYPELIB *get_typelib() const { return NULL; } + const TYPELIB *get_typelib() const override { return NULL; } + /* optimized setting of maybe_null without jumps. Minimizes code size */ inline void set_maybe_null(bool maybe_null_arg) { - flags= ((item_flags_t) - ((flags & (item_flags_t) ~ITEM_FLAG_MAYBE_NULL) | - ((maybe_null_arg << ITEM_FLAG_MAYBE_NULL_SHIFT)))); + base_flags= ((item_base_t) ((base_flags & ~item_base_t::MAYBE_NULL)) | + (item_base_t) (maybe_null_arg << + ITEM_FLAGS_MAYBE_NULL_SHIFT)); + } + /* This is used a lot, so make it simpler to use */ + void set_maybe_null() + { + base_flags|= item_base_t::MAYBE_NULL; } /* This is used when calling Type_all_attributes::set_type_maybe_null() */ void set_type_maybe_null(bool maybe_null_arg) override { set_maybe_null(maybe_null_arg); } - void set_typelib(const TYPELIB *typelib) + + void set_typelib(const TYPELIB *typelib) override { // Non-field Items (e.g. hybrid functions) never have ENUM/SET types yet. DBUG_ASSERT(0); @@ -1220,7 +1312,8 @@ public: { return NON_MONOTONIC; } /* - Convert "func_arg $CMP$ const" half-interval into "FUNC(func_arg) $CMP2$ const2" + Convert "func_arg $CMP$ const" half-interval into + "FUNC(func_arg) $CMP2$ const2" SYNOPSIS val_int_endpoint() @@ -2742,26 +2835,28 @@ class Item_fixed_hybrid: public Item public: Item_fixed_hybrid(THD *thd): Item(thd) { - flags&= (item_flags_t) ~ITEM_FLAG_FIXED; + base_flags&= ~item_base_t::FIXED; } Item_fixed_hybrid(THD *thd, Item_fixed_hybrid *item) :Item(thd, item) { - flags|= (item_flags_t) (item->flags & ITEM_FLAG_FIXED); + base_flags|= (item->base_flags & item_base_t::FIXED); } bool fix_fields(THD *thd, Item **ref) override { DBUG_ASSERT(!fixed()); - flags|= ITEM_FLAG_FIXED; + base_flags|= item_base_t::FIXED; return false; } void cleanup() override { Item::cleanup(); - flags&= (item_flags_t) ~ITEM_FLAG_FIXED; + base_flags&= ~item_base_t::FIXED; } - void quick_fix_field() override { flags|= ITEM_FLAG_FIXED; } - void unfix_fields() override { flags&= (item_flags_t) ~ITEM_FLAG_FIXED; } + void quick_fix_field() override + { base_flags|= item_base_t::FIXED; } + void unfix_fields() override + { base_flags&= ~item_base_t::FIXED; } }; @@ -3685,7 +3780,7 @@ public: Item_null(THD *thd, const char *name_par=0, CHARSET_INFO *cs= &my_charset_bin): Item_basic_constant(thd) { - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); null_value= TRUE; max_length= 0; name.str= name_par ? name_par : "NULL"; @@ -5099,7 +5194,7 @@ public: Item_date_literal_for_invalid_dates(THD *thd, const Date *ltime) :Item_date_literal(thd, ltime) { - flags&= (item_flags_t) ~ITEM_FLAG_MAYBE_NULL; + base_flags&= ~item_base_t::MAYBE_NULL; } bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { @@ -5121,7 +5216,7 @@ public: decimal_digits_t dec_arg) :Item_datetime_literal(thd, ltime, dec_arg) { - flags&= (item_flags_t) ~ITEM_FLAG_MAYBE_NULL; + base_flags&= ~item_base_t::MAYBE_NULL; } bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { @@ -6046,7 +6141,7 @@ public: ref= &outer_ref; set_properties(); /* reset flag set in set_properties() */ - flags&= (item_flags_t) ~ITEM_FLAG_FIXED; + base_flags&= ~item_base_t::FIXED; } Item_outer_ref(THD *thd, Name_resolution_context *context_arg, Item **item, const LEX_CSTRING &table_name_arg, LEX_CSTRING &field_name_arg, @@ -6194,7 +6289,7 @@ protected: DBUG_ASSERT(org->fixed()); item= org; null_value= item->maybe_null(); - copy_flags(item, ITEM_FLAG_MAYBE_NULL); + copy_flags(item, item_base_t::MAYBE_NULL); Type_std_attributes::set(item); name= item->name; set_handler(item->type_handler()); @@ -6821,7 +6916,7 @@ public: value_cached(0), used_table_map(0) { - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); null_value= 1; null_value_inside= true; } @@ -6833,7 +6928,7 @@ protected: value_cached(0), used_table_map(0) { - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); null_value= 1; null_value_inside= true; } @@ -7385,8 +7480,8 @@ public: Type_std_attributes::set(*attr); set_maybe_null(maybe_null_arg); copy_flags(item, - ITEM_FLAG_IS_AUTOGENERATED_NAME | - ITEM_FLAG_IS_IN_WITH_CYCLE); + item_base_t::IS_AUTOGENERATED_NAME | + item_base_t::IS_IN_WITH_CYCLE); } const Type_handler *type_handler() const override diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 56b8791dabf..044dbe9f8ae 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -1142,7 +1142,7 @@ int Arg_comparator::compare_e_str_json() bool Item_func_truth::fix_length_and_dec() { - flags&= (item_flags_t) ~ITEM_FLAG_MAYBE_NULL; + base_flags&= ~item_base_t::MAYBE_NULL; null_value= 0; decimals= 0; max_length= 1; @@ -1336,10 +1336,8 @@ bool Item_in_optimizer::fix_left(THD *thd) used_tables_cache= args[0]->used_tables(); } eval_not_null_tables(NULL); - flags|= ((args[0]->flags & (ITEM_FLAG_WITH_SUM_FUNC | ITEM_FLAG_WITH_PARAM | - ITEM_FLAG_WITH_FIELD)) | - (args[1]->flags & (ITEM_FLAG_WITH_PARAM))); - + with_flags|= (args[0]->with_flags | + (args[1]->with_flags & item_with_t::SP_VAR)); if ((const_item_cache= args[0]->const_item())) { cache->store(args[0]); @@ -1349,7 +1347,7 @@ bool Item_in_optimizer::fix_left(THD *thd) { /* to avoid overriding is called to update left expression */ used_tables_and_const_cache_join(args[1]); - flags|= args[1]->flags & ITEM_FLAG_WITH_SUM_FUNC; + with_flags|= args[1]->with_flags & item_with_t::SUM_FUNC; } DBUG_RETURN(0); } @@ -1371,7 +1369,7 @@ bool Item_in_optimizer::fix_fields(THD *thd, Item **ref) if (fix_left(thd)) return TRUE; if (args[0]->maybe_null()) - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); if (args[1]->fix_fields_if_needed(thd, args + 1)) return TRUE; @@ -1383,12 +1381,11 @@ bool Item_in_optimizer::fix_fields(THD *thd, Item **ref) return TRUE; } - flags|= (ITEM_FLAG_FIXED | ITEM_FLAG_WITH_SUBQUERY | - (args[1]->flags & (ITEM_FLAG_MAYBE_NULL | - ITEM_FLAG_WITH_SUM_FUNC | - ITEM_FLAG_WITH_FIELD | - ITEM_FLAG_WITH_PARAM)) | - (args[0]->flags & ITEM_FLAG_WITH_PARAM)); + base_flags|= (item_base_t::FIXED | + (args[1]->base_flags & item_base_t::MAYBE_NULL)); + with_flags|= (item_with_t::SUBQUERY | + args[1]->with_flags | + (args[0]->with_flags & item_with_t::SP_VAR)); used_tables_and_const_cache_join(args[1]); return FALSE; } @@ -1777,7 +1774,7 @@ longlong Item_func_eq::val_int() bool Item_func_equal::fix_length_and_dec() { bool rc= Item_bool_rowready_func2::fix_length_and_dec(); - flags&= (item_flags_t) ~ITEM_FLAG_MAYBE_NULL; + base_flags&= ~item_base_t::MAYBE_NULL; null_value=0; return rc; } @@ -1931,13 +1928,11 @@ bool Item_func_interval::fix_length_and_dec() } } } - flags&= (item_flags_t) ~ITEM_FLAG_MAYBE_NULL; + base_flags&= ~item_base_t::MAYBE_NULL; max_length= 2; used_tables_and_const_cache_join(row); not_null_tables_cache= row->not_null_tables(); - flags|= (row->flags & (ITEM_FLAG_WITH_SUM_FUNC | - ITEM_FLAG_WITH_PARAM | - ITEM_FLAG_WITH_FIELD)); + with_flags|= row->with_flags; return FALSE; } @@ -2722,7 +2717,7 @@ Item_func_nullif::fix_length_and_dec() decimals= args[2]->decimals; unsigned_flag= args[2]->unsigned_flag; fix_char_length(args[2]->max_char_length()); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); m_arg0= args[0]; if (setup_args_and_comparator(thd, &cmp)) return TRUE; @@ -3137,7 +3132,7 @@ bool Item_func_case::fix_fields(THD *thd, Item **ref) Item **pos= else_expr_addr(); if (!pos || pos[0]->maybe_null()) - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return res; } @@ -4898,7 +4893,7 @@ Item_cond::fix_fields(THD *thd, Item **ref) return TRUE; /* purecov: inspected */ item= *li.ref(); // item can be substituted in fix_fields used_tables_cache|= item->used_tables(); - if (item->const_item() && !item->with_param() && + if (item->const_item() && !item->with_sp_var() && !item->is_expensive() && !cond_has_datetime_is_null(item)) { if (item->eval_const_cond() == is_and_cond && top_level()) @@ -4934,17 +4929,12 @@ Item_cond::fix_fields(THD *thd, Item **ref) const_item_cache= FALSE; } - - flags|= (item->flags & (ITEM_FLAG_WITH_SUM_FUNC | - ITEM_FLAG_WITH_PARAM | - ITEM_FLAG_WITH_FIELD | - ITEM_FLAG_WITH_SUBQUERY | - ITEM_FLAG_WITH_WINDOW_FUNC | - ITEM_FLAG_MAYBE_NULL)); + base_flags|= item->base_flags & item_base_t::MAYBE_NULL; + with_flags|= item->with_flags; } if (fix_length_and_dec()) return TRUE; - flags|= ITEM_FLAG_FIXED; + base_flags|= item_base_t::FIXED; return FALSE; } @@ -4960,7 +4950,7 @@ Item_cond::eval_not_null_tables(void *opt_arg) while ((item=li++)) { table_map tmp_table_map; - if (item->const_item() && !item->with_param() && + if (item->const_item() && !item->with_sp_var() && !item->is_expensive() && !cond_has_datetime_is_null(item)) { if (item->eval_const_cond() == is_and_cond && top_level()) @@ -6090,14 +6080,14 @@ void Regexp_processor_pcre::fix_owner(Item_func *owner, { if (compile(pattern_arg, true)) { - owner->flags|= ITEM_FLAG_MAYBE_NULL; // Will always return NULL + owner->set_maybe_null(); // Will always return NULL return; } set_const(true); - owner->flags|= subject_arg->flags & ITEM_FLAG_MAYBE_NULL; + owner->base_flags|= subject_arg->base_flags & item_base_t::MAYBE_NULL; } else - owner->flags|= ITEM_FLAG_MAYBE_NULL; + owner->set_maybe_null(); } @@ -7056,7 +7046,7 @@ bool Item_equal::fix_fields(THD *thd, Item **ref) not_null_tables_cache|= tmp_table_map; DBUG_ASSERT(!item->with_sum_func() && !item->with_subquery()); if (item->maybe_null()) - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); if (!item->get_item_equal()) item->set_item_equal(this); if (link_equal_fields && item->real_item()->type() == FIELD_ITEM) @@ -7073,7 +7063,7 @@ bool Item_equal::fix_fields(THD *thd, Item **ref) last_equal_field->next_equal_field= first_equal_field; if (fix_length_and_dec()) return TRUE; - flags|= ITEM_FLAG_FIXED; + base_flags|= item_base_t::FIXED; return FALSE; } diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index 99f17077e3b..e0e4a17ef89 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -368,7 +368,7 @@ public: Item_bool_func(thd, a, b), cache(0), expr_cache(0), save_cache(0), result_for_null_param(UNKNOWN) { - flags|= ITEM_FLAG_WITH_SUBQUERY; + with_flags|= item_with_t::SUBQUERY; } bool fix_fields(THD *, Item **) override; bool fix_left(THD *thd); @@ -1126,7 +1126,7 @@ public: IFNULL(inet6_not_null_expr, 'foo') -> INET6 NULL IFNULL(inet6_not_null_expr, '::1') -> INET6 NOT NULL */ - copy_flags(args[1], ITEM_FLAG_MAYBE_NULL); + copy_flags(args[1], item_base_t::MAYBE_NULL); if (Item_func_case_abbreviation2::fix_length_and_dec2(args)) return TRUE; return FALSE; @@ -2567,7 +2567,7 @@ public: { decimals=0; max_length=1; - flags&= (item_flags_t) ~ITEM_FLAG_MAYBE_NULL; + base_flags&= ~item_base_t::MAYBE_NULL; return FALSE; } bool count_sargable_conds(void *arg); @@ -3464,7 +3464,7 @@ public: Item_func_cursor_found(THD *thd, const LEX_CSTRING *name, uint offset) :Item_func_cursor_bool_attr(thd, name, offset) { - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); } const char *func_name() const { return "%FOUND"; } longlong val_int(); @@ -3479,7 +3479,7 @@ public: Item_func_cursor_notfound(THD *thd, const LEX_CSTRING *name, uint offset) :Item_func_cursor_bool_attr(thd, name, offset) { - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); } const char *func_name() const { return "%NOTFOUND"; } longlong val_int(); diff --git a/sql/item_func.cc b/sql/item_func.cc index 67251b73faf..21aaebdd52e 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -133,12 +133,7 @@ void Item_func::sync_with_sum_func_and_with_field(List<Item> &list) List_iterator_fast<Item> li(list); Item *item; while ((item= li++)) - { - flags|= (item->flags & (ITEM_FLAG_WITH_SUM_FUNC | - ITEM_FLAG_WITH_WINDOW_FUNC | - ITEM_FLAG_WITH_FIELD | - ITEM_FLAG_WITH_PARAM)); - } + with_flags|= item->with_flags; } @@ -353,8 +348,8 @@ Item_func::fix_fields(THD *thd, Item **ref) return TRUE; /* purecov: inspected */ item= *arg; - flags|= item->flags & ~(ITEM_FLAG_IS_AUTOGENERATED_NAME | - ITEM_FLAG_IS_IN_WITH_CYCLE); + base_flags|= item->base_flags & item_base_t::MAYBE_NULL; + with_flags|= item->with_flags; used_tables_and_const_cache_join(item); not_null_tables_cache|= item->not_null_tables(); } @@ -363,7 +358,7 @@ Item_func::fix_fields(THD *thd, Item **ref) return true; if (fix_length_and_dec()) return TRUE; - flags|= ITEM_FLAG_FIXED; + base_flags|= item_base_t::FIXED; return FALSE; } @@ -379,7 +374,7 @@ Item_func::quick_fix_field() (*arg)->quick_fix_field(); } } - flags|= ITEM_FLAG_FIXED; + base_flags|= item_base_t::FIXED; } @@ -593,9 +588,12 @@ void Item_func::split_sum_func(THD *thd, Ref_ptr_array ref_pointer_array, List<Item> &fields, uint flags) { Item **arg, **arg_end; + DBUG_ENTER("Item_func::split_sum_func"); + for (arg= args, arg_end= args+arg_count; arg != arg_end ; arg++) (*arg)->split_sum_func2(thd, ref_pointer_array, fields, arg, flags | SPLIT_SUM_SKIP_REGISTERED); + DBUG_VOID_RETURN; } @@ -1586,7 +1584,7 @@ bool Item_func_div::fix_length_and_dec() DBUG_ENTER("Item_func_div::fix_length_and_dec"); DBUG_PRINT("info", ("name %s", func_name())); prec_increment= current_thd->variables.div_precincrement; - flags|= ITEM_FLAG_MAYBE_NULL; // division by zero + set_maybe_null(); // division by zero const Type_aggregator *aggregator= &type_handler_data->m_type_aggregator_for_div; DBUG_EXECUTE_IF("num_op", aggregator= &type_handler_data->m_type_aggregator_non_commutative_test;); @@ -1664,7 +1662,7 @@ bool Item_func_int_div::fix_length_and_dec() uint32 prec= args[0]->decimal_int_part(); set_if_smaller(prec, MY_INT64_NUM_DECIMAL_DIGITS); fix_char_length(prec); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); unsigned_flag=args[0]->unsigned_flag | args[1]->unsigned_flag; return false; } @@ -1744,7 +1742,7 @@ bool Item_func_mod::fix_length_and_dec() { DBUG_ENTER("Item_func_mod::fix_length_and_dec"); DBUG_PRINT("info", ("name %s", func_name())); - flags|= ITEM_FLAG_MAYBE_NULL; // division by zero + set_maybe_null(); // division by zero const Type_aggregator *aggregator= &type_handler_data->m_type_aggregator_for_mod; DBUG_EXECUTE_IF("num_op", aggregator= &type_handler_data->m_type_aggregator_non_commutative_test;); DBUG_ASSERT(!aggregator->is_commutative()); @@ -2553,7 +2551,7 @@ void Item_func_round::fix_arg_datetime() return NULL. */ if (!truncate) - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); fix_arg_temporal(&type_handler_datetime2, MAX_DATETIME_WIDTH); } @@ -3235,7 +3233,7 @@ longlong Item_func_field::val_int() bool Item_func_field::fix_length_and_dec() { - flags&= (item_flags_t) ~ITEM_FLAG_MAYBE_NULL; + base_flags&= ~item_base_t::MAYBE_NULL; max_length=3; cmp_type= args[0]->result_type(); for (uint i=1; i < arg_count ; i++) @@ -3479,7 +3477,7 @@ udf_handler::fix_fields(THD *thd, Item_func_or_sum *func, args=arguments; /* Fix all arguments */ - func->flags&= (Item::item_flags_t) ~ITEM_FLAG_MAYBE_NULL; + func->base_flags&= ~item_base_t::MAYBE_NULL; func->used_tables_and_const_cache_init(); if ((f_args.arg_count=arg_count)) @@ -3514,12 +3512,8 @@ udf_handler::fix_fields(THD *thd, Item_func_or_sum *func, */ if (item->collation.collation->state & MY_CS_BINSORT) func->collation.set(&my_charset_bin); - func->flags|= (item->flags & (ITEM_FLAG_MAYBE_NULL | - ITEM_FLAG_WITH_SUM_FUNC | - ITEM_FLAG_WITH_WINDOW_FUNC | - ITEM_FLAG_WITH_FIELD | - ITEM_FLAG_WITH_PARAM | - ITEM_FLAG_WITH_SUBQUERY)); + func->base_flags|= item->base_flags & item_base_t::MAYBE_NULL; + func->with_flags|= item->with_flags; func->used_tables_and_const_cache_join(item); f_args.arg_type[i]=item->result_type(); } @@ -4789,7 +4783,7 @@ bool Item_func_set_user_var::fix_fields(THD *thd, Item **ref) bool Item_func_set_user_var::fix_length_and_dec() { - flags|= (args[0]->flags & ITEM_FLAG_MAYBE_NULL); + base_flags|= (args[0]->base_flags & item_base_t::MAYBE_NULL); decimals=args[0]->decimals; if (args[0]->collation.derivation == DERIVATION_NUMERIC) { @@ -5646,7 +5640,7 @@ bool Item_func_get_user_var::fix_length_and_dec() { THD *thd=current_thd; int error; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); decimals=NOT_FIXED_DEC; max_length=MAX_BLOB_WIDTH; @@ -5856,7 +5850,7 @@ void Item_func_get_system_var::update_null_value() bool Item_func_get_system_var::fix_length_and_dec() { char *cptr; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); max_length= 0; if (var->check_type(var_type)) @@ -6219,7 +6213,7 @@ bool Item_func_match::fix_fields(THD *thd, Item **ref) status_var_increment(thd->status_var.feature_fulltext); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); join_key=0; /* @@ -6555,7 +6549,7 @@ Item_func_sp::Item_func_sp(THD *thd, Name_resolution_context *context_arg, sp_name *name, const Sp_handler *sph): Item_func(thd), Item_sp(thd, context_arg, name), m_handler(sph) { - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); } @@ -6564,7 +6558,7 @@ Item_func_sp::Item_func_sp(THD *thd, Name_resolution_context *context_arg, List<Item> &list): Item_func(thd, list), Item_sp(thd, context_arg, name_arg), m_handler(sph) { - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); } @@ -6620,7 +6614,7 @@ bool Item_func_sp::fix_length_and_dec() Type_std_attributes::set(sp_result_field->type_std_attributes()); // There is a bug in the line below. See MDEV-11292 for details. collation.derivation= DERIVATION_COERCIBLE; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); DBUG_RETURN(FALSE); } diff --git a/sql/item_func.h b/sql/item_func.h index bac2b8d0f94..4b8ed99a9d8 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -97,45 +97,33 @@ public: virtual enum Functype functype() const { return UNKNOWN_FUNC; } Item_func(THD *thd): Item_func_or_sum(thd) { - flags&=(item_flags_t) ~(ITEM_FLAG_WITH_FIELD | ITEM_FLAG_WITH_FIELD); + DBUG_ASSERT(with_flags == item_with_t::NONE); + with_flags= item_with_t::NONE; } Item_func(THD *thd, Item *a): Item_func_or_sum(thd, a) { - copy_flags(a, - ITEM_FLAG_WITH_SUM_FUNC | ITEM_FLAG_WITH_FIELD | - ITEM_FLAG_WITH_PARAM); + with_flags= a->with_flags; } Item_func(THD *thd, Item *a, Item *b): Item_func_or_sum(thd, a, b) { - flags|= ((a->flags | b->flags) & - (ITEM_FLAG_WITH_SUM_FUNC | - ITEM_FLAG_WITH_PARAM | - ITEM_FLAG_WITH_FIELD)); + with_flags= a->with_flags | b->with_flags; } Item_func(THD *thd, Item *a, Item *b, Item *c): Item_func_or_sum(thd, a, b, c) { - flags|= ((a->flags | b->flags | c->flags) & - (ITEM_FLAG_WITH_SUM_FUNC | - ITEM_FLAG_WITH_PARAM | - ITEM_FLAG_WITH_FIELD)); + with_flags|= a->with_flags | b->with_flags | c->with_flags; } Item_func(THD *thd, Item *a, Item *b, Item *c, Item *d): Item_func_or_sum(thd, a, b, c, d) { - flags|= ((a->flags | b->flags | c->flags | d->flags) & - (ITEM_FLAG_WITH_SUM_FUNC | - ITEM_FLAG_WITH_PARAM | - ITEM_FLAG_WITH_FIELD)); + with_flags= a->with_flags | b->with_flags | c->with_flags | d->with_flags; } Item_func(THD *thd, Item *a, Item *b, Item *c, Item *d, Item* e): Item_func_or_sum(thd, a, b, c, d, e) { - flags|= ((a->flags | b->flags | c->flags | d->flags | e->flags) & - (ITEM_FLAG_WITH_SUM_FUNC | - ITEM_FLAG_WITH_PARAM | - ITEM_FLAG_WITH_FIELD)); + with_flags= (a->with_flags | b->with_flags | c->with_flags | d->with_flags | + e->with_flags); } Item_func(THD *thd, List<Item> &list): Item_func_or_sum(thd, list) @@ -153,10 +141,11 @@ public: Item_func_or_sum::cleanup(); used_tables_and_const_cache_init(); } - void fix_after_pullout(st_select_lex *new_parent, Item **ref, bool merge); - void quick_fix_field(); - table_map not_null_tables() const; - void update_used_tables() + void fix_after_pullout(st_select_lex *new_parent, Item **ref, bool merge) + override; + void quick_fix_field() override; + table_map not_null_tables() const override; + void update_used_tables() override { used_tables_and_const_cache_init(); used_tables_and_const_cache_update_and_join(arg_count, args); @@ -201,7 +190,7 @@ public: if (max_result_length >= MAX_BLOB_WIDTH) { max_length= MAX_BLOB_WIDTH; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); } else max_length= (uint32) max_result_length; @@ -1253,7 +1242,7 @@ public: Item_func_cursor_rowcount(THD *thd, const LEX_CSTRING *name, uint offset) :Item_longlong_func(thd), Cursor_ref(name, offset) { - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); } const char *func_name() const { return "%ROWCOUNT"; } longlong val_int(); @@ -1433,7 +1422,7 @@ public: void print(String *str, enum_query_type query_type); void fix_length_and_dec_generic() { - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); } }; @@ -1699,7 +1688,7 @@ class Item_dec_func :public Item_real_func { decimals= NOT_FIXED_DEC; max_length= float_length(decimals); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } }; @@ -1873,7 +1862,7 @@ public: fix_attributes_datetime(0); set_handler(&type_handler_datetime2); // Thinks like CEILING(TIMESTAMP'0000-01-01 23:59:59.9') returns NULL - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); } bool fix_length_and_dec(); String *str_op(String *str) { DBUG_ASSERT(0); return 0; } @@ -2234,7 +2223,7 @@ public: bool fix_length_and_dec() { max_length=10; - flags&= (item_flags_t) ~ITEM_FLAG_MAYBE_NULL; + base_flags&= ~item_base_t::MAYBE_NULL; return FALSE; } bool eval_not_null_tables(void *) @@ -2497,7 +2486,7 @@ public: bool fix_length_and_dec() { max_length=1; - flags&= (item_flags_t) ~ITEM_FLAG_MAYBE_NULL; + base_flags&= ~item_base_t::MAYBE_NULL; return FALSE; } virtual void print(String *str, enum_query_type query_type); @@ -2579,7 +2568,7 @@ public: DBUG_ASSERT(fixed() == 0); bool res= udf.fix_fields(thd, this, arg_count, args); set_non_deterministic_if_needed(); - flags|= ITEM_FLAG_FIXED; + base_flags|= item_base_t::FIXED; return res; } void fix_num_length_and_dec(); @@ -2828,7 +2817,8 @@ public: { DBUG_ASSERT(fixed()); null_value=1; return 0; } double val_real() { DBUG_ASSERT(fixed()); null_value= 1; return 0.0; } longlong val_int() { DBUG_ASSERT(fixed()); null_value=1; return 0; } - bool fix_length_and_dec() { flags|= ITEM_FLAG_MAYBE_NULL; max_length=0; return FALSE; } + bool fix_length_and_dec() override + { base_flags|= item_base_t::MAYBE_NULL; max_length=0; return FALSE; } }; #endif /* HAVE_DLOPEN */ @@ -2871,7 +2861,7 @@ class Item_func_get_lock final :public Item_func_lock bool fix_length_and_dec() { max_length= 1; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } Item *get_copy(THD *thd) final @@ -2903,7 +2893,7 @@ public: bool fix_length_and_dec() { max_length= 1; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } Item *get_copy(THD *thd) final @@ -2936,7 +2926,7 @@ public: bool fix_length_and_dec() { max_length=21; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } bool check_vcol_func_processor(void *arg) @@ -3378,7 +3368,7 @@ public: { decimals=0; max_length=1; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } bool check_vcol_func_processor(void *arg) @@ -3401,7 +3391,7 @@ public: bool fix_length_and_dec() { decimals=0; max_length=10; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } bool check_vcol_func_processor(void *arg) @@ -3458,7 +3448,7 @@ public: bool fix_length_and_dec() { decimals= 0; - flags&= (item_flags_t) ~ITEM_FLAG_MAYBE_NULL; + base_flags&= ~item_base_t::MAYBE_NULL; return FALSE; } bool check_vcol_func_processor(void *arg) @@ -3628,7 +3618,7 @@ public: bool fix_length_and_dec() { decimals= 0; - flags&= (item_flags_t) ~ITEM_FLAG_MAYBE_NULL; + base_flags&= ~item_base_t::MAYBE_NULL; return FALSE; } bool check_vcol_func_processor(void *arg) @@ -3675,7 +3665,7 @@ public: } bool fix_length_and_dec() { - flags&= (item_flags_t) ~ITEM_FLAG_MAYBE_NULL; + base_flags&= ~item_base_t::MAYBE_NULL; null_value= false; max_length= 11; return FALSE; @@ -3735,7 +3725,7 @@ public: void update_used_tables() { Item_func::update_used_tables(); - copy_flags(last_value, ITEM_FLAG_MAYBE_NULL); + copy_flags(last_value, item_base_t::MAYBE_NULL); } Item *get_copy(THD *thd) { return get_item_copy<Item_func_last_value>(thd, this); } @@ -3758,7 +3748,7 @@ public: { unsigned_flag= 0; max_length= MAX_BIGINT_WIDTH; - flags|= ITEM_FLAG_MAYBE_NULL; /* In case of errors */ + set_maybe_null(); /* In case of errors */ return FALSE; } /* diff --git a/sql/item_geofunc.cc b/sql/item_geofunc.cc index 4c6b7417055..8247fae6226 100644 --- a/sql/item_geofunc.cc +++ b/sql/item_geofunc.cc @@ -47,7 +47,7 @@ bool Item_geometry_func::fix_length_and_dec() collation.set(&my_charset_bin); decimals=0; max_length= (uint32) UINT_MAX32; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } @@ -218,7 +218,7 @@ bool Item_func_as_wkt::fix_length_and_dec() { collation.set(default_charset(), DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII); max_length= (uint32) UINT_MAX32; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } @@ -245,7 +245,7 @@ bool Item_func_as_geojson::fix_length_and_dec() { collation.set(default_charset(), DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII); max_length=MAX_BLOB_WIDTH; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } diff --git a/sql/item_geofunc.h b/sql/item_geofunc.h index bafd666789e..476bee672ff 100644 --- a/sql/item_geofunc.h +++ b/sql/item_geofunc.h @@ -284,7 +284,7 @@ public: collation.set(&my_charset_bin); decimals=0; max_length= (uint32) UINT_MAX32; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } Item *get_copy(THD *thd) @@ -326,7 +326,7 @@ public: { // "GeometryCollection" is the longest fix_length_and_charset(20, default_charset()); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; }; Item *get_copy(THD *thd) @@ -675,7 +675,7 @@ public: Item_func_spatial_rel(THD *thd, Item *a, Item *b, enum Functype sp_rel): Item_bool_func2_with_rev(thd, a, b), spatial_rel(sp_rel) { - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); } enum Functype functype() const { return spatial_rel; } enum Functype rev_functype() const @@ -854,11 +854,12 @@ class Item_func_isempty: public Item_bool_func_args_geometry public: Item_func_isempty(THD *thd, Item *a) :Item_bool_func_args_geometry(thd, a) {} - longlong val_int(); + longlong val_int() override; const char *func_name() const { return "st_isempty"; } - bool fix_length_and_dec() { flags|= ITEM_FLAG_MAYBE_NULL; return FALSE; } - bool need_parentheses_in_default() { return false; } - Item *get_copy(THD *thd) + bool fix_length_and_dec() override + { set_maybe_null(); return FALSE; } + bool need_parentheses_in_default() override { return false; } + Item *get_copy(THD *thd) override { return get_item_copy<Item_func_isempty>(thd, this); } }; @@ -907,10 +908,11 @@ class Item_func_dimension: public Item_long_func_args_geometry public: Item_func_dimension(THD *thd, Item *a) :Item_long_func_args_geometry(thd, a) {} - longlong val_int(); + longlong val_int() override; const char *func_name() const { return "st_dimension"; } - bool fix_length_and_dec() { max_length= 10; flags|= ITEM_FLAG_MAYBE_NULL; return FALSE; } - Item *get_copy(THD *thd) + bool fix_length_and_dec() override + { max_length= 10; set_maybe_null(); return FALSE; } + Item *get_copy(THD *thd) override { return get_item_copy<Item_func_dimension>(thd, this); } }; @@ -925,7 +927,7 @@ public: { if (Item_real_func::fix_length_and_dec()) return TRUE; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } Item *get_copy(THD *thd) @@ -943,7 +945,7 @@ public: { if (Item_real_func::fix_length_and_dec()) return TRUE; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } Item *get_copy(THD *thd) @@ -956,10 +958,11 @@ class Item_func_numgeometries: public Item_long_func_args_geometry public: Item_func_numgeometries(THD *thd, Item *a) :Item_long_func_args_geometry(thd, a) {} - longlong val_int(); + longlong val_int() override; const char *func_name() const { return "st_numgeometries"; } - bool fix_length_and_dec() { max_length= 10; flags|= ITEM_FLAG_MAYBE_NULL; return FALSE; } - Item *get_copy(THD *thd) + bool fix_length_and_dec() override + { max_length= 10; set_maybe_null(); return FALSE; } + Item *get_copy(THD *thd) override { return get_item_copy<Item_func_numgeometries>(thd, this); } }; @@ -969,10 +972,11 @@ class Item_func_numinteriorring: public Item_long_func_args_geometry public: Item_func_numinteriorring(THD *thd, Item *a) :Item_long_func_args_geometry(thd, a) {} - longlong val_int(); + longlong val_int() override; const char *func_name() const { return "st_numinteriorrings"; } - bool fix_length_and_dec() { max_length= 10; flags|= ITEM_FLAG_MAYBE_NULL; return FALSE; } - Item *get_copy(THD *thd) + bool fix_length_and_dec() override + { max_length= 10; set_maybe_null(); return FALSE; } + Item *get_copy(THD *thd) override { return get_item_copy<Item_func_numinteriorring>(thd, this); } }; @@ -982,10 +986,11 @@ class Item_func_numpoints: public Item_long_func_args_geometry public: Item_func_numpoints(THD *thd, Item *a) :Item_long_func_args_geometry(thd, a) {} - longlong val_int(); + longlong val_int() override; const char *func_name() const { return "st_numpoints"; } - bool fix_length_and_dec() { max_length= 10; flags|= ITEM_FLAG_MAYBE_NULL; return FALSE; } - Item *get_copy(THD *thd) + bool fix_length_and_dec() override + { max_length= 10; set_maybe_null(); return FALSE; } + Item *get_copy(THD *thd) override { return get_item_copy<Item_func_numpoints>(thd, this); } }; @@ -1000,7 +1005,7 @@ public: { if (Item_real_func::fix_length_and_dec()) return TRUE; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } Item *get_copy(THD *thd) @@ -1020,7 +1025,7 @@ public: { if (Item_real_func::fix_length_and_dec()) return TRUE; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } Item *get_copy(THD *thd) @@ -1033,10 +1038,11 @@ class Item_func_srid: public Item_long_func_args_geometry public: Item_func_srid(THD *thd, Item *a) :Item_long_func_args_geometry(thd, a) {} - longlong val_int(); + longlong val_int() override; const char *func_name() const { return "srid"; } - bool fix_length_and_dec() { max_length= 10; flags|= ITEM_FLAG_MAYBE_NULL; return FALSE; } - Item *get_copy(THD *thd) + bool fix_length_and_dec() override + { max_length= 10; set_maybe_null(); return FALSE; } + Item *get_copy(THD *thd) override { return get_item_copy<Item_func_srid>(thd, this); } }; diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc index 41bcc98df2d..67a5a8fec00 100644 --- a/sql/item_jsonfunc.cc +++ b/sql/item_jsonfunc.cc @@ -397,7 +397,7 @@ bool Item_func_json_exists::fix_length_and_dec() { if (Item_bool_func::fix_length_and_dec()) return TRUE; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); path.set_constant_flag(args[1]->const_item()); return FALSE; } @@ -451,7 +451,7 @@ bool Item_func_json_value::fix_length_and_dec() collation.set(args[0]->collation); max_length= args[0]->max_length; set_constant_flag(args[1]->const_item()); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } @@ -461,7 +461,7 @@ bool Item_func_json_query::fix_length_and_dec() collation.set(args[0]->collation); max_length= args[0]->max_length; set_constant_flag(args[1]->const_item()); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } @@ -609,7 +609,7 @@ bool Item_func_json_unquote::fix_length_and_dec() collation.set(&my_charset_utf8mb3_general_ci, DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII); max_length= args[0]->max_length; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } @@ -730,7 +730,7 @@ bool Item_func_json_extract::fix_length_and_dec() max_length= args[0]->max_length * (arg_count - 1); mark_constant_paths(paths, args+1, arg_count-1); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } @@ -1000,7 +1000,7 @@ bool Item_func_json_contains::fix_length_and_dec() { a2_constant= args[1]->const_item(); a2_parsed= FALSE; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); if (arg_count > 2) path.set_constant_flag(args[2]->const_item()); return Item_bool_func::fix_length_and_dec(); @@ -1251,7 +1251,7 @@ bool Item_func_json_contains_path::fix_length_and_dec() { ooa_constant= args[1]->const_item(); ooa_parsed= FALSE; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); mark_constant_paths(paths, args+2, arg_count-2); return Item_bool_func::fix_length_and_dec(); } @@ -1642,7 +1642,7 @@ bool Item_func_json_array_append::fix_length_and_dec() } fix_char_length_ulonglong(char_length); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } @@ -2561,7 +2561,7 @@ bool Item_func_json_length::fix_length_and_dec() { if (arg_count > 1) path.set_constant_flag(args[1]->const_item()); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); max_length= 10; return FALSE; } @@ -2707,7 +2707,7 @@ bool Item_func_json_type::fix_length_and_dec() { collation.set(&my_charset_utf8mb3_general_ci); max_length= 12; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } @@ -2776,7 +2776,7 @@ bool Item_func_json_insert::fix_length_and_dec() } fix_char_length_ulonglong(char_length); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } @@ -3028,7 +3028,7 @@ bool Item_func_json_remove::fix_length_and_dec() max_length= args[0]->max_length; mark_constant_paths(paths, args+1, arg_count-1); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } @@ -3213,7 +3213,7 @@ bool Item_func_json_keys::fix_length_and_dec() { collation.set(args[0]->collation); max_length= args[0]->max_length; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); if (arg_count > 1) path.set_constant_flag(args[1]->const_item()); return FALSE; @@ -3398,7 +3398,7 @@ bool Item_func_json_search::fix_length_and_dec() if (arg_count > 4) mark_constant_paths(paths, args+4, arg_count-4); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } @@ -3581,7 +3581,7 @@ bool Item_func_json_format::fix_length_and_dec() { decimals= 0; max_length= args[0]->max_length; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } @@ -3789,7 +3789,7 @@ Item_func_json_objectagg::fix_fields(THD *thd, Item **ref) if (init_sum_func_check(thd)) return TRUE; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); /* Fix fields for select list and ORDER clause @@ -3799,9 +3799,7 @@ Item_func_json_objectagg::fix_fields(THD *thd, Item **ref) { if (args[i]->fix_fields_if_needed_for_scalar(thd, &args[i])) return TRUE; - flags|= (args[i]->flags & (ITEM_FLAG_WITH_SUBQUERY | - ITEM_FLAG_WITH_PARAM | - ITEM_FLAG_WITH_WINDOW_FUNC)); + with_flags|= args[i]->with_flags; } /* skip charset aggregation for order columns */ @@ -3818,7 +3816,7 @@ Item_func_json_objectagg::fix_fields(THD *thd, Item **ref) if (check_sum_func(thd, ref)) return TRUE; - flags|= ITEM_FLAG_FIXED; + base_flags|= item_base_t::FIXED; return FALSE; } diff --git a/sql/item_jsonfunc.h b/sql/item_jsonfunc.h index af4221f0305..2ba515f448b 100644 --- a/sql/item_jsonfunc.h +++ b/sql/item_jsonfunc.h @@ -88,7 +88,7 @@ public: { if (Item_bool_func::fix_length_and_dec()) return TRUE; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } bool set_format_by_check_constraint(Send_field_extended_metadata *to) const diff --git a/sql/item_row.cc b/sql/item_row.cc index 5cbd2d4caa9..3981392b0ae 100644 --- a/sql/item_row.cc +++ b/sql/item_row.cc @@ -38,7 +38,7 @@ bool Item_row::fix_fields(THD *thd, Item **ref) { DBUG_ASSERT(fixed() == 0); null_value= 0; - flags&= (item_flags_t) ~ITEM_FLAG_MAYBE_NULL; + base_flags&= ~item_base_t::MAYBE_NULL; Item **arg, **arg_end; for (arg= args, arg_end= args + arg_count; arg != arg_end ; arg++) @@ -61,14 +61,10 @@ bool Item_row::fix_fields(THD *thd, Item **ref) with_null|= 1; } } - flags|= (item->flags & (ITEM_FLAG_MAYBE_NULL | - ITEM_FLAG_WITH_SUM_FUNC | - ITEM_FLAG_WITH_WINDOW_FUNC | - ITEM_FLAG_WITH_FIELD | - ITEM_FLAG_WITH_SUBQUERY | - ITEM_FLAG_WITH_PARAM)); + base_flags|= (item->base_flags & item_base_t::MAYBE_NULL); + with_flags|= item->with_flags; } - flags|= ITEM_FLAG_FIXED; + base_flags|= item_base_t::FIXED; return FALSE; } diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index d4b6e28d96f..186693fb128 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -124,7 +124,8 @@ bool Item_str_func::fix_fields(THD *thd, Item **ref) In Item_str_func::check_well_formed_result() we may set null_value flag on the same condition as in test() below. */ - flags|= thd->is_strict_mode() ? ITEM_FLAG_MAYBE_NULL : 0; + if (thd->is_strict_mode()) + set_maybe_null(); return res; } @@ -286,7 +287,7 @@ String *Item_func_sha2::val_str_ascii(String *str) bool Item_func_sha2::fix_length_and_dec() { - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); max_length = 0; int sha_variant= (int)(args[1]->const_item() ? args[1]->val_int() : 512); @@ -374,7 +375,7 @@ bool Item_func_aes_encrypt::fix_length_and_dec() bool Item_func_aes_decrypt::fix_length_and_dec() { max_length=args[0]->max_length; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); what= ENCRYPTION_FLAG_DECRYPT; return FALSE; } @@ -382,11 +383,11 @@ bool Item_func_aes_decrypt::fix_length_and_dec() bool Item_func_to_base64::fix_length_and_dec() { - flags|= args[0]->flags & ITEM_FLAG_MAYBE_NULL; + base_flags|= args[0]->base_flags & item_base_t::MAYBE_NULL; collation.set(default_charset(), DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII); if (args[0]->max_length > (uint) my_base64_encode_max_arg_length()) { - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); fix_char_length_ulonglong((ulonglong) my_base64_encode_max_arg_length()); } else @@ -442,7 +443,8 @@ bool Item_func_from_base64::fix_length_and_dec() int length= my_base64_needed_decoded_length((int) args[0]->max_length); fix_char_length_ulonglong((ulonglong) length); } - flags|= ITEM_FLAG_MAYBE_NULL; // Can be NULL, e.g. in case of badly formed input string + // Can be NULL, e.g. in case of badly formed input string + set_maybe_null(); return FALSE; } @@ -2311,7 +2313,8 @@ bool Item_func_encode::seed() bool Item_func_encode::fix_length_and_dec() { max_length=args[0]->max_length; - flags|= (args[0]->flags | args[1]->flags) & ITEM_FLAG_MAYBE_NULL; + base_flags|= ((args[0]->base_flags | args[1]->base_flags) & + item_base_t::MAYBE_NULL); collation.set(&my_charset_bin); /* Precompute the seed state if the item is constant. */ seeded= args[1]->const_item() && @@ -2475,11 +2478,11 @@ bool Item_func_current_role::fix_fields(THD *thd, Item **ref) return 1; str_value.mark_as_const(); null_value= 0; - flags&= (item_flags_t) ~ITEM_FLAG_MAYBE_NULL; + base_flags&= ~item_base_t::MAYBE_NULL; return 0; } null_value= 1; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return 0; } @@ -2814,7 +2817,7 @@ bool Item_func_elt::fix_length_and_dec() set_if_bigger(decimals,args[i]->decimals); } fix_char_length(char_length); - flags|= ITEM_FLAG_MAYBE_NULL; // NULL if wrong first arg + set_maybe_null(); // NULL if wrong first arg return FALSE; } @@ -3038,7 +3041,7 @@ bool Item_func_repeat::fix_length_and_dec() return false; } max_length= MAX_BLOB_WIDTH; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return false; } @@ -3110,7 +3113,7 @@ bool Item_func_space::fix_length_and_dec() return false; } max_length= MAX_BLOB_WIDTH; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return false; } @@ -3165,7 +3168,7 @@ bool Item_func_binlog_gtid_pos::fix_length_and_dec() { collation.set(system_charset_info); max_length= MAX_BLOB_WIDTH; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } @@ -3207,8 +3210,9 @@ bool Item_func_pad::fix_length_and_dec() if (arg_count == 3) { String *str; - if (!args[2]->basic_const_item() || !(str= args[2]->val_str(&pad_str)) || !str->length()) - flags|= ITEM_FLAG_MAYBE_NULL; + if (!args[2]->basic_const_item() || !(str= args[2]->val_str(&pad_str)) || + !str->length()) + set_maybe_null(); // Handle character set for args[0] and args[2]. if (agg_arg_charsets_for_string_result(collation, &args[0], 2, 2)) return TRUE; @@ -3229,7 +3233,7 @@ bool Item_func_pad::fix_length_and_dec() return false; } max_length= MAX_BLOB_WIDTH; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return false; } @@ -3614,7 +3618,7 @@ bool Item_func_weight_string::fix_length_and_dec() args[0]->max_char_length() : nweights * cs->levels_for_order; max_length= (uint32) cs->strnxfrmlen(char_length * cs->mbmaxlen); } - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } @@ -4397,7 +4401,7 @@ bool Item_func_dyncol_create::fix_fields(THD *thd, Item **ref) bool Item_func_dyncol_create::fix_length_and_dec() { max_length= MAX_BLOB_WIDTH; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); collation.set(&my_charset_bin); decimals= 0; return FALSE; diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index 2501a6d99fb..5981123888b 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -299,7 +299,7 @@ public: { collation.set(system_charset_info); max_length= MAX_BLOB_WIDTH; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } const char *func_name() const { return "decode_histogram"; } @@ -511,7 +511,7 @@ public: bool fix_length_and_dec() { bool res= Item_func_substr::fix_length_and_dec(); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return res; } const char *func_name() const { return "substr_oracle"; } @@ -586,7 +586,7 @@ public: bool fix_length_and_dec() { bool res= Item_func_trim::fix_length_and_dec(); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return res; } Item *get_copy(THD *thd) @@ -625,7 +625,7 @@ public: bool fix_length_and_dec() { bool res= Item_func_ltrim::fix_length_and_dec(); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return res; } Item *get_copy(THD *thd) @@ -660,7 +660,7 @@ public: bool fix_length_and_dec() { bool res= Item_func_rtrim::fix_length_and_dec(); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return res; } Item *get_copy(THD *thd) @@ -719,7 +719,7 @@ public: String *val_str(String *); bool fix_length_and_dec() { - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); /* 9 = MAX ((8- (arg_len % 8)) + 1) */ max_length = args[0]->max_length + 9; return FALSE; @@ -740,7 +740,7 @@ public: String *val_str(String *); bool fix_length_and_dec() { - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); /* 9 = MAX ((8- (arg_len % 8)) + 1) */ max_length= args[0]->max_length; if (max_length >= 9U) @@ -780,7 +780,7 @@ public: String *val_str(String *); bool fix_length_and_dec() { - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); max_length = 13; return FALSE; } @@ -860,7 +860,7 @@ public: bool fix_length_and_dec() { max_length= MAX_FIELD_NAME * system_charset_info->mbmaxlen; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } const char *func_name() const { return "database"; } @@ -885,7 +885,7 @@ public: { max_length= 512 * system_charset_info->mbmaxlen; null_value= false; - flags&= (item_flags_t) ~ITEM_FLAG_MAYBE_NULL; + base_flags&= ~item_base_t::MAYBE_NULL; return FALSE; } Item *get_copy(THD *thd) @@ -1160,7 +1160,7 @@ public: bool fix_length_and_dec() { bool res= Item_func_rpad::fix_length_and_dec(); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return res; } const char *func_name() const { return "rpad_oracle"; } @@ -1195,7 +1195,7 @@ public: bool fix_length_and_dec() { bool res= Item_func_lpad::fix_length_and_dec(); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return res; } const char *func_name() const { return "lpad_oracle"; } @@ -1215,7 +1215,7 @@ public: { collation.set(default_charset()); fix_char_length(64); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } Item *get_copy(THD *thd) @@ -1265,7 +1265,7 @@ public: Item_func_unhex(THD *thd, Item *a): Item_str_func(thd, a) { /* there can be bad hex strings */ - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); } const char *func_name() const { return "unhex"; } String *val_str(String *); @@ -1292,7 +1292,7 @@ public: Item_func_like_range(THD *thd, Item *a, Item *b, bool is_min_arg): Item_str_func(thd, a, b), is_min(is_min_arg) { - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); } String *val_str(String *); bool fix_length_and_dec() @@ -1365,7 +1365,7 @@ public: bool fix_length_and_dec() { collation.set(&my_charset_bin, DERIVATION_COERCIBLE); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); max_length=MAX_BLOB_WIDTH; return FALSE; } @@ -1539,7 +1539,7 @@ public: { collation.set(system_charset_info); max_length= 64 * collation.collation->mbmaxlen; // should be enough - flags&= (item_flags_t) ~ITEM_FLAG_MAYBE_NULL; + base_flags&= ~item_base_t::MAYBE_NULL; return FALSE; }; table_map not_null_tables() const { return 0; } @@ -1632,7 +1632,7 @@ public: bool fix_length_and_dec() { max_length=10; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } longlong val_int(); Item *get_copy(THD *thd) @@ -1670,7 +1670,7 @@ public: :Item_str_binary_checksum_func(thd, a) {} bool fix_length_and_dec() { - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); max_length= MAX_BLOB_WIDTH; return FALSE; } @@ -1750,7 +1750,7 @@ public: bool fix_length_and_dec() { max_length= MAX_BLOB_WIDTH; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); decimals= 0; return FALSE; } @@ -1769,7 +1769,7 @@ public: {} bool fix_length_and_dec() { - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); max_length= MAX_BLOB_WIDTH; return FALSE; } @@ -1812,7 +1812,7 @@ public: {collation.set(DYNCOL_UTF);} bool fix_length_and_dec() { - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); max_length= MAX_BLOB_WIDTH; return FALSE; } @@ -1856,7 +1856,7 @@ public: bool fix_length_and_dec() { max_length= WSREP_GTID_STR_LEN; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } Item *get_copy(THD *thd) @@ -1873,7 +1873,7 @@ public: bool fix_length_and_dec() { max_length= WSREP_GTID_STR_LEN; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } Item *get_copy(THD *thd) diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index bab4ed9b94b..d6e852215e4 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -67,7 +67,7 @@ Item_subselect::Item_subselect(THD *thd_arg): #ifndef DBUG_OFF exec_counter= 0; #endif - flags|= ITEM_FLAG_WITH_SUBQUERY; + with_flags|= item_with_t::SUBQUERY; reset(); /* Item value is NULL if select_result_interceptor didn't change this value @@ -346,7 +346,7 @@ bool Item_subselect::fix_fields(THD *thd_param, Item **ref) if (uncacheable & UNCACHEABLE_RAND) used_tables_cache|= RAND_TABLE_BIT; } - flags|= ITEM_FLAG_FIXED; + base_flags|= item_base_t::FIXED; end: done_first_fix_fields= FALSE; @@ -1117,7 +1117,7 @@ Item_singlerow_subselect::Item_singlerow_subselect(THD *thd, st_select_lex *sele { DBUG_ENTER("Item_singlerow_subselect::Item_singlerow_subselect"); init(select_lex, new (thd->mem_root) select_singlerow_subselect(thd, this)); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); max_columns= UINT_MAX; DBUG_VOID_RETURN; } @@ -1154,7 +1154,7 @@ Item_maxmin_subselect::Item_maxmin_subselect(THD *thd, new (thd->mem_root) select_max_min_finder_subselect(thd, this, max_arg, parent->substype() == Item_subselect::ALL_SUBS)); max_columns= 1; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); max_columns= 1; /* @@ -1342,7 +1342,7 @@ bool Item_singlerow_subselect::fix_length_and_dec() else { for (uint i= 0; i < max_columns; i++) - row[i]->flags|= ITEM_FLAG_MAYBE_NULL; + row[i]->set_maybe_null(); } return FALSE; } @@ -1589,7 +1589,7 @@ Item_exists_subselect::Item_exists_subselect(THD *thd, init(select_lex, new (thd->mem_root) select_exists_subselect(thd, this)); max_columns= UINT_MAX; null_value= FALSE; //can't be NULL - flags&= (item_flags_t) ~ITEM_FLAG_MAYBE_NULL; //can't be NULL + base_flags&= ~item_base_t::MAYBE_NULL; //can't be NULL value= 0; DBUG_VOID_RETURN; } @@ -1638,7 +1638,7 @@ Item_in_subselect::Item_in_subselect(THD *thd, Item * left_exp, func= &eq_creator; init(select_lex, new (thd->mem_root) select_exists_subselect(thd, this)); max_columns= UINT_MAX; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); reset(); //if test_limit will fail then error will be reported to client test_limit(select_lex->master_unit()); @@ -3541,7 +3541,7 @@ bool Item_in_subselect::fix_fields(THD *thd_arg, Item **ref) else if (Item_subselect::fix_fields(thd_arg, ref)) goto err; - flags|= ITEM_FLAG_FIXED; + base_flags|= item_base_t::FIXED; thd->where= save_where; DBUG_RETURN(FALSE); diff --git a/sql/item_sum.cc b/sql/item_sum.cc index a3d15db4e5e..1bf1f986a2a 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -407,7 +407,7 @@ bool Item_sum::register_sum_func(THD *thd, Item **ref) for (sl= thd->lex->current_select; sl && sl != aggr_sel && sl->master_unit()->item; sl= sl->master_unit()->outer_select() ) - sl->master_unit()->item->flags|= ITEM_FLAG_WITH_SUM_FUNC; + sl->master_unit()->item->with_flags|= item_with_t::SUM_FUNC; } thd->lex->current_select->mark_as_dependent(thd, aggr_sel, NULL); @@ -488,7 +488,7 @@ void Item_sum::mark_as_sum_func() cur_select->n_sum_items++; cur_select->with_sum_func= 1; const_item_cache= false; - flags= (flags | ITEM_FLAG_WITH_SUM_FUNC) & ~ITEM_FLAG_WITH_FIELD; + with_flags= (with_flags | item_with_t::SUM_FUNC) & ~item_with_t::FIELD; window_func_sum_expr_flag= false; } @@ -892,7 +892,7 @@ bool Aggregator_distinct::setup(THD *thd) */ item_sum->null_value= 1; - item_sum->flags|= ITEM_FLAG_MAYBE_NULL; + item_sum->set_maybe_null(); item_sum->quick_group= 0; DBUG_ASSERT(item_sum->get_arg(0)->fixed()); @@ -1125,9 +1125,8 @@ Item_sum_num::fix_fields(THD *thd, Item **ref) if (args[i]->fix_fields_if_needed_for_scalar(thd, &args[i])) return TRUE; set_if_bigger(decimals, args[i]->decimals); - flags|= (args[i]->flags & (ITEM_FLAG_WITH_SUBQUERY | - ITEM_FLAG_WITH_PARAM | - ITEM_FLAG_WITH_WINDOW_FUNC)); + /* We should ignore FIELD's in arguments to sum functions */ + with_flags|= (args[i]->with_flags & ~item_with_t::FIELD); } result_field=0; max_length=float_length(decimals); @@ -1138,7 +1137,7 @@ Item_sum_num::fix_fields(THD *thd, Item **ref) if (arg_count) memcpy (orig_args, args, sizeof (Item *) * arg_count); - flags|= ITEM_FLAG_FIXED; + base_flags|= item_base_t::FIXED; return FALSE; } @@ -1156,10 +1155,8 @@ Item_sum_min_max::fix_fields(THD *thd, Item **ref) if (args[0]->fix_fields_if_needed_for_scalar(thd, &args[0])) DBUG_RETURN(TRUE); - flags|= (args[0]->flags & (ITEM_FLAG_WITH_SUBQUERY | - ITEM_FLAG_WITH_PARAM | - ITEM_FLAG_WITH_WINDOW_FUNC)); - + /* We should ignore FIELD's in arguments to sum functions */ + with_flags|= (args[0]->with_flags & ~item_with_t::FIELD); if (fix_length_and_dec()) DBUG_RETURN(TRUE); @@ -1171,7 +1168,7 @@ Item_sum_min_max::fix_fields(THD *thd, Item **ref) DBUG_RETURN(TRUE); orig_args[0]= args[0]; - flags|= ITEM_FLAG_FIXED; + base_flags|= item_base_t::FIXED; DBUG_RETURN(FALSE); } @@ -1241,7 +1238,7 @@ bool Item_sum_min_max::fix_length_and_dec() DBUG_ASSERT(args[0]->field_type() == args[0]->real_item()->field_type()); DBUG_ASSERT(args[0]->result_type() == args[0]->real_item()->result_type()); /* MIN/MAX can return NULL for empty set indepedent of the used column */ - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); null_value= true; return args[0]->type_handler()->Item_sum_hybrid_fix_length_and_dec(this); } @@ -1313,7 +1310,7 @@ Item_sum_sp::Item_sum_sp(THD *thd, Name_resolution_context *context_arg, sp_name *name_arg, sp_head *sp, List<Item> &list) :Item_sum(thd, list), Item_sp(thd, context_arg, name_arg) { - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); quick_group= 0; m_sp= sp; } @@ -1322,7 +1319,7 @@ Item_sum_sp::Item_sum_sp(THD *thd, Name_resolution_context *context_arg, sp_name *name_arg, sp_head *sp) :Item_sum(thd), Item_sp(thd, context_arg, name_arg) { - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); quick_group= 0; m_sp= sp; } @@ -1330,7 +1327,7 @@ Item_sum_sp::Item_sum_sp(THD *thd, Name_resolution_context *context_arg, Item_sum_sp::Item_sum_sp(THD *thd, Item_sum_sp *item): Item_sum(thd, item), Item_sp(thd, item) { - flags|= (item->flags & ITEM_FLAG_MAYBE_NULL); + base_flags|= (item->base_flags & item_base_t::MAYBE_NULL); quick_group= item->quick_group; } @@ -1359,8 +1356,8 @@ Item_sum_sp::fix_fields(THD *thd, Item **ref) if (args[i]->fix_fields_if_needed_for_scalar(thd, &args[i])) return TRUE; set_if_bigger(decimals, args[i]->decimals); - flags|= (args[i]->flags & (ITEM_FLAG_WITH_SUBQUERY | - ITEM_FLAG_WITH_WINDOW_FUNC)); + /* We should ignore FIELD's in arguments to sum functions */ + with_flags|= (args[i]->with_flags & ~item_with_t::FIELD); } result_field= NULL; max_length= float_length(decimals); @@ -1373,7 +1370,7 @@ Item_sum_sp::fix_fields(THD *thd, Item **ref) if (arg_count) memcpy(orig_args, args, sizeof(Item *) * arg_count); - flags|= ITEM_FLAG_FIXED; + base_flags|= item_base_t::FIXED; return FALSE; } @@ -1557,7 +1554,7 @@ void Item_sum_sum::fix_length_and_dec_decimal() bool Item_sum_sum::fix_length_and_dec() { DBUG_ENTER("Item_sum_sum::fix_length_and_dec"); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); null_value=1; if (args[0]->cast_to_int_type_handler()-> Item_sum_sum_fix_length_and_dec(this)) @@ -1980,7 +1977,7 @@ bool Item_sum_avg::fix_length_and_dec() { DBUG_ENTER("Item_sum_avg::fix_length_and_dec"); prec_increment= current_thd->variables.div_precincrement; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); null_value=1; if (args[0]->cast_to_int_type_handler()-> Item_sum_avg_fix_length_and_dec(this)) @@ -2211,7 +2208,7 @@ void Item_sum_variance::fix_length_and_dec_decimal() bool Item_sum_variance::fix_length_and_dec() { DBUG_ENTER("Item_sum_variance::fix_length_and_dec"); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); null_value= 1; prec_increment= current_thd->variables.div_precincrement; @@ -4224,7 +4221,7 @@ Item_func_group_concat::fix_fields(THD *thd, Item **ref) if (init_sum_func_check(thd)) return TRUE; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); /* Fix fields for select list and ORDER clause @@ -4234,9 +4231,8 @@ Item_func_group_concat::fix_fields(THD *thd, Item **ref) { if (args[i]->fix_fields_if_needed_for_scalar(thd, &args[i])) return TRUE; - flags|= (args[i]->flags & (ITEM_FLAG_WITH_SUBQUERY | - ITEM_FLAG_WITH_PARAM | - ITEM_FLAG_WITH_WINDOW_FUNC)); + /* We should ignore FIELD's in arguments to sum functions */ + with_flags|= (args[i]->with_flags & ~item_with_t::FIELD); } /* skip charset aggregation for order columns */ @@ -4275,7 +4271,7 @@ Item_func_group_concat::fix_fields(THD *thd, Item **ref) if (check_sum_func(thd, ref)) return TRUE; - flags|= ITEM_FLAG_FIXED; + base_flags|= item_base_t::FIXED; return FALSE; } diff --git a/sql/item_sum.h b/sql/item_sum.h index 02da520048b..14672af6ef6 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -463,7 +463,7 @@ public: virtual void update_field()=0; virtual bool fix_length_and_dec() { - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); null_value=1; return FALSE; } @@ -786,7 +786,7 @@ public: { decimals=0; max_length=21; - flags&= (item_flags_t) ~ITEM_FLAG_MAYBE_NULL; + base_flags&= ~item_base_t::MAYBE_NULL; null_value=0; return FALSE; } }; @@ -1219,7 +1219,7 @@ public: if (args[0]->check_type_can_return_int(func_name())) return true; decimals= 0; max_length=21; unsigned_flag= 1; - flags&= (item_flags_t) ~ITEM_FLAG_MAYBE_NULL; + base_flags&= ~item_base_t::MAYBE_NULL; null_value= 0; return FALSE; } @@ -1470,7 +1470,7 @@ public: :Item(thd), field(item->result_field) { name= item->name; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); decimals= item->decimals; max_length= item->max_length; unsigned_flag= item->unsigned_flag; @@ -1614,7 +1614,7 @@ public: if (init_sum_func_check(thd)) return TRUE; - flags|= ITEM_FLAG_FIXED; + base_flags|= item_base_t::FIXED; /* We set const_item_cache to false in constructors. It can be later changed to "true", in a Item_sum::make_const() call. @@ -1846,7 +1846,8 @@ public: { DBUG_ASSERT(fixed()); null_value=1; return 0; } double val_real() { DBUG_ASSERT(fixed()); null_value=1; return 0.0; } longlong val_int() { DBUG_ASSERT(fixed()); null_value=1; return 0; } - bool fix_length_and_dec() { flags|= ITEM_FLAG_MAYBE_NULL; max_length=0; return FALSE; } + bool fix_length_and_dec() override + { base_flags|= item_base_t::MAYBE_NULL; max_length=0; return FALSE; } enum Sumfunctype sum_func () const { return UDF_SUM_FUNC; } void clear() {} bool add() { return 0; } diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 031866798ef..96d7daf9c63 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -980,7 +980,7 @@ bool Item_func_monthname::fix_length_and_dec() collation.set(cs, DERIVATION_COERCIBLE, locale->repertoire()); decimals=0; max_length= locale->max_month_name_length * collation.collation->mbmaxlen; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } @@ -1125,7 +1125,7 @@ bool Item_func_dayname::fix_length_and_dec() collation.set(cs, DERIVATION_COERCIBLE, locale->repertoire()); decimals=0; max_length= locale->max_day_name_length * collation.collation->mbmaxlen; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } @@ -1774,7 +1774,7 @@ bool Item_func_date_format::fix_length_and_dec() collation.collation->mbmaxlen; set_if_smaller(max_length,MAX_BLOB_WIDTH); } - flags|= ITEM_FLAG_MAYBE_NULL; // If wrong date + set_maybe_null(); // If wrong date return FALSE; } @@ -1937,7 +1937,7 @@ bool Item_func_from_unixtime::fix_length_and_dec() Type_temporal_attributes_not_fixed_dec(MAX_DATETIME_WIDTH, args[0]->decimals, false), DTCollation_numeric()); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } @@ -2064,7 +2064,7 @@ bool Item_date_add_interval::fix_length_and_dec() { set_func_handler(&func_handler_date_add_interval_string); } - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return m_func_handler->fix_length_and_dec(this); } @@ -2141,7 +2141,7 @@ bool Item_extract::check_arguments() const bool Item_extract::fix_length_and_dec() { - flags|= ITEM_FLAG_MAYBE_NULL; // If wrong date + set_maybe_null(); // If wrong date uint32 daylen= args[0]->cmp_type() == TIME_RESULT ? 2 : TIME_MAX_INTERVAL_DAY_CHAR_LENGTH; switch (int_type) { @@ -2504,7 +2504,8 @@ Item_char_typecast::fix_length_and_dec_native_to_binary(uint32 octet_length) { collation.set(&my_charset_bin, DERIVATION_IMPLICIT); max_length= has_explicit_length() ? (uint32) cast_length : octet_length; - flags|= (current_thd->is_strict_mode() ? ITEM_FLAG_MAYBE_NULL : 0); + if (current_thd->is_strict_mode()) + set_maybe_null(); } @@ -2549,7 +2550,8 @@ void Item_char_typecast::fix_length_and_dec_internal(CHARSET_INFO *from_cs) args[0]->collation.collation->mbmaxlen)); max_length= char_length * cast_cs->mbmaxlen; // Add NULL-ability in strict mode. See Item_str_func::fix_fields() - flags|= (current_thd->is_strict_mode() ? ITEM_FLAG_MAYBE_NULL : 0); + if (current_thd->is_strict_mode()) + set_maybe_null(); } @@ -2673,7 +2675,7 @@ bool Item_func_add_time::fix_length_and_dec() &func_handler_add_time_string_sub); } - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return m_func_handler->fix_length_and_dec(this); } @@ -3059,7 +3061,7 @@ bool Item_func_str_to_date::fix_length_and_dec() if (collation.collation->mbminlen > 1) internal_charset= &my_charset_utf8mb4_general_ci; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); set_func_handler(&func_handler_str_to_date_datetime_usec); if ((const_item= args[1]->const_item())) diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index 26501dbd077..c717a7bde98 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -97,7 +97,7 @@ public: { decimals=0; max_length=6*MY_CHARSET_BIN_MB_MAXLEN; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } enum_monotonicity_info get_monotonicity_info() const; @@ -125,7 +125,7 @@ public: { decimals=0; fix_char_length(12); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } enum_monotonicity_info get_monotonicity_info() const; @@ -152,7 +152,7 @@ public: { decimals=0; max_length=2*MY_CHARSET_BIN_MB_MAXLEN; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } bool check_partition_func_processor(void *int_arg) {return FALSE;} @@ -177,7 +177,7 @@ public: { decimals= 0; fix_char_length(2); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } bool check_partition_func_processor(void *int_arg) {return FALSE;} @@ -223,7 +223,7 @@ public: { decimals= 0; fix_char_length(3); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } bool check_partition_func_processor(void *int_arg) {return FALSE;} @@ -247,7 +247,7 @@ public: { decimals=0; max_length=2*MY_CHARSET_BIN_MB_MAXLEN; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } bool check_partition_func_processor(void *int_arg) {return FALSE;} @@ -271,7 +271,7 @@ public: { decimals=0; max_length=2*MY_CHARSET_BIN_MB_MAXLEN; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } bool check_partition_func_processor(void *int_arg) {return FALSE;} @@ -295,7 +295,7 @@ public: { decimals=0; max_length=1*MY_CHARSET_BIN_MB_MAXLEN; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } bool check_partition_func_processor(void *int_arg) {return FALSE;} @@ -319,7 +319,7 @@ public: { decimals=0; max_length=2*MY_CHARSET_BIN_MB_MAXLEN; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } bool check_partition_func_processor(void *int_arg) {return FALSE;} @@ -349,7 +349,7 @@ public: { decimals=0; max_length=2*MY_CHARSET_BIN_MB_MAXLEN; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } bool check_vcol_func_processor(void *arg) @@ -382,7 +382,7 @@ public: { decimals=0; max_length=6*MY_CHARSET_BIN_MB_MAXLEN; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } bool check_partition_func_processor(void *int_arg) {return FALSE;} @@ -408,7 +408,7 @@ public: { decimals=0; max_length=4*MY_CHARSET_BIN_MB_MAXLEN; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } bool check_partition_func_processor(void *int_arg) {return FALSE;} @@ -441,7 +441,7 @@ public: { decimals= 0; fix_char_length(1); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } bool check_partition_func_processor(void *int_arg) {return FALSE;} @@ -487,7 +487,7 @@ public: DBUG_ASSERT(dec <= TIME_SECOND_PART_DIGITS); decimals= dec; max_length=17 + (decimals ? decimals + 1 : 0); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); if (decimals) set_handler(&type_handler_newdecimal); else @@ -906,7 +906,7 @@ class Item_func_convert_tz :public Item_datetimefunc bool fix_length_and_dec() { fix_attributes_datetime(args[0]->datetime_precision(current_thd)); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate); @@ -926,7 +926,7 @@ public: bool fix_length_and_dec() { fix_attributes_time(args[0]->decimals); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } const char *func_name() const { return "sec_to_time"; } @@ -1214,7 +1214,7 @@ public: uint dec0= args[0]->datetime_precision(thd); uint dec1= Interval_DDhhmmssff::fsp(thd, args[1]); fix_attributes_datetime(MY_MAX(dec0, dec1)); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return false; } bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) @@ -1274,7 +1274,7 @@ public: uint dec= MY_MAX(args[0]->time_precision(thd), args[1]->time_precision(thd)); fix_attributes_time(dec); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate); @@ -1296,7 +1296,7 @@ public: bool fix_length_and_dec() { fix_attributes_time(args[2]->decimals); - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } const char *func_name() const { return "maketime"; } @@ -1315,7 +1315,7 @@ public: bool fix_length_and_dec() { decimals=0; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); fix_char_length(6); return FALSE; } @@ -1346,7 +1346,7 @@ public: bool fix_length_and_dec() { decimals=0; - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); return FALSE; } virtual void print(String *str, enum_query_type query_type); @@ -1371,7 +1371,7 @@ public: const char *func_name() const { return "get_format"; } bool fix_length_and_dec() { - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); decimals=0; fix_length_and_charset(17, default_charset()); return FALSE; diff --git a/sql/item_vers.h b/sql/item_vers.h index 2981c56aac1..e6cfe652029 100644 --- a/sql/item_vers.h +++ b/sql/item_vers.h @@ -40,7 +40,7 @@ public: } bool fix_length_and_dec() { - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); null_value= 0; decimals= 0; max_length= 1; diff --git a/sql/item_windowfunc.cc b/sql/item_windowfunc.cc index cdf8ebf9879..262481d019b 100644 --- a/sql/item_windowfunc.cc +++ b/sql/item_windowfunc.cc @@ -120,7 +120,7 @@ Item_window_func::fix_fields(THD *thd, Item **ref) const_item_cache= false; - flags= (flags & ~ITEM_FLAG_WITH_SUM_FUNC) | ITEM_FLAG_WITH_WINDOW_FUNC; + with_flags= (with_flags & ~item_with_t::SUM_FUNC) | item_with_t::WINDOW_FUNC; if (fix_length_and_dec()) return TRUE; @@ -128,7 +128,7 @@ Item_window_func::fix_fields(THD *thd, Item **ref) max_length= window_func()->max_length; set_maybe_null(window_func()->maybe_null()); - flags|= ITEM_FLAG_FIXED; + base_flags|= item_base_t::FIXED; set_phase_to_initial(); return false; } @@ -344,8 +344,7 @@ bool Item_sum_hybrid_simple::fix_fields(THD *thd, Item **ref) { if (args[i]->fix_fields_if_needed_for_scalar(thd, &args[i])) return TRUE; - flags|= (args[i]->flags & (ITEM_FLAG_WITH_WINDOW_FUNC | - ITEM_FLAG_WITH_SUBQUERY)); + with_flags|= args[i]->with_flags; } if (fix_length_and_dec()) @@ -359,14 +358,14 @@ bool Item_sum_hybrid_simple::fix_fields(THD *thd, Item **ref) for (uint i= 0; i < arg_count; i++) orig_args[i]= args[i]; - flags|= ITEM_FLAG_FIXED; + base_flags|= item_base_t::FIXED; return FALSE; } bool Item_sum_hybrid_simple::fix_length_and_dec() { - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); null_value= true; return args[0]->type_handler()->Item_sum_hybrid_fix_length_and_dec(this); } diff --git a/sql/item_xmlfunc.h b/sql/item_xmlfunc.h index 3369304d79c..1d2b6e70995 100644 --- a/sql/item_xmlfunc.h +++ b/sql/item_xmlfunc.h @@ -110,12 +110,12 @@ protected: public: Item_xml_str_func(THD *thd, Item *a, Item *b): Item_str_func(thd, a, b) { - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); } Item_xml_str_func(THD *thd, Item *a, Item *b, Item *c): Item_str_func(thd, a, b, c) { - flags|= ITEM_FLAG_MAYBE_NULL; + set_maybe_null(); } bool fix_fields(THD *thd, Item **ref); bool fix_length_and_dec(); diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index b850e88ac6d..859ee5f16ff 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -966,7 +966,7 @@ bool make_in_exists_conversion(THD *thd, JOIN *join, Item_in_subselect *item) call. */ item->changed= 0; - item->flags|= ITEM_FLAG_FIXED; + item->base_flags|= item_base_t::FIXED; SELECT_LEX *save_select_lex= thd->lex->current_select; thd->lex->current_select= item->unit->first_select(); @@ -1318,7 +1318,7 @@ bool convert_join_subqueries_to_semijoins(JOIN *join) { JOIN *child_join= in_subq->unit->first_select()->join; in_subq->changed= 0; - in_subq->flags|= ITEM_FLAG_FIXED; + in_subq->base_flags|= item_base_t::FIXED; SELECT_LEX *save_select_lex= thd->lex->current_select; thd->lex->current_select= in_subq->unit->first_select(); diff --git a/sql/sp_head.cc b/sql/sp_head.cc index 980bf4eaf10..c4e08bb9606 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -2994,7 +2994,7 @@ sp_head::show_create_routine_get_fields(THD *thd, const Sp_handler *sph, Item_empty_string *stmt_fld= new (mem_root) Item_empty_string(thd, col3_caption, 1024); - stmt_fld->flags|= ITEM_FLAG_MAYBE_NULL; + stmt_fld->set_maybe_null(); fields->push_back(stmt_fld, mem_root); } @@ -3070,7 +3070,7 @@ sp_head::show_create_routine(THD *thd, const Sp_handler *sph) new (mem_root) Item_empty_string(thd, col3_caption, (uint)MY_MAX(m_defstr.length, 1024)); - stmt_fld->flags|= ITEM_FLAG_MAYBE_NULL; + stmt_fld->set_maybe_null(); fields.push_back(stmt_fld, thd->mem_root); } diff --git a/sql/sql_admin.cc b/sql/sql_admin.cc index e660f72ab66..ba5809c6835 100644 --- a/sql/sql_admin.cc +++ b/sql/sql_admin.cc @@ -510,18 +510,18 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, field_list.push_back(item= new (thd->mem_root) Item_empty_string(thd, "Table", NAME_CHAR_LEN * 2), thd->mem_root); - item->flags|= ITEM_FLAG_MAYBE_NULL; + item->set_maybe_null(); field_list.push_back(item= new (thd->mem_root) Item_empty_string(thd, "Op", 10), thd->mem_root); - item->flags|= ITEM_FLAG_MAYBE_NULL; + item->set_maybe_null(); field_list.push_back(item= new (thd->mem_root) Item_empty_string(thd, "Msg_type", 10), thd->mem_root); - item->flags|= ITEM_FLAG_MAYBE_NULL; + item->set_maybe_null(); field_list.push_back(item= new (thd->mem_root) Item_empty_string(thd, "Msg_text", SQL_ADMIN_MSG_TEXT_SIZE), thd->mem_root); - item->flags|= ITEM_FLAG_MAYBE_NULL; + item->set_maybe_null(); if (protocol->send_result_set_metadata(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) DBUG_RETURN(TRUE); diff --git a/sql/sql_analyse.cc b/sql/sql_analyse.cc index 090fd724873..a6fc7c25e55 100644 --- a/sql/sql_analyse.cc +++ b/sql/sql_analyse.cc @@ -1165,16 +1165,16 @@ bool analyse::change_columns(THD *thd, List<Item> &field_list) func_items[0]= new (mem_root) Item_proc_string(thd, "Field_name", 255); func_items[1]= new (mem_root) Item_proc_string(thd, "Min_value", 255); - func_items[1]->flags|= ITEM_FLAG_MAYBE_NULL; + func_items[1]->set_maybe_null(); func_items[2]= new (mem_root) Item_proc_string(thd, "Max_value", 255); - func_items[2]->flags|= ITEM_FLAG_MAYBE_NULL; + func_items[2]->set_maybe_null(); func_items[3]= new (mem_root) Item_proc_int(thd, "Min_length"); func_items[4]= new (mem_root) Item_proc_int(thd, "Max_length"); func_items[5]= new (mem_root) Item_proc_int(thd, "Empties_or_zeros"); func_items[6]= new (mem_root) Item_proc_int(thd, "Nulls"); func_items[7]= new (mem_root) Item_proc_string(thd, "Avg_value_or_avg_length", 255); func_items[8]= new (mem_root) Item_proc_string(thd, "Std", 255); - func_items[8]->flags|= ITEM_FLAG_MAYBE_NULL; + func_items[8]->set_maybe_null(); func_items[9]= new (mem_root) Item_proc_string(thd, "Optimal_fieldtype", MY_MAX(64, output_str_length)); diff --git a/sql/sql_class.cc b/sql/sql_class.cc index aa621d4b7f1..59e40298b97 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -2711,45 +2711,45 @@ void THD::make_explain_field_list(List<Item> &field_list, uint8 explain_flags, field_list.push_back(item= new (mem_root) Item_return_int(this, "id", 3, MYSQL_TYPE_LONGLONG), mem_root); - item->flags|= ITEM_FLAG_MAYBE_NULL; + item->set_maybe_null(); field_list.push_back(new (mem_root) Item_empty_string(this, "select_type", 19, cs), mem_root); field_list.push_back(item= new (mem_root) Item_empty_string(this, "table", NAME_CHAR_LEN, cs), mem_root); - item->flags|= ITEM_FLAG_MAYBE_NULL; + item->set_maybe_null(); if (explain_flags & DESCRIBE_PARTITIONS) { /* Maximum length of string that make_used_partitions_str() can produce */ item= new (mem_root) Item_empty_string(this, "partitions", MAX_PARTITIONS * (1 + FN_LEN), cs); field_list.push_back(item, mem_root); - item->flags|= ITEM_FLAG_MAYBE_NULL; + item->set_maybe_null(); } field_list.push_back(item= new (mem_root) Item_empty_string(this, "type", 10, cs), mem_root); - item->flags|= ITEM_FLAG_MAYBE_NULL; + item->set_maybe_null(); field_list.push_back(item= new (mem_root) Item_empty_string(this, "possible_keys", NAME_CHAR_LEN*MAX_KEY, cs), mem_root); - item->flags|= ITEM_FLAG_MAYBE_NULL; + item->set_maybe_null(); field_list.push_back(item=new (mem_root) Item_empty_string(this, "key", NAME_CHAR_LEN, cs), mem_root); - item->flags|= ITEM_FLAG_MAYBE_NULL; + item->set_maybe_null(); field_list.push_back(item=new (mem_root) Item_empty_string(this, "key_len", NAME_CHAR_LEN*MAX_KEY), mem_root); - item->flags|= ITEM_FLAG_MAYBE_NULL; + item->set_maybe_null(); field_list.push_back(item=new (mem_root) Item_empty_string(this, "ref", NAME_CHAR_LEN*MAX_REF_PARTS, cs), mem_root); - item->flags|= ITEM_FLAG_MAYBE_NULL; + item->set_maybe_null(); field_list.push_back(item=new (mem_root) Item_empty_string(this, "rows", NAME_CHAR_LEN, cs), mem_root); @@ -2758,7 +2758,7 @@ void THD::make_explain_field_list(List<Item> &field_list, uint8 explain_flags, field_list.push_back(item= new (mem_root) Item_empty_string(this, "r_rows", NAME_CHAR_LEN, cs), mem_root); - item->flags|= ITEM_FLAG_MAYBE_NULL; + item->set_maybe_null(); } if (is_analyze || (explain_flags & DESCRIBE_EXTENDED)) @@ -2766,7 +2766,7 @@ void THD::make_explain_field_list(List<Item> &field_list, uint8 explain_flags, field_list.push_back(item= new (mem_root) Item_float(this, "filtered", 0.1234, 2, 4), mem_root); - item->flags|= ITEM_FLAG_MAYBE_NULL; + item->set_maybe_null(); } if (is_analyze) @@ -2774,10 +2774,10 @@ void THD::make_explain_field_list(List<Item> &field_list, uint8 explain_flags, field_list.push_back(item= new (mem_root) Item_float(this, "r_filtered", 0.1234, 2, 4), mem_root); - item->flags|= ITEM_FLAG_MAYBE_NULL; + item->set_maybe_null(); } - item->flags|= ITEM_FLAG_MAYBE_NULL; + item->set_maybe_null(); field_list.push_back(new (mem_root) Item_empty_string(this, "Extra", 255, cs), mem_root); diff --git a/sql/sql_cte.cc b/sql/sql_cte.cc index 6f62a38b231..aed37df9c42 100644 --- a/sql/sql_cte.cc +++ b/sql/sql_cte.cc @@ -993,7 +993,7 @@ With_element::process_columns_of_derived_unit(THD *thd, while ((item= it++, name= nm++)) { item->set_name(thd, *name); - item->flags&= ~ITEM_FLAG_IS_AUTOGENERATED_NAME; + item->base_flags&= ~item_base_t::IS_AUTOGENERATED_NAME; } if (arena) @@ -1036,7 +1036,7 @@ With_element::process_columns_of_derived_unit(THD *thd, my_error(ER_BAD_FIELD_ERROR, MYF(0), name->str, "CYCLE clause"); return true; } - item->flags|= ITEM_FLAG_IS_IN_WITH_CYCLE; + item->base_flags|= item_base_t::IS_IN_WITH_CYCLE; } } unit->columns_are_renamed= true; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 0a7a981a73e..ef44b20308b 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -18731,7 +18731,7 @@ bool Create_tmp_table::add_fields(THD *thd, new_field->maybe_null() is still false, it will be changed below. But we have to setup Item_field correctly */ - arg->flags|= ITEM_FLAG_MAYBE_NULL; + arg->set_maybe_null(); } if (current_counter == distinct) new_field->flags|= FIELD_PART_OF_TMP_UNIQUE; @@ -19133,7 +19133,7 @@ bool Create_tmp_table::finalize(THD *thd, that the key,field and item definition match. */ maybe_null= 0; - (*cur_group->item)->flags&= (Item::item_flags_t) ~ITEM_FLAG_MAYBE_NULL; + (*cur_group->item)->base_flags&= ~item_base_t::MAYBE_NULL; } if (!(cur_group->field= field->new_key_field(thd->mem_root,table, @@ -25119,7 +25119,7 @@ count_field_types(SELECT_LEX *select_lex, TMP_TABLE_PARAM *param, { param->func_count++; if (reset_with_sum_func) - field->flags&= ~ITEM_FLAG_WITH_SUM_FUNC; + field->with_flags&= ~item_with_t::SUM_FUNC; } } } @@ -26192,7 +26192,7 @@ static bool change_group_ref(THD *thd, Item_func *expr, ORDER *group_list, } if (arg_changed) { - expr->flags|= ITEM_FLAG_MAYBE_NULL | ITEM_FLAG_IN_ROLLUP; + expr->base_flags|= item_base_t::MAYBE_NULL | item_base_t::IN_ROLLUP; *changed= TRUE; } } @@ -26263,7 +26263,7 @@ bool JOIN::rollup_init() { if (*group_tmp->item == item) { - item->flags|= ITEM_FLAG_MAYBE_NULL | ITEM_FLAG_IN_ROLLUP; + item->base_flags|= item_base_t::MAYBE_NULL | item_base_t::IN_ROLLUP; found_in_group= 1; break; } @@ -26279,7 +26279,7 @@ bool JOIN::rollup_init() Marking the expression item as 'with_sum_func' will ensure this. */ if (changed) - item->flags|= ITEM_FLAG_WITH_SUM_FUNC; + item->with_flags|= item_with_t::SUM_FUNC; } } return 0; @@ -26449,7 +26449,8 @@ bool JOIN::rollup_make_fields(List<Item> &fields_arg, List<Item> &sel_fields, Item_null_result *null_item= new (thd->mem_root) Item_null_result(thd); if (!null_item) return 1; - item->flags|= ITEM_FLAG_MAYBE_NULL; // Value will be null sometimes + // Value will be null sometimes + item->set_maybe_null(); null_item->result_field= item->get_tmp_table_field(); item= null_item; break; diff --git a/sql/sql_show.cc b/sql/sql_show.cc index c5084c4dff4..f1e08222359 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -2865,7 +2865,7 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose) field_list.push_back(field=new (mem_root) Item_empty_string(thd, "db", NAME_CHAR_LEN), mem_root); - field->flags|= ITEM_FLAG_MAYBE_NULL;; + field->set_maybe_null();; field_list.push_back(new (mem_root) Item_empty_string(thd, "Command", 16), mem_root); field_list.push_back(field= new (mem_root) @@ -2875,18 +2875,18 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose) field_list.push_back(field=new (mem_root) Item_empty_string(thd, "State", 30), mem_root); - field->flags|= ITEM_FLAG_MAYBE_NULL;; + field->set_maybe_null();; field_list.push_back(field=new (mem_root) Item_empty_string(thd, "Info", arg.max_query_length), mem_root); - field->flags|= ITEM_FLAG_MAYBE_NULL;; + field->set_maybe_null();; if (!thd->variables.old_mode && !(thd->variables.old_behavior & OLD_MODE_NO_PROGRESS_INFO)) { field_list.push_back(field= new (mem_root) Item_float(thd, "Progress", 0.0, 3, 7), mem_root); - field->flags&= (Item::item_flags_t) ~ITEM_FLAG_MAYBE_NULL; + field->base_flags&= ~item_base_t::MAYBE_NULL; } if (protocol->send_result_set_metadata(&field_list, Protocol::SEND_NUM_ROWS | @@ -9767,7 +9767,7 @@ static bool show_create_trigger_impl(THD *thd, Trigger *trigger) (uint)MY_MAX(trg_sql_original_stmt.length, 1024)); - stmt_fld->flags|= ITEM_FLAG_MAYBE_NULL; + stmt_fld->set_maybe_null(); fields.push_back(stmt_fld, mem_root); } diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 81c599f24cb..794b46217c5 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -11816,12 +11816,12 @@ bool mysql_checksum_table(THD *thd, TABLE_LIST *tables, field_list.push_back(item= new (thd->mem_root) Item_empty_string(thd, "Table", NAME_LEN*2), thd->mem_root); - item->flags|= ITEM_FLAG_MAYBE_NULL; + item->set_maybe_null(); field_list.push_back(item= new (thd->mem_root) Item_int(thd, "Checksum", (longlong) 1, MY_INT64_NUM_DECIMAL_DIGITS), thd->mem_root); - item->flags|= ITEM_FLAG_MAYBE_NULL; + item->set_maybe_null(); if (protocol->send_result_set_metadata(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) DBUG_RETURN(TRUE); diff --git a/sql/sql_type.cc b/sql/sql_type.cc index 760dc5ed68f..af046817add 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -4792,7 +4792,8 @@ bool Type_handler_temporal_result:: continue; // No conversion. if (ha->cmp_type() != TIME_RESULT) { - func->flags|= ITEM_FLAG_MAYBE_NULL; // Conversion from non-temporal is not safe + // Conversion from non-temporal is not safe + func->set_maybe_null(); break; } timestamp_type tf= hf->mysql_timestamp_type(); @@ -4843,7 +4844,7 @@ bool Type_handler_temporal_result:: DBUG_ASSERT(hf->field_type() == MYSQL_TYPE_DATETIME); if (!(thd->variables.old_behavior & OLD_MODE_ZERO_DATE_TIME_CAST)) continue; - func->flags|= ITEM_FLAG_MAYBE_NULL; + func->set_maybe_null(); break; } return rc; @@ -4867,7 +4868,7 @@ bool Type_handler_date_common:: { if (items[i]->type_handler()->cmp_type() != TIME_RESULT) { - func->flags|= ITEM_FLAG_MAYBE_NULL; + func->set_maybe_null(); break; } } @@ -6749,7 +6750,7 @@ bool Type_handler:: item->arguments()[0]->time_precision(current_thd) : item->decimals; item->fix_attributes_temporal(MIN_TIME_WIDTH, dec); - item->flags|= ITEM_FLAG_MAYBE_NULL; + item->set_maybe_null(); return false; } @@ -6758,7 +6759,7 @@ bool Type_handler:: Item_date_typecast_fix_length_and_dec(Item_date_typecast *item) const { item->fix_attributes_temporal(MAX_DATE_WIDTH, 0); - item->flags|= ITEM_FLAG_MAYBE_NULL; + item->set_maybe_null(); return false; } @@ -6771,7 +6772,7 @@ bool Type_handler:: item->arguments()[0]->datetime_precision(current_thd) : item->decimals; item->fix_attributes_temporal(MAX_DATETIME_WIDTH, dec); - item->flags|= ITEM_FLAG_MAYBE_NULL; + item->set_maybe_null(); return false; } diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 11ee44d5c5f..ee698e51243 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -137,7 +137,7 @@ bool check_duplicate_names(THD *thd, List<Item> &item_list, bool gen_unique_view Item *check; /* treat underlying fields like set by user names */ if (item->real_item()->type() == Item::FIELD_ITEM) - item->flags&= ~ITEM_FLAG_IS_AUTOGENERATED_NAME; + item->base_flags&= ~item_base_t::IS_AUTOGENERATED_NAME; itc.rewind(); while ((check= itc++) && check != item) { @@ -566,7 +566,7 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, while ((item= it++, name= nm++)) { item->set_name(thd, *name); - item->flags&= ~ITEM_FLAG_IS_AUTOGENERATED_NAME; + item->base_flags&= ~item_base_t::IS_AUTOGENERATED_NAME; } } diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 6e6d73cee0f..35987f08238 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -9223,7 +9223,7 @@ select_item: if (unlikely(Lex->sql_command == SQLCOM_CREATE_VIEW && check_column_name($4.str))) my_yyabort_error((ER_WRONG_COLUMN_NAME, MYF(0), $4.str)); - $2->flags&= ~ITEM_FLAG_IS_AUTOGENERATED_NAME; + $2->base_flags&= ~item_base_t::IS_AUTOGENERATED_NAME; $2->set_name(thd, $4); } else if (!$2->name.str || $2->name.str == item_empty_name) @@ -10801,7 +10801,7 @@ udf_expr: */ if ($4.str) { - $2->flags&= ~ITEM_FLAG_IS_AUTOGENERATED_NAME; + $2->base_flags&= ~item_base_t::IS_AUTOGENERATED_NAME; $2->set_name(thd, $4); } /* diff --git a/sql/table.cc b/sql/table.cc index 39b8a8f1900..570f01efa28 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -6854,7 +6854,7 @@ Item *create_view_field(THD *thd, TABLE_LIST *view, Item **field_ref, views/derived tables. */ if (view->table && view->table->maybe_null) - item->flags|= ITEM_FLAG_MAYBE_NULL; + item->set_maybe_null(); /* Save item in case we will need to fall back to materialization. */ view->used_items.push_front(item, thd->mem_root); /* |