Commit acf76e3b authored by unknown's avatar unknown
Browse files

First stage of table definition cache

Split TABLE to TABLE and TABLE_SHARE (TABLE_SHARE is still allocated as part of table, will be fixed soon)
Created Field::make_field() and made Field_num::make_field() to call this
Added 'TABLE_SHARE->db' that points to database name; Changed all usage of table_cache_key as database name to use this instead
Changed field->table_name to point to pointer to alias. This allows us to change alias for a table by just updating one pointer.
Renamed TABLE_SHARE->real_name to table_name
Renamed TABLE->table_name to alias
Renamed TABLE_LIST->real_name to table_name


include/myisam.h:
  Added const before names
mysql-test/r/group_min_max.result:
  Make results repeatable
mysql-test/t/group_min_max.test:
  Make results repeatable
sql/field.cc:
  Created Field::make_field() and made Field_num::make_field() to call this
  Use TABLE_SHARE
  Use sql_strmake() instead of sql_memdup() to simplify code
sql/field.h:
  Changed table_name to be pointer to table_name. This allows us to change alias for all fields by just changing one pointer.
  Use TABLE_SHARE
sql/field_conv.cc:
  Use TABLE_SHARE
sql/filesort.cc:
  Use TABLE_SHARE
sql/ha_berkeley.cc:
  Use TABLE_SHARE
sql/ha_heap.cc:
  Use TABLE_SHARE
sql/ha_innodb.cc:
  Use TABLE_SHARE
sql/ha_myisam.cc:
  Use TABLE_SHARE
sql/ha_myisammrg.cc:
  Use TABLE_SHARE
  Change some pointer handling to use const char*
sql/ha_ndbcluster.cc:
  Use TABLE_SHARE
sql/handler.cc:
  Use TABLE_SHARE
sql/item.cc:
  Use TABLE_SHARE
sql/item_func.cc:
  Use TABLE_SHARE
sql/item_subselect.cc:
  Use TABLE_SHARE
sql/item_sum.cc:
  Use TABLE_SHARE
sql/key.cc:
  Use TABLE_SHARE
sql/lock.cc:
  Use TABLE_SHARE
sql/log_event.cc:
  real_name -> table_name
sql/mysql_priv.h:
  Use TABLE_SHARE
sql/opt_range.cc:
  Use TABLE_SHARE
sql/opt_sum.cc:
  Use TABLE_SHARE
sql/records.cc:
  Use TABLE_SHARE
sql/repl_failsafe.cc:
  real_name -> table_name
sql/slave.cc:
  Use TABLE_SHARE
sql/sp.cc:
  Use TABLE_SHARE
sql/sp_head.cc:
  real_name -> table_name
sql/sql_acl.cc:
  Use TABLE_SHARE
  removed unnecessary assert
  fixed indentation
  changed some char * -> const char*
sql/sql_acl.h:
  changed some char* -> const char*
sql/sql_base.cc:
  Use TABLE_SHARE
sql/sql_cache.cc:
  Use TABLE_SHARE
sql/sql_class.cc:
  Use TABLE_SHARE
sql/sql_db.cc:
  real_name -> table_name
sql/sql_delete.cc:
  Use TABLE_SHARE
sql/sql_derived.cc:
  Use TABLE_SHARE
sql/sql_handler.cc:
  Use TABLE_SHARE
sql/sql_help.cc:
  Use TABLE_SHARE
sql/sql_insert.cc:
  Use TABLE_SHARE
sql/sql_load.cc:
  Use TABLE_SHARE
sql/sql_parse.cc:
  Use TABLE_SHARE
sql/sql_rename.cc:
  real_name -> table_name
sql/sql_select.cc:
  Use TABLE_SHARE
  table->blob_fields now points to field offsets, not fields
  tmp_table->table_name now points to alias name
sql/sql_show.cc:
  Use TABLE_SHARE
sql/sql_table.cc:
  Use TABLE_SHARE
sql/sql_test.cc:
  Use TABLE_SHARE
sql/sql_trigger.cc:
  Use TABLE_SHARE
sql/sql_udf.cc:
  Use TABLE_SHARE
sql/sql_union.cc:
  real_name -> table_name
sql/sql_update.cc:
  Use TABLE_SHARE
sql/sql_view.cc:
  Use TABLE_SHARE
