Commit message: MDEV-25635 Assertion failure when pushing from HAVING into WHERE of view

This bug could manifest itself after pushing a where condition over a
mergeable derived table / view / CTE DT into a grouping view / derived
table / CTE V whose item list contained set functions with constant
arguments such as MIN(2), SUM(1) etc. In such cases the field references
used in the condition pushed into the view V that correspond set functions
are wrapped into Item_direct_view_ref wrappers. Due to a wrong implementation
of the virtual method const_item() for the class Item_direct_view_ref the
wrapped set functions with constant arguments could be erroneously taken
for constant items. This could lead to a wrong result set returned by the
main select query in 10.2. In 10.4 where a possibility of pushing condition
from HAVING into WHERE had been added this could cause a crash.

Approved by Sergey Petrunya <sergey.petrunya@mariadb.com>
CVE: CVE-2021-46666
CWE: CWE-617
Vulnerability description: MariaDB before 10.6.2 allows an application crash because of mishandling of a pushdown from a HAVING clause to a WHERE clause.

Project: server

  void cleanup()
  {
    clear();
    Item_basic_constant::cleanup();
  }

Project: server

  Item_copy(THD *thd, Item *i): Item(thd)
  {
    item= i;
    null_value=maybe_null=item->maybe_null;
    Type_std_attributes::set(item);
    name=item->name;
    set_handler_by_field_type(item->field_type());
    fixed= item->fixed;
  }

Project: server

  bool finalize()
  { return copy_up_to(src_len); }

Project: server

  virtual fast_field_copier setup_fast_field_copier(Field *field)
  { return NULL; }

Project: server

    size_t char_length() const { return MY_STRING_METADATA::char_length; }

Project: server

  bool real_eq(double value, const Item *item) const
  {
    DBUG_ASSERT(is_basic_value(REAL_ITEM));
    return is_basic_value(item, REAL_ITEM) &&
           value == ((Item_basic_value*)item)->val_real();
  }

Project: server

  virtual bool check_field_expression_processor(void *arg) { return 0; }

Project: server

  void save_in_result_field(bool no_conversions) { }

Project: server

  Item_date_literal(THD *thd, MYSQL_TIME *ltime)
    :Item_temporal_literal(thd, ltime)
  {
    max_length= MAX_DATE_WIDTH;
    fixed= 1;
    /*
      If date has zero month or day, it can return NULL in case of
      NO_ZERO_DATE or NO_ZERO_IN_DATE.
      We can't just check the current sql_mode here in constructor,
      because sql_mode can change in case of prepared statements
      between PREPARE and EXECUTE.
    */
    maybe_null= !ltime->month || !ltime->day;
  }

Project: server

  Item *get_tmp_table_item(THD *thd) { return this; }

Project: server

  DTCollation(CHARSET_INFO *collation_arg,
              Derivation derivation_arg,
              uint repertoire_arg)
   :collation(collation_arg),
    derivation(derivation_arg),
    repertoire(repertoire_arg)
  { }

Project: server

  longlong val_int_from_real()
  {
    DBUG_ASSERT(fixed == 1);
    return Converter_double_to_longlong_with_warn(val_real(), false).result();
  }

Project: server

  COND *build_equal_items(THD *thd, COND_EQUAL *inherited,
                          bool link_item_fields,
                          COND_EQUAL **cond_equal_ref)
  {
    /*
      normilize_cond() replaced all conditions of type
         WHERE/HAVING field
      to:
        WHERE/HAVING field<>0
      By the time of a build_equal_items() call, all such conditions should
      already be replaced. No Item_ref referencing to Item_field are possible.
    */
    DBUG_ASSERT(real_type() != FIELD_ITEM);
    return Item_ident::build_equal_items(thd, inherited, link_item_fields,
                                         cond_equal_ref);
  }

Project: server

  bool eq(const Item *item, bool binary_cmp) const
  {
    return item->basic_const_item() && item->type() == type() &&
           item->cast_to_int_type() == cast_to_int_type() &&
           str_value.bin_eq(&((Item_hex_constant*)item)->str_value);
  }

Project: server

  virtual void save_result(Field *to) { save_val(to); }

Project: server

  enum Item_result cast_to_int_type() const { return STRING_RESULT; }

Project: server

  table_map not_null_tables() const { return orig_item->not_null_tables(); }

Project: server

  bool check_vcol_func_processor(void *arg)
  {
    return mark_unsupported_function("cache", arg, VCOL_IMPOSSIBLE);
  }

Project: server

  virtual bool exists2in_processor(void *arg) { return 0; }

Project: server

  inline Item **arguments() const { return args; }

Project: server

  void bring_value()
  {
    if (result_type() == ROW_RESULT)
      orig_item->bring_value();
  }

Project: server

  virtual bool update_table_bitmaps_processor(void *arg) { return 0; }

Project: server

  Item_ignore_value(THD *thd, Name_resolution_context *context_arg)
    :Item_default_value(thd, context_arg)
  {};

Project: server

  virtual enum Type real_type() const { return type(); }

Project: server

  Item_direct_ref(THD *thd, TABLE_LIST *view_arg, Item **item,
                  const char *field_name_arg,
                  bool alias_name_used_arg= FALSE):
    Item_ref(thd, view_arg, item, field_name_arg,
             alias_name_used_arg)
  {}

Project: server

  void set_extraction_flag(int flags) 
  { 
    marker &= ~EXTRACTION_MASK;
    marker|= flags; 
  }

Project: server

  Item_hex_string(THD *thd, const char *str, uint str_length):
    Item_hex_constant(thd, str, str_length) {}

Project: server

  Item *get_copy(THD *thd, MEM_ROOT *mem_root)
  { return get_item_copy<Item_hex_string>(thd, mem_root, this); }

Project: server

  Load_data_outvar *get_load_data_outvar_or_error()
  {
    Load_data_outvar *dst= get_load_data_outvar();
    if (dst)
      return dst;
    my_error(ER_NONUPDATEABLE_COLUMN, MYF(0), name);
    return NULL;
  }

Project: server

  Item *get_copy(THD *thd, MEM_ROOT *mem_root)
  { return get_item_copy<Item_string>(thd, mem_root, this); }

Project: server

  table_map not_null_tables() const 
  { 
    return depended_from ? 0 : (*ref)->not_null_tables();
  }

Project: server

  virtual Item *safe_charset_converter(THD *thd, CHARSET_INFO *tocs)
  {
    return const_charset_converter(thd, tocs, true);
  }

Project: server

  bool check_func_default_processor(void *arg) { return true; }

Project: server

  enum Type type() const { return EXPR_CACHE_ITEM; }

Project: server

  Item_temporal_literal(THD *thd, MYSQL_TIME *ltime): Item_basic_constant(thd)
  {
    collation.set(&my_charset_numeric, DERIVATION_NUMERIC, MY_REPERTOIRE_ASCII);
    decimals= 0;
    cached_time= *ltime;
  }

Project: server

  bool walk(Item_processor processor, bool walk_subquery, void *args)
  {
    return (item->walk(processor, walk_subquery, args)) ||
      (this->*processor)(args);
  }

Project: server

  bool check_vcol_func_processor(void *arg) 
  {
    return mark_unsupported_function(m_name.str, arg, VCOL_IMPOSSIBLE);
  }

Project: server

  Item *derived_grouping_field_transformer_for_where(THD *thd, uchar *arg)
  { return convert_to_basic_const_item(thd); }

Project: server

  void update_table_bitmaps()
  {
    if (field && field->table)
    {
      TABLE *tab= field->table;
      tab->covering_keys.intersect(field->part_of_key);
      if (tab->read_set)
        bitmap_fast_test_and_set(tab->read_set, field->field_index);
      /* 
        Do not mark a self-referecing virtual column.
        Such virtual columns are reported as invalid.
      */
      if (field->vcol_info && tab->vcol_set)
        tab->mark_virtual_col(field);
    }
  }

Project: server

  virtual bool remove_dependence_processor(void *arg) { return 0; }

Project: server

  bool check_vcol_func_processor(void *arg) 
  {
    return mark_unsupported_function("safe_string", arg, VCOL_IMPOSSIBLE);
  }

Project: server

  bool agg_arg_charsets_for_string_result(DTCollation &c,
                                          Item **items, uint nitems,
                                          int item_sep= 1)
  {
    uint flags= MY_COLL_ALLOW_SUPERSET_CONV |
                MY_COLL_ALLOW_COERCIBLE_CONV |
                MY_COLL_ALLOW_NUMERIC_CONV;
    return agg_arg_charsets(c, items, nitems, flags, item_sep);
  }

Project: server

  bool basic_const_item() const { return ref && (*ref)->basic_const_item(); }

Project: server

  Item_string(THD *thd, const char *name_par, const char *str, uint length,
              CHARSET_INFO *cs, Derivation dv, uint repertoire):
    Item_basic_constant(thd)
  {
    str_value.set_or_copy_aligned(str, length, cs);
    fix_from_value(dv, Metadata(&str_value, repertoire));
    set_name(thd, name_par, 0, system_charset_info);
  }

Project: server

  bool is_null() { return !has_value(); }

Project: server

  Item_int(THD *thd, int32 i,uint length= MY_INT32_NUM_DECIMAL_DIGITS):
    Item_num(thd), value((longlong) i)
    { max_length=length; fixed= 1; }

Project: server

  Item_int(THD *thd, longlong i,uint length= MY_INT64_NUM_DECIMAL_DIGITS):
    Item_num(thd), value(i)
    { max_length=length; fixed= 1; }

Project: server

  bool agg_arg_charsets_for_comparison(CHARSET_INFO **cs, Item **a, Item **b)
  {
    DTCollation tmp;
    if (tmp.set((*a)->collation, (*b)->collation, MY_COLL_CMP_CONV) ||
        tmp.derivation == DERIVATION_NONE)
    {
      my_error(ER_CANT_AGGREGATE_2COLLATIONS,MYF(0),
               (*a)->collation.collation->name,
               (*a)->collation.derivation_name(),
               (*b)->collation.collation->name,
               (*b)->collation.derivation_name(),
               func_name());
      return true;
    }
    if (agg_item_set_converter(tmp, func_name(),
                               a, 1, MY_COLL_CMP_CONV, 1) ||
        agg_item_set_converter(tmp, func_name(),
                               b, 1, MY_COLL_CMP_CONV, 1))
      return true;
    *cs= tmp.collation;
    return false;
  }

Project: server

  uint cols()
  { return result_type() == ROW_RESULT ? orig_item->cols() : 1; }

Project: server

  void sortlength(THD *thd,
                  const Type_std_attributes *item,
                  SORT_FIELD_ATTR *attr) const
  {
    type_handler()->sortlength(thd, item, attr);
  }

Project: server

  Sql_mode_dependency value_depends_on_sql_mode() const
  {
    return Sql_mode_dependency(0, field->value_depends_on_sql_mode());
  }

Project: server

  bool check_vcol_func_processor(void *arg) { return FALSE;}

Project: server

  Item *get_copy(THD *thd, MEM_ROOT *mem_root)
  { return get_item_copy<Item_cache_temporal>(thd, mem_root, this); }

Project: server

  virtual Item_field *field_for_view_update() { return 0; }

Project: server

  bool eq(const Item *item, bool binary_cmp) const
  { return int_eq(value, item); }

Project: server

  Cached_item_real(Item *item_par) :Cached_item_item(item_par),value(0.0) {}

Project: server

  Item_num(THD *thd): Item_basic_constant(thd) { collation.set_numeric(); }

Project: server

  bool vcol_assignment_allowed_value() const { return true; }

Project: server

  String *val_str() { return val_str(&str_value); }

Project: server

  virtual bool update_vcol_processor(void *arg) { return 0; }

Project: server

  virtual bool vcol_assignment_allowed_value() const { return false; }

Project: server

  virtual bool check_partition_func_processor(void *arg) { return 1;}

