Commit 12a0f4ff authored by unknown's avatar unknown
Browse files

Remove dflt_field from field structure as this was only needed when createing...

Remove dflt_field from field structure as this was only needed when createing temporary table and I found another soultion that doesn't increase the size of the field structure for all table instances. (Better fix for bug #19089)
Fixed compiler warnings
Fixed valgrind warning in Item_date_add_intervall::eq. (Recoding of bugfix #19490)


sql/field.cc:
  remove dflt_field from field structure (not needed)
  Simple cleanup of code that been copied elsewhere
sql/field.h:
  remove dflt_field from field structure (not needed)
sql/item.h:
  Removed compiler warnings
sql/item_timefunc.cc:
  Fixed Item_date_add_intervall::eq
  The problem was that when we call 'eq' 'this' is not fixed, which means we can't call const_item() or a value function.
  I fixed this so that we check eq for all arguments and that the sign and type are identical.
  (The original code gave a 'accessing uninitialized data' in valgrind.
sql/mysql_priv.h:
  Added default fields to create_tmp_field
sql/sql_insert.cc:
  New default_field parameter to create_tmp_field()
sql/sql_select.cc:
  New default_field parameter to create_tmp_field()
  Use this in create_tmp_table() to set right default value for a field
parent fc2e96ee
Loading
Loading
Loading
Loading
+7 −8
Original line number Diff line number Diff line
@@ -1228,7 +1228,7 @@ Field::Field(char *ptr_arg,uint32 length_arg,uchar *null_ptr_arg,
   field_name(field_name_arg),
   query_id(0), key_start(0), part_of_key(0), part_of_sortkey(0),
   unireg_check(unireg_check_arg),
   field_length(length_arg), null_bit(null_bit_arg), dflt_field(0)
   field_length(length_arg), null_bit(null_bit_arg) 
{
  flags=null_ptr ? 0: NOT_NULL_FLAG;
  comment.str= (char*) "";
@@ -8964,22 +8964,21 @@ create_field::create_field(Field *old_field,Field *orig_field)
       old_field->table->timestamp_field != old_field ||  /* timestamp field */ 
       unireg_check == Field::TIMESTAMP_UN_FIELD))        /* has default val */
  {
    char buff[MAX_FIELD_WIDTH],*pos;
    String tmp(buff,sizeof(buff), charset), *res;
    my_ptrdiff_t diff;

    /* Get the value from default_values */
    diff= (my_ptrdiff_t) (orig_field->table->s->default_values-
                          orig_field->table->record[0]);
    orig_field->move_field(diff);		// Points now at default_values
    bool is_null=orig_field->is_real_null();
    res= orig_field->val_str(&tmp);
    orig_field->move_field(-diff);		// Back to record[0]
    if (!is_null)
    if (!orig_field->is_real_null())
    {
      char buff[MAX_FIELD_WIDTH],*pos;
      String tmp(buff,sizeof(buff), charset), *res;
      res= orig_field->val_str(&tmp);
      pos= (char*) sql_strmake(res->ptr(), res->length());
      def= new Item_string(pos, res->length(), charset);
    }
    orig_field->move_field(-diff);		// Back to record[0]
  }
}

+0 −6
Original line number Diff line number Diff line
@@ -53,12 +53,6 @@ class Field

  char		*ptr;			// Position to field in record
  uchar		*null_ptr;		// Byte where null_bit is
  /*
    dflt_field is used only for the fields of temporary tables.
    It points to the default value of the field in another table
    from which this field has been created.
  */ 
  Field         *dflt_field;            // Field to copy default value from
  /*
    Note that you can use table->in_use as replacement for current_thd member 
    only inside of val_*() and store() members (e.g. you can't use it in cons)
+2 −0
Original line number Diff line number Diff line
@@ -388,6 +388,8 @@ class Settable_routine_parameter
                  required, otherwise we only reading it and SELECT
                  privilege might be required.
  */
  Settable_routine_parameter() {}
  virtual ~Settable_routine_parameter() {}
  virtual void set_required_privilege(bool rw) {};

  /*
+4 −32
Original line number Diff line number Diff line
@@ -2130,39 +2130,11 @@ longlong Item_date_add_interval::val_int()

bool Item_date_add_interval::eq(const Item *item, bool binary_cmp) const
{
  INTERVAL interval, other_interval;
  String val= value;   // Because of const

  if (this == item)
    return TRUE;

  if ((item->type() != FUNC_ITEM) ||
      (arg_count != ((Item_func*) item)->arg_count) ||
      (func_name() != ((Item_func*) item)->func_name()))
    return FALSE;

  Item_date_add_interval *other= (Item_date_add_interval*) item;

  if ((int_type != other->int_type) ||
      (!args[0]->eq(other->args[0], binary_cmp)))
    return FALSE;

  if (!args[1]->const_item() || !other->args[1]->const_item())
    return (args[1]->eq(other->args[1], binary_cmp)); 

  if (get_interval_value(args[1], int_type, &val, &interval))
    return FALSE;

  val= other->value;

  if ((get_interval_value(other->args[1], other->int_type, &val,
                         &other_interval)) ||
      ((date_sub_interval ^ interval.neg) ^
       (other->date_sub_interval ^ other_interval.neg)))
    return FALSE;

  // Assume comparing same types here due to earlier check
  return memcmp(&interval, &other_interval, sizeof(INTERVAL)) == 0;
  if (!Item_func::eq(item, binary_cmp))
    return 0;
  return ((int_type == other->int_type) &&
          (date_sub_interval == other->date_sub_interval));
}


+1 −0
Original line number Diff line number Diff line
@@ -704,6 +704,7 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *t);
bool mysql_derived_filling(THD *thd, LEX *lex, TABLE_LIST *t);
Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
			Item ***copy_func, Field **from_field,
                        Field **def_field,
			bool group, bool modify_item,
			bool table_cant_handle_bit_fields,
                        bool make_copy_field,
Loading