sql/table.cc:
  Split TABLE to TABLE and TABLE_SHARE
  Changed blob_field to be field offsets instead of pointer to fields
  Only initialize table->s->default_values with default record (not all table->record[#])
  Some indentation changes
sql/table.h:
  Split TABLE to TABLE and TABLE_SHARE
sql/tztime.cc:
  real_name -> table_name
sql/unireg.cc:
  Use TABLE_SHARE
sql/unireg.h:
  Use TABLE_SHARE
parent bd365f76
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -340,8 +340,8 @@ typedef struct st_mi_check_param
  ha_checksum key_crc[MI_MAX_POSSIBLE_KEY];
  ulong rec_per_key_part[MI_MAX_KEY_SEG*MI_MAX_POSSIBLE_KEY];
  void *thd;
  char *db_name,*table_name;
  char *op_name;
  const char *db_name, *table_name;
  const char *op_name;
} MI_CHECK;

typedef struct st_sort_ft_buf
+1 −1
Original line number Diff line number Diff line
@@ -148,7 +148,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1	SIMPLE	t1	range	NULL	idx_t1_1	147	NULL	17	Using index for group-by
explain select a1,a2,b,max(c),min(c) from t2 group by a1,a2,b;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	range	NULL	idx_t2_1	163	NULL	21	Using index for group-by
1	SIMPLE	t2	range	NULL	idx_t2_1	#	NULL	21	Using index for group-by
explain select min(a2), a1, max(a2), min(a2), a1 from t1 group by a1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	range	NULL	idx_t1_1	65	NULL	5	Using index for group-by
+1 −0
Original line number Diff line number Diff line
@@ -174,6 +174,7 @@ explain select a1, max(a2) from t1 group by a1;
explain select a1, min(a2), max(a2) from t1 group by a1;
explain select a1, a2, b, min(c), max(c) from t1 group by a1,a2,b;
explain select a1,a2,b,max(c),min(c) from t1 group by a1,a2,b;
--replace_column 7 #
explain select a1,a2,b,max(c),min(c) from t2 group by a1,a2,b;
-- Select fields in different order
explain select min(a2), a1, max(a2), min(a2), a1 from t1 group by a1;
+22 −50
Original line number Diff line number Diff line
@@ -351,10 +351,8 @@ String *Field::val_int_as_str(String *val_buffer, my_bool unsigned_flag)
}


/****************************************************************************
** Functions for the base classes
** This is an unpacked number.
****************************************************************************/
/* This is used as a table name when the table structure is not set up */
const char *unknown_table_name= 0;

Field::Field(char *ptr_arg,uint32 length_arg,uchar *null_ptr_arg,
	     uchar null_bit_arg,
@@ -362,7 +360,7 @@ Field::Field(char *ptr_arg,uint32 length_arg,uchar *null_ptr_arg,
	     struct st_table *table_arg)
  :ptr(ptr_arg),null_ptr(null_ptr_arg),
   table(table_arg),orig_table(table_arg),
   table_name(table_arg ? table_arg->table_name : 0),
   table_name(table_arg ? &table_arg->alias : &unknown_table_name),
   field_name(field_name_arg),
   query_id(0), key_start(0), part_of_key(0), part_of_sortkey(0),
   unireg_check(unireg_check_arg),
@@ -407,35 +405,24 @@ void Field_num::add_zerofill_and_unsigned(String &res) const
    res.append(" zerofill");
}

void Field_num::make_field(Send_field *field)
void Field::make_field(Send_field *field)
{
  /* table_cache_key is not set for temp tables */
  field->db_name= (orig_table->table_cache_key ? orig_table->table_cache_key :
		   "");
  field->org_table_name= orig_table->real_name;
  field->table_name= orig_table->table_name;
  field->db_name= orig_table->s->table_cache_key;
  field->org_table_name= orig_table->s->table_name;
  field->table_name= orig_table->alias;
  field->col_name= field->org_col_name= field_name;
  field->charsetnr= charset()->number;
  field->length=field_length;
  field->type=type();
  field->flags=table->maybe_null ? (flags & ~NOT_NULL_FLAG) : flags;
  field->decimals=dec;
  field->decimals= 0;
}


void Field_str::make_field(Send_field *field)
void Field_num::make_field(Send_field *field)
{
  /* table_cache_key is not set for temp tables */
  field->db_name= (orig_table->table_cache_key ? orig_table->table_cache_key :
		   "");
  field->org_table_name= orig_table->real_name;
  field->table_name= orig_table->table_name;
  field->col_name=field->org_col_name=field_name;
  field->charsetnr= charset()->number;
  field->length=field_length;
  field->type=type();
  field->flags=table->maybe_null ? (flags & ~NOT_NULL_FLAG) : flags;
  field->decimals=0;
  Field::make_field(field);
  field->decimals= dec;
}