Project: server

  Item *get_copy(THD *thd, MEM_ROOT *mem_root)
  { return get_item_copy<Item_uint>(thd, mem_root, this); }

Project: server

  Item_string_with_introducer(THD *thd, const char *name_arg,
                              const char *str, uint length, CHARSET_INFO *tocs):
    Item_string(thd, name_arg, str, length, tocs)
  { }

Project: server

  Item_static_string_func(THD *thd, const char *name_par,
                          const String *str,
                          CHARSET_INFO *tocs, uint *conv_errors,
                          Derivation dv, uint repertoire):
    Item_string(thd, str, tocs, conv_errors, dv, repertoire),
    func_name(name_par)
  {}

Project: server

  double val_real()
  { 
    DBUG_ASSERT(fixed == 1); 
    return (double) (ulonglong) Item_hex_hybrid::val_int();
  }

Project: server

  Item_func_or_sum(THD *thd, List<Item> &list):
    Item_result_field(thd), Item_args(thd, list) { }

Project: server

  bool cleanup_excluding_const_fields_processor(void *arg)
  { return field && const_item() ? 0 : cleanup_processor(arg); }

Project: server

  bool has_no_value() const
  {
    return state == NO_VALUE;
  }

Project: server

  Item_field *field_for_view_update() { return 0; }

Project: server

  virtual uint get_join_tab_idx() { return join_tab_idx; }

Project: server

  Item_date_literal_for_invalid_dates(THD *thd, MYSQL_TIME *ltime)
   :Item_date_literal(thd, ltime) { }

Project: server

  Item_outer_ref(THD *thd, Name_resolution_context *context_arg, Item **item,
                 const char *table_name_arg, const char *field_name_arg,
                 bool alias_name_used_arg):
    Item_direct_ref(thd, context_arg, item, table_name_arg, field_name_arg,
                    alias_name_used_arg),
    outer_ref(0), in_sum_func(0), found_in_select_list(1), found_in_group_by(0)
  {}

Project: server

  virtual bool find_function_processor (void *arg) { return 0; }

Project: server

  virtual bool find_selective_predicates_list_processor(void *arg) { return 0; }

Project: server

  bool is_basic_value(const Item *item, Type type_arg) const
  {
    return item->basic_const_item() && item->type() == type_arg;
  }

Project: server

  uint divisor_precision_increment() const
  {
    return decimals <  NOT_FIXED_DEC ? decimals :
           is_temporal_type_with_time(field_type()) ?
           TIME_SECOND_PART_DIGITS :
           decimals;
  }

Project: server

  Item_args(void)
    :args(NULL), arg_count(0)
  { }

Project: server

  Item *get_copy(THD *thd, MEM_ROOT *mem_root)
  { return get_item_copy<Item_copy_string>(thd, mem_root, this); }

Project: server

  enum Item_result result_type () const { return orig_item->result_type(); }

Project: server

  bool basic_const_item() const { return true; }

Project: server

  bool eq(const Item *item, bool binary_cmp) const
  { return real_eq(value, item); }

Project: server

  Type_std_attributes()
   :collation(&my_charset_bin, DERIVATION_COERCIBLE),
    decimals(0), max_length(0), unsigned_flag(false)
  { }

Project: server

  Item_string(THD *thd, const char *str, uint length,
              CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE):
    Item_basic_constant(thd)
  {
    str_value.set_or_copy_aligned(str, length, cs);
    fix_and_set_name_from_value(thd, dv, Metadata(&str_value));
  }

Project: server

  bool check_partition_func_processor(void *int_arg) { return FALSE;}

Project: server

  virtual Item* build_clone(THD *thd, MEM_ROOT *mem_root) { return get_copy(thd, mem_root); }

Project: server

  table_map used_tables() const { return used_tables_cache; }

Project: server

  void fix_from_value(Derivation dv, const Metadata metadata)
  {
    fix_charset_and_length_from_str_value(dv, metadata);
    // it is constant => can be used without fix_fields (and frequently used)
    fixed= 1;
  }

Project: server

  Item_args(THD *thd, List<Item> &list)
  {
    set_arguments(thd, list);
  }

Project: server

  bool vcol_assignment_allowed_value() const { return arg == NULL; }

Project: server

  Item_uint(THD *thd, ulonglong i): Item_int(thd, i, 10) {}

Project: server

  bool cleanup_excluding_const_fields_processor(void *arg)
  { 
    Item *item= real_item();
    if (item && item->type() == FIELD_ITEM &&
        ((Item_field *) item)->field && item->const_item())
      return 0;
    return cleanup_processor(arg);
  }

Project: server

  void save_org_in_field(Field *field,
                         fast_field_copier data __attribute__ ((__unused__)))
  {
    if (check_null_ref())
      field->set_null();
    else
      Item_direct_ref::save_val(field);
  }

Project: server

  int sortcmp(const String *s, const String *t) const
  {
    return collation->coll->strnncollsp(collation,
                                        (uchar *) s->ptr(), s->length(),
                                        (uchar *) t->ptr(), t->length());
  }

Project: server

  Cached_item_field(THD *thd, Field *arg_field): field(arg_field)
  {
    field= arg_field;
    /* TODO: take the memory allocation below out of the constructor. */
    buff= (uchar*) thd_calloc(thd, length= field->pack_length());
  }

Project: server

  virtual Item_equal *get_item_equal() { return NULL; }

Project: server

  Item_hex_constant(THD *thd): Item_basic_constant(thd)
  {
    hex_string_init(thd, "", 0);
  }

Project: server

  void no_rows_in_result()
  {
    (*ref)->no_rows_in_result();
  }

Project: server

  enum_field_types odbc_temporal_literal_type(const LEX_STRING *type_str) const
  {
    /*
      If string is a reasonably short pure ASCII string literal,
      try to parse known ODBC style date, time or timestamp literals,
      e.g:
      SELECT {d'2001-01-01'};
      SELECT {t'10:20:30'};
      SELECT {ts'2001-01-01 10:20:30'};
    */
    if (collation.repertoire == MY_REPERTOIRE_ASCII &&
        str_value.length() < MAX_DATE_STRING_REP_LENGTH * 4)
    {
      if (type_str->length == 1)
      {
        if (type_str->str[0] == 'd')  /* {d'2001-01-01'} */
          return MYSQL_TYPE_DATE;
        else if (type_str->str[0] == 't') /* {t'10:20:30'} */
          return MYSQL_TYPE_TIME;
      }
      else if (type_str->length == 2) /* {ts'2001-01-01 10:20:30'} */
      {
        if (type_str->str[0] == 't' && type_str->str[1] == 's')
          return MYSQL_TYPE_DATETIME;
      }
    }
    return MYSQL_TYPE_STRING; // Not a temporal literal
  }

Project: server

  Item_string(THD *thd, const char *str, uint length, CHARSET_INFO *cs,
              Derivation dv, uint repertoire): Item_basic_constant(thd)
  {
    str_value.set_or_copy_aligned(str, length, cs);
    fix_and_set_name_from_value(thd, dv, Metadata(&str_value, repertoire));
  }

Project: server

  Used_tables_and_const_cache()
   :used_tables_cache(0),
    const_item_cache(true)
  { }

Project: server

  virtual bool need_parentheses_in_default() { return false; }

Project: server

  enum Item_result cmp_type () const
  { return Type_handler_hybrid_field_type::cmp_type(); }

Project: server

  bool is_basic_value(Type type_arg) const
  {
    return basic_const_item() && type() == type_arg;
  }

Project: server

  virtual bool eval_not_null_tables(void *arg) { return 0; }

Project: server

  bool walk(Item_processor processor, bool walk_subquery, void *arg)
  { 
    if (ref && *ref)
      return (*ref)->walk(processor, walk_subquery, arg) ||
             (this->*processor)(arg); 
    else
      return FALSE;
  }

Project: server

  bool const_item() const 
  {
    return (*ref)->const_item();
  }

Project: server

  bool save_in_param(THD *thd, Item_param *param)
  {
    // It should not be possible to have "EXECUTE .. USING DEFAULT(a)"
    DBUG_ASSERT(arg == NULL);
    param->set_default();
    return false;
  }

Project: server

  virtual bool is_bool_type() { return false; }

Project: server

  Settable_routine_parameter *get_settable_routine_parameter()
  { return this; }

Project: server

  Item *safe_charset_converter(THD *thd, CHARSET_INFO *tocs)
  {
    return const_charset_converter(thd, tocs, true, func_name);
  }

Project: server

  my_decimal *val_decimal(my_decimal *decimal_value)
  {
    // following assert is redundant, because fixed=1 assigned in constructor
    DBUG_ASSERT(fixed == 1);
    ulonglong value= (ulonglong) Item_hex_hybrid::val_int();
    int2my_decimal(E_DEC_FATAL_ERROR, value, TRUE, decimal_value);
    return decimal_value;
  }

Project: server

  void make_sort_key(uchar *to, Item *item, const SORT_FIELD_ATTR *sort_field,
                     Sort_param *param) const
  {
    type_handler()->make_sort_key(to, item, sort_field, param);
  }

Project: server

  void print_value(String *to) const
  {
    str_value.print(to);
  }

Project: server

  bool str_eq(const String *value,
              const String *other, CHARSET_INFO *cs, bool binary_cmp) const
  {
    return binary_cmp ?
      value->bin_eq(other) :
      collation.collation == cs && value->eq(other, collation.collation);
  }

Project: server

  Item_string_ascii(THD *thd, const char *str, uint length):
    Item_string(thd, str, length, &my_charset_latin1,
                DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII)
  { }

Project: server

  Item_static_float_func(THD *thd, const char *str, double val_arg,
                         uint decimal_par, uint length):
    Item_float(thd, NullS, val_arg, decimal_par, length), func_name(str)
  {}

Project: server

  virtual bool register_field_in_bitmap(void *arg) { return 0; }

Project: server

  Item *get_copy(THD *thd, MEM_ROOT *mem_root) { return 0; }

Project: server

  Item_basic_value(THD *thd): Item(thd) {}

Project: server

  Item_float(THD *thd, const char *str, double val_arg, uint decimal_par,
             uint length): Item_num(thd), value(val_arg)
  {
    presentation= name=(char*) str;
    decimals=(uint8) decimal_par;
    max_length=length;
    fixed= 1;
  }

Project: server

  bool is_expensive_processor(void *arg)
  {
    DBUG_ASSERT(example);
    if (value_cached)
      return false;
    return example->is_expensive_processor(arg);
  }

Project: server

  Item_string_with_introducer(THD *thd, const char *str, uint length,
                              CHARSET_INFO *cs):
    Item_string(thd, str, length, cs)
  { }

Project: server

  virtual bool check_vcol_func_processor(void *arg)
  {
    return mark_unsupported_function(full_name(), arg, VCOL_IMPOSSIBLE);
  }

Project: server

  Item_datetime_literal_for_invalid_dates(THD *thd,
                                          MYSQL_TIME *ltime, uint dec_arg)
   :Item_datetime_literal(thd, ltime, dec_arg) { }

Project: server

  Item_args(THD *thd, Item *a, Item *b, Item *c, Item *d)
  {
    arg_count= 0;
    if ((args= (Item**) thd_alloc(thd, sizeof(Item*) * 4)))
    {
      arg_count= 4;
      args[0]= a; args[1]= b; args[2]= c; args[3]= d;
    }
  }

Project: server

  Item* element_index(uint i)
  { return result_type() == ROW_RESULT ? orig_item->element_index(i) : this; }

Project: server

  virtual bool enumerate_field_refs_processor(void *arg) { return 0; }

Project: server

  bool check_vcol_func_processor(void *arg) 
  {
    return mark_unsupported_function("name_const()", arg, VCOL_IMPOSSIBLE);
  }

Project: server

  Item_cache_row(THD *thd):
    Item_cache(thd), values(0), item_count(2),
    save_array(0) {}

Project: server

  bool enumerate_field_refs_processor(void *arg)
  { return (*ref)->enumerate_field_refs_processor(arg); }

Project: server

    bool convert_if_needed(THD *thd, String *str)
    {
      /*
        Check is so simple because all charsets were set up properly
        in setup_one_conversion_function, where typecode of
        placeholder was also taken into account: the variables are different
        here only if conversion is really necessary.
      */
      if (needs_conversion())
        return convert(thd, str);
      str->set_charset(final_character_set_of_str_value);
      return false;
    }

Project: server

  void close() {}

Project: server

  bool register_clone(Item_param *i) { return m_clones.push_back(i); }

Project: server

  Item_iterator_row(Item *base) : base_item(base), current(0) {}

Project: server

  static Item_cache* get_cache(THD *thd, const Item* item,
                         const Item_result type)
  {
    return get_cache(thd, item, type, item->field_type());
  }

Project: server

  Item_field *field_for_view_update() { return this; }

Project: server

  virtual void get_cache_parameters(List<Item> &parameters) { };

Project: server

  double val_real() { return (double)val_int(); }

Project: server

  virtual bool is_subquery_processor(void *arg) { return 0; }

Project: server

  Item_ref(THD *thd, Name_resolution_context *context_arg,
           const char *db_arg, const char *table_name_arg,
           const char *field_name_arg):
    Item_ident(thd, context_arg, db_arg, table_name_arg, field_name_arg),
    set_properties_only(0), ref(0), reference_trough_name(1) {}

Project: server

  const Type_handler  *type_handler() const
  {
    return get_handler_by_field_type(field_type());
  }

Project: server

  Item_direct_view_ref(THD *thd, Name_resolution_context *context_arg,
                       Item **item,
                       const char *table_name_arg,
                       const char *field_name_arg,
                       TABLE_LIST *view_arg):
    Item_direct_ref(thd, context_arg, item, table_name_arg, field_name_arg),
    item_equal(0), view(view_arg),
    null_ref_table(NULL)
  {
    if (fixed)
      set_null_ref_table();
  }

Project: server

  void open() { current= 0; }

Project: server

  virtual Item *replace_equal_field(THD *thd, uchar *arg) { return this; }

Project: server

  void used_tables_and_const_cache_update_and_join(Item *item)
  {
    item->update_used_tables();
    used_tables_and_const_cache_join(item);
  }

Project: server

  bool agg_arg_charsets_for_string_result_with_comparison(DTCollation &c,
                                                          Item **items,
                                                          uint nitems,
                                                          int item_sep= 1)
  {
    uint flags= MY_COLL_ALLOW_SUPERSET_CONV |
                MY_COLL_ALLOW_COERCIBLE_CONV |
                MY_COLL_ALLOW_NUMERIC_CONV |
                MY_COLL_DISALLOW_NONE;
    return agg_arg_charsets(c, items, nitems, flags, item_sep);
  }

Project: server

  Item_ref_null_helper(THD *thd, Name_resolution_context *context_arg,
                       Item_in_subselect* master, Item **item,
		       const char *table_name_arg, const char *field_name_arg):
    Item_ref(thd, context_arg, item, table_name_arg, field_name_arg),
    owner(master) {}

Project: server

  Cached_item_item(Item *arg) : item(arg) {}

Project: server

  Item_iterator_ref_list(List_iterator<Item*> &arg_list):
    list(arg_list) {}

Project: server

  Item *get_copy(THD *thd, MEM_ROOT *mem_root)
  { return get_item_copy<Item_date_literal>(thd, mem_root, this); }

Project: server

  Item_basic_constant(THD *thd): Item_basic_value(thd), used_table_map(0) {};

Project: server

  virtual longlong val_datetime_packed()
  {
    MYSQL_TIME ltime;
    uint fuzzydate= TIME_FUZZY_DATES | TIME_INVALID_DATES;
    return get_date_with_conversion(&ltime, fuzzydate) ? 0 : pack_time(&ltime);
  }

Project: server

  bool has_long_data_value() const
  {
    return state == LONG_DATA_VALUE;
  }

Project: server

  Item_return_date_time(THD *thd, const char *name_arg, uint length_arg,
                        enum_field_types field_type_arg):
    Item_partition_func_safe_string(thd, name_arg, length_arg, &my_charset_bin),
    date_time_field_type(field_type_arg)
  { decimals= 0; }

Project: server

  virtual void update_used_tables()
  {
    if (field && field->default_value)
      field->default_value->expr->update_used_tables();
  }

Project: server

  Item *get_copy(THD *thd, MEM_ROOT *mem_root)
  { return get_item_copy<Item_cache_str>(thd, mem_root, this); }

Project: server

  Item *get_copy(THD *thd, MEM_ROOT *mem_root)
  { return get_item_copy<Item_field>(thd, mem_root, this); }

Project: server

  virtual longlong val_time_packed()
  {
    MYSQL_TIME ltime;
    uint fuzzydate= TIME_FUZZY_DATES | TIME_INVALID_DATES | TIME_TIME_ONLY;
    return get_date(&ltime, fuzzydate) ? 0 : pack_time(&ltime);
  }

Project: server

  Item *get_copy(THD *thd, MEM_ROOT *mem_root)
  { return get_item_copy<Item_name_const>(thd, mem_root, this); }

Project: server

inline void Item_sp_variable::make_field(THD *thd, Send_field *field)
{
  Item *it= this_item();

  if (name)
    it->set_name(thd, name, (uint) strlen(name), system_charset_info);
  else
    it->set_name(thd, m_name.str, (uint) m_name.length, system_charset_info);
  it->make_field(thd, field);
}

Project: server

  bool check_vcol_func_processor(void *arg) 
  {
    return mark_unsupported_function("copy", arg, VCOL_IMPOSSIBLE);
  }

Project: server

  bool needs_charset_converter(uint32 length, CHARSET_INFO *tocs) const
  {
    /*
      This will return "true" if conversion happens:
      - between two non-binary different character sets
      - from "binary" to "unsafe" character set
        (those that can have non-well-formed string)
      - from "binary" to UCS2-alike character set with mbminlen>1,
        when prefix left-padding is needed for an incomplete character:
        binary 0xFF -> ucs2 0x00FF)
    */
    if (!String::needs_conversion_on_storage(length,
                                             collation.collation, tocs))
      return false;
    /*
      No needs to add converter if an "arg" is NUMERIC or DATETIME
      value (which is pure ASCII) and at the same time target DTCollation
      is ASCII-compatible. For example, no needs to rewrite:
        SELECT * FROM t1 WHERE datetime_field = '2010-01-01';
      to
        SELECT * FROM t1 WHERE CONVERT(datetime_field USING cs) = '2010-01-01';

      TODO: avoid conversion of any values with
      repertoire ASCII and 7bit-ASCII-compatible,
      not only numeric/datetime origin.
    */
    if (collation.derivation == DERIVATION_NUMERIC &&
        collation.repertoire == MY_REPERTOIRE_ASCII &&
        !(collation.collation->state & MY_CS_NONASCII) &&
        !(tocs->state & MY_CS_NONASCII))
      return false;
    return true;
  }

Project: server

  longlong val_temporal_packed(enum_field_types f_type)
  {
    return f_type == MYSQL_TYPE_TIME ? val_time_packed() :
                                       val_datetime_packed();
  }

Project: server

  virtual bool set_fake_select_as_master_processor(void *arg) { return 0; }

Project: server

  Item *next()
  {
    if (current >= base_item->cols())
      return NULL;
    return base_item->element_index(current++);
  }

Project: server

  String_copier_for_item(THD *thd): m_thd(thd) { }

Project: server

  Item_default_value(THD *thd, Name_resolution_context *context_arg, Field *a)
    :Item_field(thd, context_arg, (const char *)NULL, (const char *)NULL,
                (const char *)NULL),
    arg(NULL),cached_field(NULL) {}

Project: server

  bool check_vcol_func_processor(void *arg)
  {
    context= 0;
    if (field && (field->unireg_check == Field::NEXT_NUMBER))
    {
      // Auto increment fields are unsupported
      return mark_unsupported_function(field_name, arg, VCOL_FIELD_REF | VCOL_AUTO_INC);
    }
    return mark_unsupported_function(field_name, arg, VCOL_FIELD_REF);
  }

Project: server

  Item_cache_str_for_nullif(THD *thd, const Item *item)
   :Item_cache_str(thd, item)
  { }

Project: server

  virtual ~Field_enumerator() {};             /* purecov: inspected */

Project: server

  enum_field_types real_field_type() const
  { return Type_handler_hybrid_real_field_type::real_field_type(); }

Project: server

  enum_field_types field_type() const
  {
    return value_item->field_type();
  }

Project: server

  Item_direct_ref(THD *thd, Name_resolution_context *context_arg, Item **item,
                  const char *table_name_arg,
                  const char *field_name_arg,
                  bool alias_name_used_arg= FALSE):
    Item_ref(thd, context_arg, item, table_name_arg,
             field_name_arg, alias_name_used_arg)
  {}

Project: server

  Item_cache_decimal(THD *thd): Item_cache(thd, MYSQL_TYPE_NEWDECIMAL) {}

Project: server

  void make_field(THD *thd, Send_field *field) { item->make_field(thd, field); }

Project: server

  bool excl_dep_on_grouping_fields(st_select_lex *sel)
  {
    for (uint i= 0; i < arg_count; i++)
    {
      if (args[i]->const_item())
        continue;      
      if (!args[i]->excl_dep_on_grouping_fields(sel))
        return false;
    }
    return true;
  }

Project: server

  Cached_item_int(Item *item_par) :Cached_item_item(item_par),value(0) {}

Project: server

  Item_cache(THD *thd, enum_field_types field_type_arg):
    Item_basic_constant(thd),
    Type_handler_hybrid_field_type(field_type_arg),
    example(0), cached_field(0),
    value_cached(0)
  {
    fixed= 1;
    maybe_null= 1;
    null_value= 1;
    null_value_inside= true;
  }

Project: server

  enum_field_types field_type() const
  {
    return result_field->type();
  }

Project: server

  bool null_inside()
  { return result_type() == ROW_RESULT ? orig_item->null_inside() : 0; }

Project: server

  bool walk(Item_processor processor, bool walk_subquery, void *arg)
  {
    if (walk_args(processor, walk_subquery, arg))
      return true;
    return (this->*processor)(arg);
  }

Project: server

  bool setup(THD *thd, Item *item)
  {
    if (Item_cache_int::setup(thd, item))
      return true;
    set_if_smaller(decimals, TIME_SECOND_PART_DIGITS);
    return false;
  }

Project: server

  Item_empty_string(THD *thd, const char *header,uint length,
                    CHARSET_INFO *cs= NULL):
    Item_partition_func_safe_string(thd, "", 0,
                                    cs ? cs : &my_charset_utf8_general_ci)
    { name=(char*) header; max_length= length * collation.collation->mbmaxlen; }

Project: server

  virtual void under_not(Item_func_not * upper
                         __attribute__((unused))) {};

Project: server

  Item_args(THD *thd, Item *a, Item *b, Item *c, Item *d, Item* e)
  {
    arg_count= 5;
    if ((args= (Item**) thd_alloc(thd, sizeof(Item*) * 5)))
    {
      arg_count= 5;
      args[0]= a; args[1]= b; args[2]= c; args[3]= d; args[4]= e;
    }
  }

Project: server

  bool check_vcol_func_processor(void *arg)
  {
    return mark_unsupported_function(full_name(), arg, VCOL_IMPOSSIBLE);
  }

Project: server

  bool is_expensive() { return orig_item->is_expensive(); }

Project: server

  virtual bool rename_fields_processor(void *arg) { return 0; }

Project: server

  bool walk(Item_processor processor, bool walk_subquery, void *arg)
  { 
    return (*ref)->walk(processor, walk_subquery, arg) ||
           (this->*processor)(arg);
  }

Project: server

  Sql_mode_dependency value_depends_on_sql_mode() const
  {
    return Item_args::value_depends_on_sql_mode_bit_or().soft_to_hard();
  }