@@ -448,7 +435,7 @@ uint Field::fill_cache_field(CACHE_FIELD *copy)
  {
    copy->blob_field=(Field_blob*) this;
    copy->strip=0;
    copy->length-=table->blob_ptr_size;
    copy->length-= table->s->blob_ptr_size;
    return copy->length;
  }
  else if (!zero_pack() &&
@@ -5189,7 +5176,7 @@ Field_blob::Field_blob(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
{
  flags|= BLOB_FLAG;
  if (table)
    table->blob_fields++;
    table->s->blob_fields++;
}


@@ -6295,22 +6282,6 @@ Field *Field_bit::new_key_field(MEM_ROOT *root,
}


void Field_bit::make_field(Send_field *field)
{
  /* table_cache_key is not set for temp tables */
  field->db_name= (orig_table->table_cache_key ? orig_table->table_cache_key :
		   "");
  field->org_table_name= orig_table->real_name;
  field->table_name= orig_table->table_name;
  field->col_name= field->org_col_name= field_name;
  field->charsetnr= charset()->number;
  field->length= field_length;
  field->type= type();
  field->flags= table->maybe_null ? (flags & ~NOT_NULL_FLAG) : flags;
  field->decimals= 0;
}


int Field_bit::store(const char *from, uint length, CHARSET_INFO *cs)
{
  int delta;
@@ -6776,7 +6747,7 @@ create_field::create_field(Field *old_field,Field *orig_field)

  /* Fix if the original table had 4 byte pointer blobs */
  if (flags & BLOB_FLAG)
    pack_length= (pack_length- old_field->table->blob_ptr_size +
    pack_length= (pack_length- old_field->table->s->blob_ptr_size +
		  portable_sizeof_char_ptr);

  switch (sql_type) {
@@ -6824,19 +6795,20 @@ create_field::create_field(Field *old_field,Field *orig_field)
      old_field->ptr && orig_field)
  {
    char buff[MAX_FIELD_WIDTH],*pos;
    String tmp(buff,sizeof(buff), charset);
    String tmp(buff,sizeof(buff), charset), *res;
    my_ptrdiff_t diff;

    /* Get the value from default_values */
    my_ptrdiff_t diff= (my_ptrdiff_t) (orig_field->table->rec_buff_length*2);
    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();
    orig_field->val_str(&tmp);
    res= orig_field->val_str(&tmp);
    orig_field->move_field(-diff);		// Back to record[0]
    if (!is_null)
    {
      pos= (char*) sql_memdup(tmp.ptr(),tmp.length()+1);
      pos[tmp.length()]=0;
      def= new Item_string(pos, tmp.length(), charset);
      pos= (char*) sql_strmake(res->ptr(), res->length());
      def= new Item_string(pos, res->length(), charset);
    }
  }
}
+6 −8
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ class Field
  */
  struct st_table *table;		// Pointer for table
  struct st_table *orig_table;		// Pointer to original table
  const char	*table_name,*field_name;
  const char	**table_name, *field_name;
  LEX_STRING	comment;
  ulong		query_id;		// For quick test of used fields
  /* Field is part of the following keys */
@@ -127,7 +127,7 @@ class Field
  virtual void reset_fields() {}
  virtual void set_default()
  {
    my_ptrdiff_t offset = (my_ptrdiff_t) (table->default_values -
    my_ptrdiff_t offset = (my_ptrdiff_t) (table->s->default_values -
					  table->record[0]);
    memcpy(ptr, ptr + offset, pack_length());
    if (null_ptr)
@@ -176,7 +176,7 @@ class Field
    { if (null_ptr) null_ptr[row_offset]&= (uchar) ~null_bit; }
  inline bool maybe_null(void) { return null_ptr != 0 || table->maybe_null; }
  inline bool real_maybe_null(void) { return null_ptr != 0; }
  virtual void make_field(Send_field *)=0;
  virtual void make_field(Send_field *);
  virtual void sort_string(char *buff,uint length)=0;
  virtual bool optimize_range(uint idx, uint part);
  /*
@@ -355,7 +355,6 @@ class Field_str :public Field {
  int  store(double nr);
  int  store(longlong nr)=0;
  int  store(const char *to,uint length,CHARSET_INFO *cs)=0;
  void make_field(Send_field *);
  uint size_of() const { return sizeof(*this); }
  CHARSET_INFO *charset(void) const { return field_charset; }
  void set_charset(CHARSET_INFO *charset) { field_charset=charset; }
@@ -906,9 +905,9 @@ class Field_string :public Field_str {
  enum_field_types type() const
  {
    return ((orig_table &&
             orig_table->db_create_options & HA_OPTION_PACK_RECORD &&
             orig_table->s->db_create_options & HA_OPTION_PACK_RECORD &&
	     field_length >= 4) &&
            orig_table->frm_version < FRM_VER_TRUE_VARCHAR ?
            orig_table->s->frm_version < FRM_VER_TRUE_VARCHAR ?
	    MYSQL_TYPE_VAR_STRING : MYSQL_TYPE_STRING);
  }
  enum ha_base_keytype key_type() const
@@ -1038,7 +1037,7 @@ class Field_blob :public Field_str {
  uint32 key_length() const { return 0; }
  void sort_string(char *buff,uint length);
  uint32 pack_length() const
  { return (uint32) (packlength+table->blob_ptr_size); }
  { return (uint32) (packlength+table->s->blob_ptr_size); }
  inline uint32 max_data_length() const
  {
    return (uint32) (((ulonglong) 1 << (packlength*8)) -1);
@@ -1212,7 +1211,6 @@ class Field_bit :public Field {
  uint32 max_length() { return (uint32) field_length + (bit_len > 0); }
  uint size_of() const { return sizeof(*this); }
  Item_result result_type () const { return INT_RESULT; }
  void make_field(Send_field *);
  void reset(void) { bzero(ptr, field_length); }
  int store(const char *to, uint length, CHARSET_INFO *charset);
  int store(double nr);
Loading