Project: server

  Item_datetime_literal(THD *thd, MYSQL_TIME *ltime, uint dec_arg):
    Item_temporal_literal(thd, ltime, dec_arg)
  {
    max_length= MAX_DATETIME_WIDTH + (decimals ? decimals + 1 : 0);
    fixed= 1;
    // See the comment on maybe_null in Item_date_literal
    maybe_null= !ltime->month || !ltime->day;
  }

Project: server

inline bool Virtual_column_info::is_equal(const Virtual_column_info* vcol) const
{
  return field_type == vcol->get_real_type()
      && stored_in_db == vcol->is_stored()
      && expr->eq(vcol->expr, true);
}

Project: server

char_to_byte_length_safe(size_t char_length_arg, uint32 mbmaxlen_arg)
{
  ulonglong tmp= ((ulonglong) char_length_arg) * mbmaxlen_arg;
  return tmp > UINT_MAX32 ? UINT_MAX32 : static_cast<uint32>(tmp);
}

Project: server

  Item_null_result(THD *thd): Item_null(thd), result_field(0) {}

Project: server

    Metadata(const String *str)
    {
      my_string_metadata_get(this, str->charset(), str->ptr(), str->length());
    }

Project: server

  const Type_handler *type_handler() const
  {
    return result_field->type_handler();
  }

Project: server

  bool load_data_add_outvar(THD *thd, Load_data_param *param) const
  {
    return param->add_outvar_field(thd, field);
  }

Project: server

  void used_tables_and_const_cache_update_and_join(uint argc, Item **argv)
  {
    for (uint i=0 ; i < argc ; i++)
      used_tables_and_const_cache_update_and_join(argv[i]);
  }

Project: server

  Item_insert_value(THD *thd, Name_resolution_context *context_arg, Item *a)
    :Item_field(thd, context_arg, (const char *)NULL, (const char *)NULL,
               (const char *)NULL),
     arg(a) {}

Project: server

  Copy_query_with_rewrite(THD *t, const char *s, size_t l, String *d)
    :thd(t), src(s), src_len(l), from(0), dst(d) { }

Project: server

  Item *get_copy(THD *thd, MEM_ROOT *mem_root)
  { return get_item_copy<Item_hex_hybrid>(thd, mem_root, this); }

Project: server

  enum_field_types string_field_type() const
  {
    return Type_handler::string_type_handler(max_length)->field_type();
  }

Project: server

  enum Type type() const { return INSERT_VALUE_ITEM; }

Project: server

  st_select_lex *outer_select()
  {
    return (outer_context ?
            outer_context->select_lex :
            NULL);
  }

Project: server

  bool eq_def(const Field *field) 
  { 
    return cached_field ? cached_field->eq_def (field) : FALSE;
  }

Project: server

  void save_in_result_field(bool no_conversions)
  {
    if (check_null_ref())
      result_field->set_null();
    else
      Item_direct_ref::save_in_result_field(no_conversions);
  }

Project: server

  Item_int_with_ref(THD *thd, longlong i, Item *ref_arg, bool unsigned_arg):
    Item_int(thd, i), ref(ref_arg)
  {
    unsigned_flag= unsigned_arg;
  }

Project: server

  Item *get_copy(THD *thd, MEM_ROOT *mem_root)
  { return get_item_copy<Item_cache_real>(thd, mem_root, this); }

Project: server

  virtual bool view_used_tables_processor(void *arg) { return 0; }

Project: server

  my_decimal *val_decimal(my_decimal *decimal_value)
  { return  val_decimal_from_date(decimal_value); }

Project: server

  virtual Item_result cast_to_int_type() const { return cmp_type(); }

Project: server

  Item *get_copy(THD *thd, MEM_ROOT *mem_root)
  { return get_item_copy<Item_datetime_literal>(thd, mem_root, this); }

Project: server

  longlong val_int()
  {
    DBUG_ASSERT(fixed == 1);
    return longlong_from_string_with_check(&str_value);
  }

Project: server

  enum_field_types field_type() const { return MYSQL_TYPE_DATE; }

Project: server

inline void Virtual_column_info::print(String* str)
{
  expr->print_for_table_def(str);
}

Project: server

  bool int_eq(longlong value, const Item *item) const
  {
    DBUG_ASSERT(is_basic_value(INT_ITEM));
    return is_basic_value(item, INT_ITEM) &&
           value == ((Item_basic_value*)item)->val_int() &&
           (value >= 0 || item->unsigned_flag == unsigned_flag);
  }

Project: server

  virtual bool is_expensive_processor(void *arg) { return 0; }

Project: server

    Metadata(const String *str, uint repertoire_arg)
    {
      MY_STRING_METADATA::repertoire= repertoire_arg;
      MY_STRING_METADATA::char_length= str->numchars();
    }

Project: server

  inline void remove_arguments() { arg_count=0; }

Project: server

  uint decimal_precision() const
  { return (uint) (max_length - MY_TEST(value < 0)); }

Project: server

  Item_cache_int(THD *thd): Item_cache(thd, MYSQL_TYPE_LONGLONG),
    value(0) {}

Project: server

  virtual bool mark_as_eliminated_processor(void *arg) { return 0; }

Project: server

  double val_real()
  { 
    DBUG_ASSERT(fixed == 1);
    return double_from_string_with_check(&str_value);
  }

Project: server

  longlong val_time_packed()
  {
    if (check_null_ref())
      return 0;
    else
      return Item_direct_ref::val_time_packed();
  }

Project: server

  Item_time_literal(THD *thd, MYSQL_TIME *ltime, uint dec_arg):
    Item_temporal_literal(thd, ltime, dec_arg)
  {
    max_length= MIN_TIME_WIDTH + (decimals ? decimals + 1 : 0);
    fixed= 1;
  }

Project: server

  enum Type real_type() const { return orig_item->type(); }

Project: server

  virtual void set_join_tab_idx(uint join_tab_idx_arg)
  {
    if (join_tab_idx_arg < join_tab_idx)
      join_tab_idx= join_tab_idx_arg;
  }

Project: server

  Item_func_or_sum(THD *thd, Item *a, Item *b, Item *c, Item *d, Item *e):
    Item_result_field(thd), Item_args(thd, a, b, c, d, e) { }

Project: server

  bool check_null_ref()
  {
    DBUG_ASSERT(null_ref_table);
    if (null_ref_table != NO_NULL_TABLE && null_ref_table->null_row)
    {
      null_value= 1;
      return TRUE;
    }
    return FALSE;
  }

Project: server

  Load_data_outvar *get_load_data_outvar()
  {
    return (*ref)->get_load_data_outvar();
  }

Project: server

  virtual Item *update_value_transformer(THD *thd, uchar *select_arg)
  { return this; }

Project: server

  bool check_vcol_func_processor(void *arg)
  { // VCOL_TIME_FUNC because the value is not constant, but does not
    // require fix_fields() to be re-run for every statement.
    return mark_unsupported_function(func_name, arg, VCOL_TIME_FUNC);
  }

Project: server

  enum_field_types field_type() const { return this_item()->field_type(); }

Project: server

  virtual ~Rewritable_query_parameter() { }

Project: server

  void set(const Type_std_attributes *other)
  {
    *this= *other;
  }

Project: server

  void used_tables_and_const_cache_init()
  {
    used_tables_cache= 0;
    const_item_cache= true;
  }

Project: server

  bool append(Rewritable_query_parameter *p)
  {
    if (copy_up_to(p->pos_in_query) || p->append_for_log(thd, dst))
      return true;
    from= p->pos_in_query + p->len_in_query;
    return false;
  }

Project: server

  virtual CHARSET_INFO *charset_for_protocol(void) const
  {
    return cmp_type() == STRING_RESULT ? collation.collation :
                                         &my_charset_bin;
  };

Project: server

  bool check_cols(uint c)
  {
    return (result_type() == ROW_RESULT ?
            orig_item->check_cols(c) :
            Item::check_cols(c));
  }

Project: server

  virtual table_map all_used_tables() const { return used_tables(); }

Project: server

  Item *get_tmp_table_item(THD *thd)
  {
    if (const_item())
      return copy_or_same(thd);
    Item *item= Item_ref::get_tmp_table_item(thd);
    item->name= name;
    return item;
  }

Project: server

  bool enumerate_field_refs_processor(void *arg)
  { return orig_item->enumerate_field_refs_processor(arg); }

Project: server

static inline const char *dbug_print_item(Item *item) { return NULL; }

Project: server

  Item_field *field_for_view_update()
  { return orig_item->field_for_view_update(); }

Project: server

  COND *build_equal_items(THD *thd, COND_EQUAL *inherited,
                          bool link_item_fields,
                          COND_EQUAL **cond_equal_ref)
  {
    /*
      normilize_cond() replaced all conditions of type
         WHERE/HAVING field
      to:
        WHERE/HAVING field<>0
      By the time of a build_equal_items() call, all such conditions should
      already be replaced. No Item_field are possible.
      Note, some Item_field derivants are still possible.
      Item_insert_value:
        SELECT * FROM t1 WHERE VALUES(a);
      Item_default_value:
        SELECT * FROM t1 WHERE DEFAULT(a);
    */
    DBUG_ASSERT(type() != FIELD_ITEM);
    return Item_ident::build_equal_items(thd, inherited, link_item_fields,
                                         cond_equal_ref);
  }

Project: server

  void split_sum_func2_example(THD *thd,  Ref_ptr_array ref_pointer_array,
                               List<Item> &fields, uint flags)
  {
    example->split_sum_func2(thd, ref_pointer_array, fields, &example, flags);
  }

Project: server

  bool excl_dep_on_table(table_map tab_map)
  {
    for (uint i= 0; i < arg_count; i++)
    {
      if (args[i]->const_item())
        continue;
      if (!args[i]->excl_dep_on_table(tab_map))
        return false;
    }
    return true;
  }

Project: server

  bool walk(Item_processor processor, bool walk_subquery, void *args)
  {
    return (arg && arg->walk(processor, walk_subquery, args)) ||
      (this->*processor)(args);
  }

Project: server

  void clear_extraction_flag()
  {
    marker &= ~EXTRACTION_MASK;
  }

Project: server

  void set(const DTCollation &dt)
  { 
    collation= dt.collation;
    derivation= dt.derivation;
    repertoire= dt.repertoire;
  }

Project: server

  virtual Item_splocal *get_item_splocal() { return 0; }

Project: server

  enum Type type() const
  {
    return item_type;
  }

Project: server

  virtual void save_val(Field *to) { save_org_in_field(to, NULL); }

Project: server

  enum_field_types field_type() const { return MYSQL_TYPE_TIME; }

Project: server

  int get_extraction_flag()
  { return  marker & EXTRACTION_MASK; }

Project: server

inline Item* get_item_copy (THD *thd, MEM_ROOT *mem_root, T* item)
{
  Item *copy= new (mem_root) T(*item);
  copy->register_in(thd);
  return copy;
}

Project: server

  void set_result_field(Field *field_arg) {}

Project: server

  Item_return_int(THD *thd, const char *name_arg, uint length,
		  enum_field_types field_type_arg, longlong value_arg= 0):
    Item_int(thd, name_arg, value_arg, length), int_field_type(field_type_arg)
  {
    unsigned_flag=1;
  }

Project: server

  enum_field_types field_type() const   { return orig_item->field_type(); }

Project: server

  enum Item_result result_type () const
  { return Type_handler_hybrid_field_type::result_type(); }

Project: server

  Item_direct_ref_to_ident(THD *thd, Item_ident *item):
    Item_direct_ref(thd, item->context, (Item**)&item, item->table_name,
                    item->field_name, FALSE)
  {
    ident= item;
    ref= (Item**)&ident;
  }

Project: server

  CHARSET_INFO *charset_for_protocol(void) const
  {
    return (*ref)->charset_for_protocol();
  }

Project: server

  int save_in_field(Field *field, bool no_conversions)
  {
    field->set_notnull();
    return field->store(str_value.ptr(), str_value.length(), 
                        collation.collation);
  }

Project: server

  virtual bool limit_index_condition_pushdown_processor(void *arg) { return 0; }

Project: server

  Item_cache(THD *thd):
    Item_basic_constant(thd),
    Type_handler_hybrid_field_type(MYSQL_TYPE_STRING),
    example(0), cached_field(0),
    value_cached(0)
  {
    fixed= 1;
    maybe_null= 1;
    null_value= 1;
    null_value_inside= true;
  }

Project: server

  Item *get_copy(THD *thd, MEM_ROOT *mem_root)
  { return get_item_copy<Item_cache_int>(thd, mem_root, this); }

Project: server

  Item_string(THD *thd, CHARSET_INFO *csi, const char *str_arg, uint length_arg):
    Item_basic_constant(thd)
  {
    collation.set(csi, DERIVATION_COERCIBLE);
    set_name(thd, NULL, 0, system_charset_info);
    decimals= NOT_FIXED_DEC;
    fixed= 1;
    str_value.copy(str_arg, length_arg, csi);
    max_length= str_value.numchars() * csi->mbmaxlen;
  }

Project: server

  Item *safe_charset_converter(THD *thd, CHARSET_INFO *tocs)
  {
    return const_charset_converter(thd, tocs, true);
  }

Project: server

  virtual inline void quick_fix_field() { fixed= 1; }

Project: server

  virtual bool register_field_in_read_map(void *arg) { return 0; }

Project: server

  Item_hex_hybrid(THD *thd): Item_hex_constant(thd) {}

Project: server

  Field *make_num_distinct_aggregator_field(MEM_ROOT *mem_root,
                                            const Item *item) const
  {
    return type_handler()->make_num_distinct_aggregator_field(mem_root, this);
  }

Project: server

  Item *get_copy(THD *thd, MEM_ROOT *mem_root)
  { return get_item_copy<Item_cache_decimal>(thd, mem_root, this); }

Project: server

  Item_blob(THD *thd, const char *name_arg, uint length):
    Item_partition_func_safe_string(thd, name_arg, (uint) strlen(name_arg), &my_charset_bin)
  { max_length= length; }

Project: server

  Item *get_copy(THD *thd, MEM_ROOT *mem_root)
  { return get_item_copy<Item_ref_null_helper>(thd, mem_root, this); }

Project: server

  virtual Item *copy_andor_structure(THD *thd) { return this; }

Project: server

  virtual bool allocate(THD *thd, uint i) { return 0; }

Project: server

  virtual Field *create_tmp_field(bool group, TABLE *table)
  {
    /*
      Values with MY_INT32_NUM_DECIMAL_DIGITS digits may or may not fit into
      Field_long : make them Field_longlong.
    */
    return create_tmp_field(false, table, MY_INT32_NUM_DECIMAL_DIGITS - 2);
  }

Project: server

  Field *make_conversion_table_field(TABLE *table,
                                     uint metadata, const Field *target) const
  {
    DBUG_ASSERT(0); // Should not be called in Item context
    return NULL;
  }

Project: server

  Item_temptable_field(THD *thd, Name_resolution_context *context_arg, Field *field)
   : Item_field(thd, context_arg, field) {}

Project: server

  virtual bool is_cs_specified() const
  {
    return true;
  }

Project: server

  longlong val_datetime_packed()
  {
    if (check_null_ref())
      return 0;
    else
      return Item_direct_ref::val_datetime_packed();
  }

Project: server

  longlong val_int()
  { return val_int_from_date(); }

Project: server

  uint load_data_fixed_length() const
  {
    return field->field_length;
  }

Project: server

  bool eval_const_cond()
  {
    DBUG_ASSERT(const_item());
    DBUG_ASSERT(!is_expensive());
    return val_bool();
  }

Project: server

  enum_field_types field_type() const
  { return Type_handler_hybrid_field_type::field_type(); }

Project: server

  virtual bool cleanup_excluding_fields_processor(void *arg) { return cleanup_processor(arg); }

Project: server

  Item_float(THD *thd, double value_par, uint decimal_par):
    Item_num(thd), presentation(0), value(value_par)
  {
    decimals= (uint8) decimal_par;
    fixed= 1;
  }

Project: server

  void open() { list.rewind(); }

Project: server

  my_decimal *val_decimal(my_decimal *tmp)
  {
    if (check_null_ref())
      return NULL;
    else
      return Item_direct_ref::val_decimal(tmp);
  }

Project: server

  virtual bool check_valid_arguments_processor(void *arg) { return 0; }

Project: server

  Item *get_orig_item() const { return orig_item; }

Project: server

  longlong val_temporal_packed(const Item *other)
  {
    return val_temporal_packed(field_type_for_temporal_comparison(other));
  }

Project: server

  virtual bool is_cs_specified() const
  {
    return false;
  }

Project: server

  Item *get_copy(THD *thd, MEM_ROOT *mem_root)
  { return get_item_copy<Item_cache_row>(thd, mem_root, this); }

Project: server

  void update_used_tables()
  {
    update_table_bitmaps();
  }

Project: server

  Field *create_field_for_schema(THD *thd, TABLE *table)
  { return tmp_table_field_from_field_type(table, false, true); }

Project: server

  void share_name_with(Item *item)
  {
    name= item->name;
    name_length= item->name_length;
    is_autogenerated_name= item->is_autogenerated_name;
  }

Project: server

  virtual Item* propagate_equal_fields(THD*, const Context &, COND_EQUAL *)
  {
    return this;
  };

Project: server

  virtual bool dynamic_result() { return 0; }

Project: server

  table_map view_used_tables(TABLE_LIST *view)
  {
    view->view_used_tables= 0;
    walk(&Item::view_used_tables_processor, 0, view);
    return view->view_used_tables;
  }

Project: server

  longlong val_int()
  {
    if (check_null_ref())
      return 0;
    else
      return Item_direct_ref::val_int();
  }

Project: server

  virtual bool change_context_processor(void *cntx)
    { context= (Name_resolution_context *)cntx; return FALSE; }

Project: server

  Item *get_copy(THD *thd, MEM_ROOT *mem_root)
  { return get_item_copy<Item_time_literal>(thd, mem_root, this); }

Project: server

  virtual void mark_as_condition_AND_part(TABLE_LIST *embedding) {};

Project: server

  longlong val_int_from_item(Item *item)
  {
    DBUG_ASSERT(fixed == 1);
    longlong value= item->val_int();
    null_value= item->null_value;
    return value;
  }

Project: server

  Item_string_sys(THD *thd, const char *str, uint length):
    Item_string(thd, str, length, system_charset_info)
  { }

Project: server

  void save_org_in_field(Field *field,
                         fast_field_copier data __attribute__ ((__unused__)))
  {
    save_val(field);
  }

Project: server

  virtual bool excl_dep_on_table(table_map tab_map) { return false; }

Project: server

  bool fix_fields(THD *thd, Item **it)
  {
    if ((!(*ref)->fixed && (*ref)->fix_fields(thd, ref)) ||
        (*ref)->check_cols(1))
      return TRUE;
    return Item_ref::fix_fields(thd, it);
  }

Project: server

  virtual bool collect_outer_ref_processor(void *arg) {return 0; }

Project: server

  Item_result cast_to_int_type() const
  {
    return field->cmp_type();
  }

Project: server

  void cleanup()
  {
    null_ref_table= NULL;
    item_equal= NULL;
    Item_direct_ref::cleanup();
  }

Project: server

  virtual bool post_fix_fields_part_expr_processor(void *arg) { return 0; }

Project: server

  my_decimal *val_decimal(my_decimal *decimal_value)
  {
    return val_decimal_from_string(decimal_value);
  }

Project: server

  bool walk(Item_processor processor, bool walk_subquery, void *args)
  {
    return arg->walk(processor, walk_subquery, args) ||
	    (this->*processor)(args);
  }

Project: server

  Item *next() { return (list++); }

Project: server

  bool is_null()
  {
    if (check_null_ref())
      return 1;
    else
      return Item_direct_ref::is_null();
  }

Project: server

  bool check_table_name_processor(void *arg)
  {
    Check_table_name_prm &p= *(Check_table_name_prm *) arg;
    if (p.table_name.length && table_name)
    {
      DBUG_ASSERT(p.db.length);
      if ((db_name &&
          my_strcasecmp(table_alias_charset, p.db.str, db_name)) ||
          my_strcasecmp(table_alias_charset, p.table_name.str, table_name))
      {
        print(&p.field, (enum_query_type) (QT_ITEM_ORIGINAL_FUNC_NULLIF |
                                          QT_NO_DATA_EXPANSION |
                                          QT_TO_SYSTEM_CHARSET));
        return true;
      }
    }
    return false;
  }

Project: server

  Item_cache_str(THD *thd, const Item *item):
    Item_cache(thd, item->field_type()), value(0),
    is_varbinary(item->type() == FIELD_ITEM &&
                 Item_cache_str::field_type() == MYSQL_TYPE_VARCHAR &&
                 !((const Item_field *) item)->field->has_charset())
  {
    collation.set(const_cast<DTCollation&>(item->collation));
  }

Project: server

  double val_real_from_item(Item *item)
  {
    DBUG_ASSERT(fixed == 1);
    double value= item->val_real();
    null_value= item->null_value;
    return value;
  }

Project: server

  virtual void split_sum_func(THD *thd, Ref_ptr_array ref_pointer_array,
                              List<Item> &fields, uint flags) {}

Project: server

  bool get_time(MYSQL_TIME *ltime)
  { return get_date(ltime, TIME_TIME_ONLY | TIME_INVALID_DATES); }

Project: server

  virtual bool check_equality(THD *thd, COND_EQUAL *cond, List<Item> *eq_list)
  {
    return false;
  }

Project: server

  Item_result cmp_type() const { return type_handler()->cmp_type(); }

Project: server

  enum precedence higher_precedence() const
  { return (enum precedence)(precedence() + 1); }

Project: server

    bool needs_conversion() const
    {
      return final_character_set_of_str_value !=
             character_set_of_placeholder;
    }

Project: server

  void update_used_tables()
  {
    orig_item->update_used_tables();
  }

Project: server

  virtual bool reset_query_id_processor(void *arg) { return 0; }

Project: server

  bool walk(Item_processor processor, bool walk_subquery, void *arg)
  {
    return orig_item->walk(processor, walk_subquery, arg) ||
      (this->*processor)(arg);
  }

Project: server

  virtual bool is_json_type() { return false; }

Project: server

  bool is_expensive_processor(void *arg)
  { return orig_item->is_expensive_processor(arg); }

Project: server

  void used_tables_and_const_cache_join(const Item *item)
  {
    used_tables_cache|= item->used_tables();
    const_item_cache&= item->const_item();
  }

Project: server

  Item_result cmp_type() const { return TIME_RESULT; }

Project: server

  bool const_item() const
  {
    return (*ref)->const_item() && (null_ref_table == NO_NULL_TABLE);
  }

Project: server

  virtual Item *derived_field_transformer_for_having(THD *thd, uchar *arg)
  { return this; }

Project: server

  Item_null(THD *thd, char *name_par=0, CHARSET_INFO *cs= &my_charset_bin):
    Item_basic_constant(thd)
  {
    maybe_null= null_value= TRUE;
    max_length= 0;
    name= name_par ? name_par : (char*) "NULL";
    fixed= 1;
    collation.set(cs, DERIVATION_IGNORABLE, MY_REPERTOIRE_ASCII);
  }

Project: server

  bool const_item() const { return orig_item->const_item(); }

Project: server

  Item_func_or_sum(THD *thd, Item *a, Item *b, Item *c, Item *d):
    Item_result_field(thd), Item_args(thd, a, b, c, d) { }

Project: server

  virtual void fix_after_pullout(st_select_lex *new_parent, Item **ref,
                                 bool merge)
    {};

Project: server

  bool eq(const Item *item, bool binary_cmp) const { return null_eq(item); }

Project: server

  void set_null_ref_table()
  {
    if (!view->is_inner_table_of_outer_join() ||
        !(null_ref_table= view->get_real_join_table()))
      null_ref_table= NO_NULL_TABLE;
  }

Project: server

  Item_temptable_field(THD *thd, Field *field)
   : Item_field(thd, field) {}

Project: server

  virtual bool find_item_in_field_list_processor(void *arg) { return 0; }

Project: server

  TABLE *get_null_ref_table() const { return null_ref_table; }

Project: server

  Item* get_copy(THD *thd, MEM_ROOT *mem_root)
  { return get_item_copy<Item_ident_for_show>(thd, mem_root, this); }

Project: server

  enum_field_types field_type() const
  { return Type_handler_hybrid_real_field_type::field_type(); }

Project: server

  void fix_char_length(size_t max_char_length_arg)
  {
    max_length= char_to_byte_length_safe(max_char_length_arg,
                                         collation.collation->mbmaxlen);
  }

Project: server

  virtual bool register_field_in_write_map(void *arg) { return 0; }

Project: server

  Item_temporal_literal(THD *thd, MYSQL_TIME *ltime, uint dec_arg):
    Item_basic_constant(thd)
  {
    collation.set(&my_charset_numeric, DERIVATION_NUMERIC, MY_REPERTOIRE_ASCII);
    decimals= dec_arg;
    cached_time= *ltime;
  }

Project: server

  Used_tables_and_const_cache(const Used_tables_and_const_cache *other)
   :used_tables_cache(other->used_tables_cache),
    const_item_cache(other->const_item_cache)
  { }

Project: server

  virtual bool excl_dep_on_grouping_fields(st_select_lex *sel) { return false; }

Project: server

  bool excl_dep_on_grouping_fields(st_select_lex *sel)
  { return (*ref)->excl_dep_on_grouping_fields(sel); }

Project: server

  bool get_date_from_item(Item *item, MYSQL_TIME *ltime, ulonglong fuzzydate)
  {
    bool rc= item->get_date(ltime, fuzzydate);
    null_value= MY_TEST(rc || item->null_value);
    return rc;
  }

Project: server

  Item_splocal *get_item_splocal() { return this; }

Project: server

  Item_int(THD *thd, const char *str_arg,longlong i,uint length):
    Item_num(thd), value(i)
    { max_length=length; name=(char*) str_arg; fixed= 1; }

Project: server

  Item *get_copy(THD *thd, MEM_ROOT *mem_root)
  { return get_item_copy<Item_direct_ref>(thd, mem_root, this); }

Project: server

  virtual enum precedence precedence() const { return DEFAULT_PRECEDENCE; }

Project: server

  enum precedence precedence() const
  {
    return ref ? (*ref)->precedence() : DEFAULT_PRECEDENCE;
  }

Project: server

  bool copy_up_to(size_t bytes)
  {
    DBUG_ASSERT(bytes >= from);
    return dst->append(src + from, uint32(bytes - from));
  }

Project: server

  bool needs_charset_converter(CHARSET_INFO *tocs)
  {
    // Pass 1 as length to force conversion if tocs->mbminlen>1.
    return needs_charset_converter(1, tocs);
  }

Project: server

  virtual void print(String *str, enum_query_type query_type)
  { ident->print(str, query_type); }

Project: server

  String *val_str(String *str)
  { return val_string_from_date(str); }

Project: server

  void fix_type(Type type)
  {
    item_type= type;
    fixed= true;
  }

Project: server

  void print_for_table_def(String *str)
  {
    print_parenthesised(str,
                     (enum_query_type)(QT_ITEM_ORIGINAL_FUNC_NULLIF |
                                       QT_ITEM_IDENT_SKIP_DB_NAMES |
                                       QT_ITEM_IDENT_SKIP_TABLE_NAMES |
                                       QT_NO_DATA_EXPANSION |
                                       QT_TO_SYSTEM_CHARSET),
                     LOWEST_PRECEDENCE);
  }

Project: server

  Item_args(Item *a)
    :args(tmp_arg), arg_count(1)
  {
    args[0]= a;
  }

Project: server

  Item_int(THD *thd, ulonglong i, uint length= MY_INT64_NUM_DECIMAL_DIGITS):
    Item_num(thd), value((longlong)i)
    { max_length=length; fixed= 1; unsigned_flag= 1; }

Project: server

  virtual Item *expr_cache_insert_transformer(THD *thd, uchar *unused)
  { return this; }

Project: server

  Item *safe_charset_converter(THD *thd, CHARSET_INFO *tocs)
  {
    /**
      Item_cache_str::safe_charset_converter() returns a new Item_cache
      with Item_func_conv_charset installed on "example". The original
      Item_cache is not referenced (neither directly nor recursively)
      from the result of Item_cache_str::safe_charset_converter().

      For NULLIF() purposes we need a different behavior:
      we need a new instance of Item_func_conv_charset,
      with the original Item_cache referenced in args[0]. See MDEV-9181.
    */
    return Item::safe_charset_converter(thd, tocs);
  }

Project: server

  bool eq(const Item *item, bool binary_cmp) const
  {
    return str_eq(&str_value, item, binary_cmp);
  }

Project: server

  virtual bool cleanup_excluding_const_fields_processor(void *arg) { return cleanup_processor(arg); }

Project: server

  bool walk_args(Item_processor processor, bool walk_subquery, void *arg)
  {
    for (uint i= 0; i < arg_count; i++)
    {
      if (args[i]->walk(processor, walk_subquery, arg))
        return true;
    }
    return false;
  }

Project: server

  Item *get_copy(THD *thd, MEM_ROOT *mem_root)
  { return get_item_copy<Item_int>(thd, mem_root, this); }

Project: server

  enum Type type() const { return DATE_ITEM; }

Project: server

  void make_field(THD *thd, Send_field *)
  {
    illegal_method_call((const char*)"make_field");
  };

Project: server

  table_map used_tables() const { return orig_item->used_tables(); }

Project: server

  virtual void save_org_in_field(Field *field,
                                 fast_field_copier data
                                 __attribute__ ((__unused__)))
  { (void) save_in_field(field, 1); }

Project: server

  Item *get_copy(THD *thd, MEM_ROOT *mem_root)
  { return get_item_copy<Item_decimal>(thd, mem_root, this); }

Project: server

  bool const_item() const { return const_item_cache; }

Project: server

  bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
  {
    if (check_null_ref())
    {
      bzero((char*) ltime,sizeof(*ltime));
      return 1;
    }
    return Item_direct_ref::get_date(ltime, fuzzydate);
  }

Project: server

  inline uint argument_count() const { return arg_count; }

Project: server

  Item_func_or_sum(THD *thd, Item *a, Item *b):
    Item_result_field(thd), Item_args(a, b) { }

Project: server

  Item_result_field(THD *thd): Item(thd), result_field(0) {}

Project: server

  bool agg_arg_charsets(DTCollation &c, Item **items, uint nitems,
                        uint flags, int item_sep)
  {
    if (agg_item_collations(c, func_name(), items, nitems, flags, item_sep))
      return true;

    return agg_item_set_converter(c, func_name(), items, nitems,
                                  flags, item_sep);
  }

Project: server

  bool val_bool()
  {
    if (check_null_ref())
      return 0;
    else
      return Item_direct_ref::val_bool();
  }

Project: server

  Item_args(Item *a, Item *b)
    :args(tmp_arg), arg_count(2)
  {
    args[0]= a; args[1]= b;
  }

Project: server

  virtual Item *clone_item(THD *thd) { return 0; }

Project: server

  virtual ~Item_iterator() {}

Project: server

  Item *next() { return *(list++); }

Project: server

  Item_copy_string(THD *thd, Item *item_arg): Item_copy(thd, item_arg) {}

Project: server

  Item_string(THD *thd, const String *str, CHARSET_INFO *tocs, uint *conv_errors,
              Derivation dv, uint repertoire): Item_basic_constant(thd)
  {
    if (str_value.copy(str, tocs, conv_errors))
      str_value.set("", 0, tocs); // EOM ?
    str_value.mark_as_const();
    fix_and_set_name_from_value(thd, dv, Metadata(&str_value, repertoire));
  }

Project: server

  void fix_and_set_name_from_value(THD *thd, Derivation dv,
                                   const Metadata metadata)
  {
    fix_from_value(dv, metadata);
    set_name(thd, str_value.ptr(), str_value.length(), str_value.charset());
  }

Project: server

  Item_hex_string(THD *thd): Item_hex_constant(thd) {}

Project: server

  double val_real()
  { return val_real_from_date(); }

Project: server

  const char *field_name_or_null()
  { return real_item()->type() == Item::FIELD_ITEM ? name : NULL; }

Project: server

  Item_func_or_sum(THD *thd, Item *a, Item *b, Item *c):
    Item_result_field(thd), Item_args(thd, a, b, c) { }

Project: server

  bool get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
  {
    *ltime= cached_time;
    return (null_value= false);
  }

Project: server

  bool check_partition_func_processor(void *int_arg) {return TRUE;}

Project: server

  virtual String *val_json(String *str) { return val_str(str); }

Project: server

  Item_static_string_func(THD *thd, const char *name_par, const char *str,
                          uint length, CHARSET_INFO *cs,
                          Derivation dv= DERIVATION_COERCIBLE):
    Item_string(thd, NullS, str, length, cs, dv), func_name(name_par)
  {}

Project: server

  Item_default_value(THD *thd, Name_resolution_context *context_arg)
    :Item_field(thd, context_arg, (const char *)NULL, (const char *)NULL,
               (const char *)NULL),
    arg(NULL), cached_field(NULL) {}

Project: server

  void used_tables_and_const_cache_update_and_join(List<Item> &list)
  {
    List_iterator_fast<Item> li(list);
    Item *item;
    while ((item=li++))
      used_tables_and_const_cache_update_and_join(item);
  }

Project: server

  void restore_to_before_no_rows_in_result()
  {
    (*ref)->restore_to_before_no_rows_in_result();
  }

Project: server

  bool save_in_param(THD *thd, Item_param *param)
  {
    param->set_ignore();
    return false;
  }

Project: server

  bool depends_only_on(table_map view_map) 
  { return marker & FULL_EXTRACTION_FL; }

Project: server

  my_decimal *val_decimal_from_item(Item *item, my_decimal *decimal_value)
  {
    DBUG_ASSERT(fixed == 1);
    my_decimal *value= item->val_decimal(decimal_value);
    if ((null_value= item->null_value))
      value= NULL;
    return value;
  }

Project: server

  Rewritable_query_parameter *get_rewritable_query_parameter()
  { return this; }

Project: server

  bool str_eq(const String *value, const Item *item, bool binary_cmp) const
  {
    DBUG_ASSERT(is_basic_value(STRING_ITEM));
    return is_basic_value(item, STRING_ITEM) &&
           str_eq(value, ((Item_basic_value*)item)->val_str(NULL),
                  item->collation.collation, binary_cmp);
  }

Project: server

  virtual bool collect_item_field_processor(void *arg) { return 0; }

Project: server

  bool fix_fields(THD *thd, Item **it)
  {
    DBUG_ASSERT(ident->type() == FIELD_ITEM || ident->type() == REF_ITEM);
    if ((!ident->fixed && ident->fix_fields(thd, ref)) ||
        ident->check_cols(1))
      return TRUE;
    set_properties();
    return FALSE;
  }

Project: server

  Item_equal *get_item_equal() { return item_equal; }

Project: server

  bool convert_time_to_datetime(THD *thd, MYSQL_TIME *ltime, ulonglong fuzzydate)
  {
    MYSQL_TIME tmp;
    if (time_to_datetime_with_warn(thd, ltime, &tmp, fuzzydate))
      return null_value= true;
    *ltime= tmp;
    return false;
  }

Project: server

  virtual bool count_sargable_conds(void *arg) { return 0; }

Project: server

  bool cleanup_is_expensive_cache_processor(void *arg)
  {
    is_expensive_cache= (int8)(-1);
    return 0;
  }

Project: server

  virtual bool add_field_to_set_processor(void *arg) { return 0; }

Project: server

  Item *const_charset_converter(THD *thd, CHARSET_INFO *tocs, bool lossless)
  { return const_charset_converter(thd, tocs, lossless, NULL); }

Project: server

  void set(const Field *field)
  {
    decimals= field->decimals();
    max_length= field->field_length;
    collation.set(field->charset());
    unsigned_flag= MY_TEST(field->flags & UNSIGNED_FLAG);
  }

Project: server

  Load_data_outvar *get_load_data_outvar()
  {
    return this;
  }

Project: server

  virtual Item_equal *find_item_equal(COND_EQUAL *cond_equal) { return NULL; }

Project: server

  bool is_bool_type() { return true; }

Project: server

  static Item_cache* get_cache(THD *thd, const Item *item)
  {
    return get_cache(thd, item, item->cmp_type());
  }

Project: server

  enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; }

Project: server

  virtual bool is_expensive()
  {
    if (is_expensive_cache < 0)
      is_expensive_cache= walk(&Item::is_expensive_processor, 0, NULL);
    return MY_TEST(is_expensive_cache);
  }

Project: server

  virtual Sql_mode_dependency value_depends_on_sql_mode() const
  {
    return Sql_mode_dependency();
  }

Project: server

  Item_func_or_sum(THD *thd, Item *a): Item_result_field(thd), Item_args(a) { }

Project: server

  Item_func_or_sum(THD *thd, Item_func_or_sum *item):
    Item_result_field(thd, item), Item_args(thd, item),
    Used_tables_and_const_cache(item) { }

Project: server

  void fix_after_pullout(st_select_lex *new_parent, Item **refptr, bool merge)
  {
    orig_item->fix_after_pullout(new_parent, &orig_item, merge);
  }

Project: server

  Settable_routine_parameter *get_settable_routine_parameter()
  { return m_is_settable_routine_parameter ? this : NULL; }

Project: server

  bool basic_const_item() const
  { return example && example->basic_const_item(); }

Project: server

  bool check_vcol_func_processor(void *arg) 
  {
    if (example)
    {
      Item::vcol_func_processor_result *res= (Item::vcol_func_processor_result*)arg;
      example->check_vcol_func_processor(arg);
      /*
        Item_cache of a non-deterministic function requires re-fixing
        even if the function itself doesn't (e.g. CURRENT_TIMESTAMP)
      */
      if (res->errors & VCOL_NOT_STRICTLY_DETERMINISTIC)
        res->errors|= VCOL_SESSION_FUNC;
      return false;
    }
    return mark_unsupported_function("cache", arg, VCOL_IMPOSSIBLE);
  }

Project: server

  bool cleanup_excluding_fields_processor(void *arg)
  {
    Item *item= real_item();
    if (item && item->type() == FIELD_ITEM &&
        ((Item_field *)item)->field)
      return 0;
    return cleanup_processor(arg);
  }

Project: server

  virtual bool eliminate_subselect_processor(void *arg) { return 0; }

Project: server

  enum Type real_type() const           { return ref ? (*ref)->type() :
                                          REF_ITEM; }

Project: server

  bool load_data_set_value(THD *thd, const char *pos, uint length,
                           const Load_data_param *param)
  {
    field->load_data_set_value(pos, length, param->charset());
    return false;
  }

Project: server

  bool cleanup_excluding_fields_processor(void *arg)
  { return field ? 0 : cleanup_processor(arg); }

Project: server

  void fix_charset_and_length_from_str_value(Derivation dv)
  {
    fix_charset_and_length_from_str_value(dv, Metadata(&str_value));
  }

Project: server

  CHARSET_INFO *charset_for_protocol(void) const
  {
    return collation.collation;
  }

Project: server

  Item_bool(THD *thd, const char *str_arg, longlong i):
    Item_int(thd, str_arg, i, 1) {}

Project: server

  Item *get_copy(THD *thd, MEM_ROOT *mem_root)
  { return get_item_copy<Item_null>(thd, mem_root, this); }

Project: server

  Item *get_copy(THD *thd, MEM_ROOT *mem_root)
  { return get_item_copy<Item_float>(thd, mem_root, this); }

Project: server

  virtual Item *convert_to_basic_const_item(THD *thd) { return 0; };

Project: server

  bool eq(const Item *item, bool binary_cmp) const
  {
    Item *it= ((Item *) item)->real_item();
    return orig_item->eq(it, binary_cmp);
  }

Project: server

  Item *get_copy(THD *thd, MEM_ROOT *mem_root)
  { return get_item_copy<Item_ref>(thd, mem_root, this); }

Project: server

  bool check_vcol_func_processor(void *arg)
  {
    return mark_unsupported_function("values()", arg, VCOL_IMPOSSIBLE);
  }

Project: server

  bool check_vcol_func_processor(void *arg) 
  {
    return mark_unsupported_function("ref", arg, VCOL_IMPOSSIBLE);
  }

Project: server

  void save_in_result_field(bool no_conversions)
  {
    save_val(result_field);
  }

Project: server

  Item *get_copy(THD *thd, MEM_ROOT *mem_root)
  { return get_item_copy<Item_cache_wrapper>(thd, mem_root, this); }

Project: server

  virtual void make_field(THD *thd, Send_field *field)
  { orig_item->make_field(thd, field); }

Project: server

  Item** addr(uint i)
  { return result_type() == ROW_RESULT ? orig_item->addr(i) : 0; }

Project: server

  Item_field *field_for_view_update()
    { return (*ref)->field_for_view_update(); }

Project: server

  Type_std_attributes(const Type_std_attributes *other)
   :collation(other->collation),
    decimals(other->decimals),
    max_length(other->max_length),
    unsigned_flag(other->unsigned_flag)
  { }

Project: server

  bool value_depends_on_sql_mode_const_item()
  {
    /*
      Currently we use value_depends_on_sql_mode() only for virtual
      column expressions. They should not contain any expensive items.
      If we ever get a crash on the assert below, it means
      check_vcol_func_processor() is badly implemented for this item.
    */
    DBUG_ASSERT(!is_expensive());
    /*
      It should return const_item() actually.
      But for some reasons Item_field::const_item() returns true
      at value_depends_on_sql_mode() call time.
      This should be checked and fixed.
    */
    return basic_const_item();
  }

Project: server

  Item_partition_func_safe_string(THD *thd, const char *name_arg, uint length,
                                  CHARSET_INFO *cs= NULL):
    Item_string(thd, name_arg, length, cs)
  {}

Project: server

  Item *get_example() const { return example; }

Project: server

  virtual bool change_context_processor(void *arg) { return 0; }

Project: server

  virtual Item *derived_grouping_field_transformer_for_where(THD *thd,
                                                             uchar *arg)
  { return this; }

Project: server

  virtual bool check_table_name_processor(void *arg) { return false; }

Project: server

  String *check_well_formed_result(bool send_error)
  { return Item::check_well_formed_result(&str_value, send_error); }

Project: server

  Rewritable_query_parameter(uint pos_in_q= 0, uint len_in_q= 0)
    : pos_in_query(pos_in_q), len_in_query(len_in_q),
      limit_clause_param(false)
  { }

Project: server

  Item_string(THD *thd, const char *name_par, const char *str, uint length,
              CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE):
    Item_basic_constant(thd)
  {
    str_value.set_or_copy_aligned(str, length, cs);
    fix_from_value(dv, Metadata(&str_value));
    set_name(thd, name_par, 0, system_charset_info);
  }

Project: server

  bool null_eq(const Item *item) const
  {
    DBUG_ASSERT(is_basic_value(NULL_ITEM));
    return item->type() == NULL_ITEM;
  }

Project: server

  fast_field_copier setup_fast_field_copier(Field *field)
  { return (*ref)->setup_fast_field_copier(field); }

Project: server

  bool update_vcol_processor(void *arg) { return 0; }

Project: server

  bool walk(Item_processor processor, bool walk_subquery, void *arg)
  {
    if (example && example->walk(processor, walk_subquery, arg))
      return TRUE;
    return (this->*processor)(arg);
  }

Project: server

  Item_iterator_list(List_iterator<Item> &arg_list):
    list(arg_list) {}

Project: server

  void fix_charset_and_length_from_str_value(Derivation dv, Metadata metadata)
  {
    /*
      We have to have a different max_length than 'length' here to
      ensure that we get the right length if we do use the item
      to create a new table. In this case max_length must be the maximum
      number of chars for a string of this type because we in Create_field::
      divide the max_length with mbmaxlen).
    */
    collation.set(str_value.charset(), dv, metadata.repertoire());
    fix_char_length(metadata.char_length());
    decimals= NOT_FIXED_DEC;
  }

Project: server

  void fetch_value_from(Item *new_item)
  {
    Item *save= item;
    item= new_item;
    cmp();
    item= save;
  }

Project: server

  bool is_null()
  { return is_null_from_temporal(); }

Project: server

  Item *derived_field_transformer_for_having(THD *thd, uchar *arg)
  { return convert_to_basic_const_item(thd); }

Project: server

  bool excl_dep_on_table(table_map tab_map)
  { 
    table_map used= used_tables();
    if (used & OUTER_REF_TABLE_BIT)
      return false;
    return (used == tab_map) || (*ref)->excl_dep_on_table(tab_map);
  }

Project: server

  bool has_int_value() const
  {
    return state == INT_VALUE;
  }

Project: server

  Item *derived_field_transformer_for_where(THD *thd, uchar *arg)
  { return convert_to_basic_const_item(thd); }

Project: server

  Item_cache_real(THD *thd): Item_cache(thd, MYSQL_TYPE_DOUBLE),
    value(0) {}

Project: server

  virtual const char *full_name() const { return orig_item->full_name(); }

Project: server

  virtual bool switch_to_nullable_fields_processor(void *arg) { return 0; }

Project: server

  void save_in_result_field(bool no_conversions)
  {
    outer_ref->save_org_in_field(result_field, NULL);
  }

Project: server

  void save_val(Field *to)
  {
    if (check_null_ref())
      to->set_null();
    else
      Item_direct_ref::save_val(to);
  }

Project: server

  Item_hex_hybrid(THD *thd, const char *str, uint str_length):
    Item_hex_constant(thd, str, str_length) {}

Project: server

  enum Item_result result_type () const
  {
    /*
      In 10.1 Item_type_holder::result_type() returned
      Field::result_merge_type(field_type()), which returned STRING_RESULT
      for the BIT data type. In 10.2 it returns INT_RESULT, similar
      to what Field_bit::result_type() does. This should not be
      important because Item_type_holder is a limited purpose Item
      and its result_type() should not be called from outside of
      Item_type_holder. It's called only internally from decimal_int_part()
      from join_types(), to calculate "decimals" of the result data type.
      As soon as we get BIT as one of the joined types, the result field
      type cannot be numeric: it's either BIT, or VARBINARY.
    */
    return Type_handler_hybrid_real_field_type::result_type();
  }

Project: server

  virtual Rewritable_query_parameter *get_rewritable_query_parameter()
  { return 0; }

Project: server

  Item_default_value(THD *thd, Name_resolution_context *context_arg, Item *a)
    :Item_field(thd, context_arg, (const char *)NULL, (const char *)NULL,
                (const char *)NULL),
    arg(a), cached_field(NULL) {}

Project: server

  Item *get_copy(THD *thd, MEM_ROOT *mem_root)
  { return get_item_copy<Item_cache_str_for_nullif>(thd, mem_root, this); }

Project: server

  Item_trigger_field(THD *thd, Name_resolution_context *context_arg,
                     row_version_type row_ver_arg,
                     const char *field_name_arg,
                     ulong priv, const bool ro)
    :Item_field(thd, context_arg,
               (const char *)NULL, (const char *)NULL, field_name_arg),
     row_version(row_ver_arg), field_idx((uint)-1), original_privilege(priv),
     want_privilege(priv), table_grants(NULL), read_only (ro)
  {}

Project: server

  Item_result result_type() const { return type_handler()->result_type(); }

Project: server

    uint repertoire() const { return MY_STRING_METADATA::repertoire; }

Project: server

  Item_ref(THD *thd, Item_ref *item)
    :Item_ident(thd, item), set_properties_only(0), ref(item->ref) {}

Project: server

  Item_temptable_field(THD *thd, Item_field *item) : Item_field(thd, item) {};

Project: server

  virtual bool is_expensive()
  {
    if (value_cached)
      return false;
    return example->is_expensive();
  }

Project: server

  bool is_result_field() { return false; }

Project: server

  Item_string(THD *thd, CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE):
    Item_basic_constant(thd)
  {
    collation.set(cs, dv);
    max_length= 0;
    set_name(thd, NULL, 0, system_charset_info);
    decimals= NOT_FIXED_DEC;
    fixed= 1;
  }

Project: server

  virtual void update_null_value ()
  {
    switch (cmp_type()) {
    case INT_RESULT:
      (void) val_int();
      break;
    case REAL_RESULT:
      (void) val_real();
      break;
    case DECIMAL_RESULT:
      {
        my_decimal tmp;
        (void) val_decimal(&tmp);
      }
      break;
    case TIME_RESULT:
      {
        MYSQL_TIME ltime;
        (void) get_temporal_with_sql_mode(&ltime);
      }
      break;
    case STRING_RESULT:
      {
        StringBuffer<MAX_FIELD_WIDTH> tmp;
        (void) val_str(&tmp);
      }
      break;
    case ROW_RESULT:
      DBUG_ASSERT(0);
      null_value= true;
    }
  }

Project: server

  String *val_str_from_item(Item *item, String *str)
  {
    DBUG_ASSERT(fixed == 1);
    String *res= item->val_str(str);
    if (res)
      res->set_charset(collation.collation);
    if ((null_value= item->null_value))
      res= NULL;
    return res;
  }

Project: server

  virtual bool expr_cache_is_needed(THD *) { return FALSE; }

Project: server

  Item_string_ascii(THD *thd, const char *str):
    Item_string(thd, str, (uint)strlen(str), &my_charset_latin1,
                DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII)
  { }

Project: server

  Item_outer_ref(THD *thd, Name_resolution_context *context_arg,
                 Item_field *outer_field_arg):
    Item_direct_ref(thd, context_arg, 0, outer_field_arg->table_name,
                    outer_field_arg->field_name),
    outer_ref(outer_field_arg), in_sum_func(0),
    found_in_select_list(0), found_in_group_by(0)
  {
    ref= &outer_ref;
    set_properties();
    fixed= 0;                     /* reset flag set in set_properties() */
  }

Project: server

  virtual bool check_func_default_processor(void *arg) { return 0; }

Project: server

  static void operator delete(void *ptr,size_t size) { TRASH_FREE(ptr, size); }

Project: server

  virtual void set_item_equal(Item_equal *item_eq) {};

Project: server

  bool load_data_set_null(THD *thd, const Load_data_param *param)
  {
    return field->load_data_set_null(thd);
  }

Project: server

  bool const_item() const { return true; }

Project: server

  Item_ident_for_show(THD *thd, Field *par_field, const char *db_arg,
                      const char *table_name_arg):
    Item(thd), field(par_field), db_name(db_arg), table_name(table_name_arg)
  {}

Project: server

    Check_table_name_prm(LEX_CSTRING _db, LEX_CSTRING _table_name) :
      db(_db), table_name(_table_name) {}

Project: server

  virtual Item *derived_field_transformer_for_where(THD *thd, uchar *arg)
  { return this; }

Project: server

  Item *build_clone(THD *thd, MEM_ROOT *mem_root) { return 0; }

Project: server

  virtual bool walk(Item_processor processor, bool walk_subquery, void *arg)
  {
    return (this->*processor)(arg);
  }

Project: server

  virtual uint exists2in_reserved_items() { return 0; };

Project: server

  Item_func_or_sum(THD *thd): Item_result_field(thd), Item_args() {}

Project: server

  Item_cache_int(THD *thd, enum_field_types field_type_arg):
    Item_cache(thd, field_type_arg), value(0) {}

Project: server

  double val_real()
  {
    if (check_null_ref())
      return 0;
    else
      return Item_direct_ref::val_real();
  }

Project: server

  bool store(struct st_value *value, ulonglong fuzzydate)
  {
    switch (cmp_type()) {
    case INT_RESULT:
    {
      value->m_type= unsigned_flag ? DYN_COL_UINT : DYN_COL_INT;
      value->value.m_longlong= val_int();
      break;
    }
    case REAL_RESULT:
    {
      value->m_type= DYN_COL_DOUBLE;
      value->value.m_double= val_real();
      break;
    }
    case DECIMAL_RESULT:
    {
      value->m_type= DYN_COL_DECIMAL;
      my_decimal *dec= val_decimal(&value->m_decimal);
      if (dec != &value->m_decimal && !null_value)
        my_decimal2decimal(dec, &value->m_decimal);
      break;
    }
    case STRING_RESULT:
    {
      value->m_type= DYN_COL_STRING;
      String *str= val_str(&value->m_string);
      if (str != &value->m_string && !null_value)
        value->m_string.set(str->ptr(), str->length(), str->charset());
      break;
    }
    case TIME_RESULT:
    {
      value->m_type= DYN_COL_DATETIME;
      get_date(&value->value.m_time, fuzzydate);
      break;
    }
    case ROW_RESULT:
      DBUG_ASSERT(false);
      null_value= true;
      break;
    }
    if (null_value)
    {
      value->m_type= DYN_COL_NULL;
      return true;
    }
    return false;
  }

Project: server

  virtual bool setup(THD *thd, Item *item)
  {
    example= item;
    Type_std_attributes::set(item);
    if (item->type() == FIELD_ITEM)
      cached_field= ((Item_field *)item)->field;
    return 0;
  };

Project: server

  Item_string_sys(THD *thd, const char *str):
    Item_string(thd, str, (uint) strlen(str), system_charset_info)
  { }

Project: server

  longlong val_time_packed_result()
  {
    MYSQL_TIME ltime;
    uint fuzzydate= TIME_TIME_ONLY | TIME_INVALID_DATES | TIME_FUZZY_DATES;
    return get_date_result(&ltime, fuzzydate) ? 0 : pack_time(&ltime);
  }

Project: server

  virtual bool check_inner_refs_processor(void *arg) { return 0; }

Project: server

  void set_item_equal(Item_equal *item_eq) { item_equal= item_eq; }

Project: server

  Longlong_hybrid to_longlong_hybrid()
  {
    return Longlong_hybrid(val_int(), unsigned_flag);
  }

Project: server

  virtual void restore_to_before_no_rows_in_result() {}

Project: server

  bool check_vcol_func_processor(void *int_arg) {return FALSE;}

Project: server

  enum_field_types field_type_for_temporal_comparison(const Item *other) const
  {
    if (cmp_type() == TIME_RESULT)
    {
      if (other->cmp_type() == TIME_RESULT)
        return Field::field_type_merge(field_type(), other->field_type());
      else
        return field_type();
    }
    else
    {
      if (other->cmp_type() == TIME_RESULT)
        return other->field_type();
      DBUG_ASSERT(0); // Two non-temporal data types, we should not get to here
      return MYSQL_TYPE_DATETIME;
    }
  }

Project: server

  bool vcol_assignment_allowed_value() const
  {
    switch (state) {
    case NULL_VALUE:
    case DEFAULT_VALUE:
    case IGNORE_VALUE:
      return true;
    case NO_VALUE:
    case INT_VALUE:
    case REAL_VALUE:
    case STRING_VALUE:
    case TIME_VALUE:
    case LONG_DATA_VALUE:
    case DECIMAL_VALUE:
      break;
    }
    return false;
  }

Project: server

  virtual Item* compile(THD *thd, Item_analyzer analyzer, uchar **arg_p,
                        Item_transformer transformer, uchar *arg_t)
  {
    if ((this->*analyzer) (arg_p))
      return ((this->*transformer) (thd, arg_t));
    return 0;
  }

Project: server

  String *val_str(String* tmp)
  {
    if (check_null_ref())
      return NULL;
    else
      return Item_direct_ref::val_str(tmp);
  }

Project: server

  Item_hex_constant(THD *thd, const char *str, uint str_length):
    Item_basic_constant(thd)
  {
    hex_string_init(thd, str, str_length);
  }

Project: server

  longlong val_int()
  {
    // following assert is redundant, because fixed=1 assigned in constructor
    DBUG_ASSERT(fixed == 1);
    return longlong_from_hex_hybrid(str_value.ptr(), str_value.length());
  }

Project: server

  virtual Load_data_outvar *get_load_data_outvar()
  {
    return 0;
  }

Project: server

  virtual COND *build_equal_items(THD *thd, COND_EQUAL *inheited,
                                  bool link_item_fields,
                                  COND_EQUAL **cond_equal_ref)
  {
    update_used_tables();
    DBUG_ASSERT(!cond_equal_ref || !cond_equal_ref[0]);
    return this;
  }

Project: server

  int save_in_field(Field *field, bool no_conversions)
  { return save_date_in_field(field); }

Project: server

  bool agg_arg_charsets_for_comparison(DTCollation &c,
                                       Item **items, uint nitems,
                                       int item_sep= 1)
  {
    uint flags= MY_COLL_ALLOW_SUPERSET_CONV |
                MY_COLL_ALLOW_COERCIBLE_CONV |
                MY_COLL_DISALLOW_NONE;
    return agg_arg_charsets(c, items, nitems, flags, item_sep);
  }

Project: server

  virtual void add_key_fields(JOIN *join, KEY_FIELD **key_fields,
                              uint *and_level,
                              table_map usable_tables,
                              SARGABLE_PARAM **sargables)
  {
    return;
  }

Project: server

  uint decimal_scale() const
  {
    return decimals < NOT_FIXED_DEC ? decimals :
           is_temporal_type_with_time(field_type()) ?
           TIME_SECOND_PART_DIGITS :
           MY_MIN(max_length, DECIMAL_MAX_SCALE);
  }

Project: server

  Item *get_copy(THD *thd, MEM_ROOT *mem_root)
  { return get_item_copy<Item_direct_view_ref>(thd, mem_root, this); }

Project: server

  Field_enumerator() {}                       /* Remove gcc warning */

Project: server

  inline uint float_length(uint decimals_par) const
  { return decimals < FLOATING_POINT_DECIMALS ? (DBL_DIG+2+decimals_par) : DBL_DIG+8;}

Project: server

  Item_args(THD *thd, Item *a, Item *b, Item *c)
  {
    arg_count= 0;
    if ((args= (Item**) thd_alloc(thd, sizeof(Item*) * 3)))
    {
      arg_count= 3;
      args[0]= a; args[1]= b; args[2]= c;
    }
  }

Project: server

  bool is_result_field() { return true; }

Project: server

  int save_in_field(Field *field, bool no_conversions)
  {
    field->set_notnull();
    return field->store_hex_hybrid(str_value.ptr(), str_value.length());
  }

Project: server

  Item_datetime(THD *thd): Item_int(thd, 0) { unsigned_flag=0; }

Project: server

  virtual bool get_date_result(MYSQL_TIME *ltime, ulonglong fuzzydate)
  { return get_date(ltime,fuzzydate); }

Project: server

  bool view_used_tables_processor(void *arg) 
  {
    TABLE_LIST *view_arg= (TABLE_LIST *) arg;
    if (view_arg == view)
      view_arg->view_used_tables|= (*ref)->used_tables();
    return 0;
  }

Project: server

  bool too_big_for_varchar() const
  { return max_char_length() > CONVERT_IF_BIGGER_TO_BLOB; }