summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/myisam.h4
-rw-r--r--mysql-test/r/group_min_max.result2
-rw-r--r--mysql-test/t/group_min_max.test1
-rw-r--r--sql/field.cc72
-rw-r--r--sql/field.h14
-rw-r--r--sql/field_conv.cc18
-rw-r--r--sql/filesort.cc4
-rw-r--r--sql/ha_berkeley.cc139
-rw-r--r--sql/ha_heap.cc37
-rw-r--r--sql/ha_innodb.cc56
-rw-r--r--sql/ha_myisam.cc220
-rw-r--r--sql/ha_myisammrg.cc41
-rw-r--r--sql/ha_ndbcluster.cc104
-rw-r--r--sql/handler.cc28
-rw-r--r--sql/item.cc29
-rw-r--r--sql/item_func.cc2
-rw-r--r--sql/item_subselect.cc4
-rw-r--r--sql/item_sum.cc20
-rw-r--r--sql/key.cc12
-rw-r--r--sql/lock.cc17
-rw-r--r--sql/log_event.cc6
-rw-r--r--sql/mysql_priv.h4
-rw-r--r--sql/opt_range.cc78
-rw-r--r--sql/opt_sum.cc2
-rw-r--r--sql/records.cc37
-rw-r--r--sql/repl_failsafe.cc2
-rw-r--r--sql/slave.cc6
-rw-r--r--sql/sp.cc28
-rw-r--r--sql/sp_head.cc4
-rw-r--r--sql/sql_acl.cc146
-rw-r--r--sql/sql_acl.h4
-rw-r--r--sql/sql_base.cc330
-rw-r--r--sql/sql_cache.cc38
-rw-r--r--sql/sql_class.cc2
-rw-r--r--sql/sql_db.cc4
-rw-r--r--sql/sql_delete.cc24
-rw-r--r--sql/sql_derived.cc6
-rw-r--r--sql/sql_handler.cc48
-rw-r--r--sql/sql_help.cc12
-rw-r--r--sql/sql_insert.cc92
-rw-r--r--sql/sql_load.cc6
-rw-r--r--sql/sql_parse.cc52
-rw-r--r--sql/sql_rename.cc4
-rw-r--r--sql/sql_select.cc205
-rw-r--r--sql/sql_show.cc182
-rw-r--r--sql/sql_table.cc133
-rw-r--r--sql/sql_test.cc20
-rw-r--r--sql/sql_trigger.cc10
-rw-r--r--sql/sql_udf.cc12
-rw-r--r--sql/sql_union.cc2
-rw-r--r--sql/sql_update.cc34
-rw-r--r--sql/sql_view.cc42
-rw-r--r--sql/table.cc388
-rw-r--r--sql/table.h205
-rw-r--r--sql/tztime.cc10
-rw-r--r--sql/unireg.cc5
-rw-r--r--sql/unireg.h10
57 files changed, 1542 insertions, 1475 deletions
diff --git a/include/myisam.h b/include/myisam.h
index fd75af2d997..e0eb8715aef 100644
--- a/include/myisam.h
+++ b/include/myisam.h
@@ -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
diff --git a/mysql-test/r/group_min_max.result b/mysql-test/r/group_min_max.result
index 006e7052376..c7be93b0fd7 100644
--- a/mysql-test/r/group_min_max.result
+++ b/mysql-test/r/group_min_max.result
@@ -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
diff --git a/mysql-test/t/group_min_max.test b/mysql-test/t/group_min_max.test
index 17a6cc88597..b42125566d5 100644
--- a/mysql-test/t/group_min_max.test
+++ b/mysql-test/t/group_min_max.test
@@ -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;
diff --git a/sql/field.cc b/sql/field.cc
index a270f102cd5..d15db92e51f 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -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->col_name=field->org_col_name=field_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);
}
}
}
diff --git a/sql/field.h b/sql/field.h
index 9375fbc8d5a..9e690705801 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -47,7 +47,7 @@ public:
*/
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 @@ public:
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 @@ public:
{ 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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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);
diff --git a/sql/field_conv.cc b/sql/field_conv.cc
index 9fd4f0228b3..b337ccd6306 100644
--- a/sql/field_conv.cc
+++ b/sql/field_conv.cc
@@ -487,16 +487,17 @@ void Copy_field::set(Field *to,Field *from,bool save)
void (*Copy_field::get_copy_func(Field *to,Field *from))(Copy_field*)
{
+ bool compatible_db_low_byte_first= (to->table->s->db_low_byte_first ==
+ from->table->s->db_low_byte_first);
if (to->flags & BLOB_FLAG)
{
if (!(from->flags & BLOB_FLAG) || from->charset() != to->charset())
return do_conv_blob;
- if (from_length != to_length ||
- to->table->db_low_byte_first != from->table->db_low_byte_first)
+ if (from_length != to_length || !compatible_db_low_byte_first)
{
// Correct pointer to point at char pointer
- to_ptr+=to_length - to->table->blob_ptr_size;
- from_ptr+=from_length- from->table->blob_ptr_size;
+ to_ptr+= to_length - to->table->s->blob_ptr_size;
+ from_ptr+= from_length- from->table->s->blob_ptr_size;
return do_copy_blob;
}
}
@@ -509,7 +510,7 @@ void (*Copy_field::get_copy_func(Field *to,Field *from))(Copy_field*)
if (from->result_type() == STRING_RESULT)
{
if (to->real_type() != from->real_type() ||
- to->table->db_low_byte_first != from->table->db_low_byte_first)
+ !compatible_db_low_byte_first)
{
if (from->real_type() == FIELD_TYPE_ENUM ||
from->real_type() == FIELD_TYPE_SET)
@@ -541,7 +542,7 @@ void (*Copy_field::get_copy_func(Field *to,Field *from))(Copy_field*)
}
else if (to->real_type() != from->real_type() ||
to_length != from_length ||
- to->table->db_low_byte_first != from->table->db_low_byte_first)
+ !compatible_db_low_byte_first)
{
if (to->real_type() == FIELD_TYPE_DECIMAL ||
to->result_type() == STRING_RESULT)
@@ -552,8 +553,7 @@ void (*Copy_field::get_copy_func(Field *to,Field *from))(Copy_field*)
}
else
{
- if (!to->eq_def(from) ||
- to->table->db_low_byte_first != from->table->db_low_byte_first)
+ if (!to->eq_def(from) || !compatible_db_low_byte_first)
{
if (to->real_type() == FIELD_TYPE_DECIMAL)
return do_field_string;
@@ -587,7 +587,7 @@ void field_conv(Field *to,Field *from)
to->real_type() != FIELD_TYPE_ENUM &&
to->real_type() != FIELD_TYPE_SET &&
from->charset() == to->charset() &&
- to->table->db_low_byte_first == from->table->db_low_byte_first)
+ to->table->s->db_low_byte_first == from->table->s->db_low_byte_first)
{ // Identical fields
memcpy(to->ptr,from->ptr,to->pack_length());
return;
diff --git a/sql/filesort.cc b/sql/filesort.cc
index 569ae3da357..41104106048 100644
--- a/sql/filesort.cc
+++ b/sql/filesort.cc
@@ -127,7 +127,7 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length,
param.ref_length= table->file->ref_length;
param.addon_field= 0;
param.addon_length= 0;
- if (!(table->tmp_table || table->fulltext_searched))
+ if (!(table->s->tmp_table || table->fulltext_searched))
{
/*
Get the descriptors of all fields whose values are appended
@@ -466,7 +466,7 @@ static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select,
if (!flag)
{
my_store_ptr(ref_pos,ref_length,record); // Position to row
- record+=sort_form->db_record_offset;
+ record+= sort_form->s->db_record_offset;
}
else
file->position(sort_form->record[0]);
diff --git a/sql/ha_berkeley.cc b/sql/ha_berkeley.cc
index 322126ff47b..fe266fdbf14 100644
--- a/sql/ha_berkeley.cc
+++ b/sql/ha_berkeley.cc
@@ -490,14 +490,16 @@ int ha_berkeley::open(const char *name, int mode, uint test_if_locked)
{
char name_buff[FN_REFLEN];
uint open_mode=(mode == O_RDONLY ? DB_RDONLY : 0) | DB_THREAD;
+ uint max_key_length;
int error;
+ TABLE_SHARE *table_share= table->s;
DBUG_ENTER("ha_berkeley::open");
/* Open primary key */
hidden_primary_key=0;
- if ((primary_key=table->primary_key) >= MAX_KEY)
+ if ((primary_key= table_share->primary_key) >= MAX_KEY)
{ // No primary key
- primary_key=table->keys;
+ primary_key= table_share->keys;
key_used_on_scan=MAX_KEY;
ref_length=hidden_primary_key=BDB_HIDDEN_PRIMARY_KEY_LENGTH;
}
@@ -505,18 +507,18 @@ int ha_berkeley::open(const char *name, int mode, uint test_if_locked)
key_used_on_scan=primary_key;
/* Need some extra memory in case of packed keys */
- uint max_key_length= table->max_key_length + MAX_REF_PARTS*3;
+ max_key_length= table_share->max_key_length + MAX_REF_PARTS*3;
if (!(alloc_ptr=
my_multi_malloc(MYF(MY_WME),
&key_buff, max_key_length,
&key_buff2, max_key_length,
&primary_key_buff,
(hidden_primary_key ? 0 :
- table->key_info[table->primary_key].key_length),
+ table->key_info[table_share->primary_key].key_length),
NullS)))
DBUG_RETURN(1); /* purecov: inspected */
if (!(rec_buff= (byte*) my_malloc((alloced_rec_buff_length=
- table->rec_buff_length),
+ table_share->rec_buff_length),
MYF(MY_WME))))
{
my_free(alloc_ptr,MYF(0)); /* purecov: inspected */
@@ -524,7 +526,7 @@ int ha_berkeley::open(const char *name, int mode, uint test_if_locked)
}
/* Init shared structure */
- if (!(share=get_share(name,table)))
+ if (!(share= get_share(name,table)))
{
my_free((char*) rec_buff,MYF(0)); /* purecov: inspected */
my_free(alloc_ptr,MYF(0)); /* purecov: inspected */
@@ -537,7 +539,7 @@ int ha_berkeley::open(const char *name, int mode, uint test_if_locked)
/* Fill in shared structure, if needed */
pthread_mutex_lock(&share->mutex);
- file = share->file;
+ file= share->file;
if (!share->use_count++)
{
if ((error=db_create(&file, db_env, 0)))
@@ -548,13 +550,13 @@ int ha_berkeley::open(const char *name, int mode, uint test_if_locked)
my_errno=error; /* purecov: inspected */
DBUG_RETURN(1); /* purecov: inspected */
}
- share->file = file;
+ share->file= file;
file->set_bt_compare(file,
(hidden_primary_key ? berkeley_cmp_hidden_key :
berkeley_cmp_packed_key));
if (!hidden_primary_key)
- file->app_private= (void*) (table->key_info+table->primary_key);
+ file->app_private= (void*) (table->key_info + table_share->primary_key);
if ((error= txn_begin(db_env, 0, (DB_TXN**) &transaction, 0)) ||
(error= (file->open(file, transaction,
fn_format(name_buff, name, "", ha_berkeley_ext,
@@ -562,7 +564,7 @@ int ha_berkeley::open(const char *name, int mode, uint test_if_locked)
"main", DB_BTREE, open_mode, 0))) ||
(error= transaction->commit(transaction, 0)))
{
- free_share(share,table, hidden_primary_key,1); /* purecov: inspected */
+ free_share(share, table, hidden_primary_key,1); /* purecov: inspected */
my_free((char*) rec_buff,MYF(0)); /* purecov: inspected */
my_free(alloc_ptr,MYF(0)); /* purecov: inspected */
my_errno=error; /* purecov: inspected */
@@ -574,7 +576,7 @@ int ha_berkeley::open(const char *name, int mode, uint test_if_locked)
key_type[primary_key]=DB_NOOVERWRITE;
DB **ptr=key_file;
- for (uint i=0, used_keys=0; i < table->keys ; i++, ptr++)
+ for (uint i=0, used_keys=0; i < table_share->keys ; i++, ptr++)
{
char part[7];
if (i != primary_key)
@@ -606,7 +608,7 @@ int ha_berkeley::open(const char *name, int mode, uint test_if_locked)
}
}
/* Calculate pack_length of primary key */
- share->fixed_length_primary_key=1;
+ share->fixed_length_primary_key= 1;
if (!hidden_primary_key)
{
ref_length=0;
@@ -616,18 +618,19 @@ int ha_berkeley::open(const char *name, int mode, uint test_if_locked)
ref_length+= key_part->field->max_packed_col_length(key_part->length);
share->fixed_length_primary_key=
(ref_length == table->key_info[primary_key].key_length);
- share->status|=STATUS_PRIMARY_KEY_INIT;
+ share->status|= STATUS_PRIMARY_KEY_INIT;
}
- share->ref_length=ref_length;
+ share->ref_length= ref_length;
}
- ref_length=share->ref_length; // If second open
+ ref_length= share->ref_length; // If second open
pthread_mutex_unlock(&share->mutex);
transaction=0;
cursor=0;
key_read=0;
block_size=8192; // Berkeley DB block size
- share->fixed_length_row=!(table->db_create_options & HA_OPTION_PACK_RECORD);
+ share->fixed_length_row= !(table_share->db_create_options &
+ HA_OPTION_PACK_RECORD);
get_status();
info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST);
@@ -667,9 +670,15 @@ bool ha_berkeley::fix_rec_buff_for_blob(ulong length)
ulong ha_berkeley::max_row_length(const byte *buf)
{
- ulong length=table->reclength + table->fields*2;
- for (Field_blob **ptr=table->blob_field ; *ptr ; ptr++)
- length+= (*ptr)->get_length((char*) buf+(*ptr)->offset())+2;
+ ulong length= table->s->reclength + table->s->fields*2;
+ uint *ptr, *end;
+ for (ptr= table->s->blob_field, end=ptr + table->s->blob_fields ;
+ ptr != end ;
+ ptr++)
+ {
+ Field_blob *blob= ((Field_blob*) table->field[*ptr]);
+ length+= blob->get_length((char*) buf + blob->offset())+2;
+ }
return length;
}
@@ -685,29 +694,30 @@ ulong ha_berkeley::max_row_length(const byte *buf)
int ha_berkeley::pack_row(DBT *row, const byte *record, bool new_row)
{
+ byte *ptr;
bzero((char*) row,sizeof(*row));
if (share->fixed_length_row)
{
row->data=(void*) record;
- row->size=table->reclength+hidden_primary_key;
+ row->size= table->s->reclength+hidden_primary_key;
if (hidden_primary_key)
{
if (new_row)
get_auto_primary_key(current_ident);
- memcpy_fixed((char*) record+table->reclength, (char*) current_ident,
+ memcpy_fixed((char*) record+table->s->reclength, (char*) current_ident,
BDB_HIDDEN_PRIMARY_KEY_LENGTH);
}
return 0;
}
- if (table->blob_fields)
+ if (table->s->blob_fields)
{
if (fix_rec_buff_for_blob(max_row_length(record)))
return HA_ERR_OUT_OF_MEM; /* purecov: inspected */
}
/* Copy null bits */
- memcpy(rec_buff, record, table->null_bytes);
- byte *ptr=rec_buff + table->null_bytes;
+ memcpy(rec_buff, record, table->s->null_bytes);
+ ptr= rec_buff + table->s->null_bytes;
for (Field **field=table->field ; *field ; field++)
ptr=(byte*) (*field)->pack((char*) ptr,
@@ -730,13 +740,13 @@ int ha_berkeley::pack_row(DBT *row, const byte *record, bool new_row)
void ha_berkeley::unpack_row(char *record, DBT *row)
{
if (share->fixed_length_row)
- memcpy(record,(char*) row->data,table->reclength+hidden_primary_key);
+ memcpy(record,(char*) row->data,table->s->reclength+hidden_primary_key);
else
{
/* Copy null bits */
const char *ptr= (const char*) row->data;
- memcpy(record, ptr, table->null_bytes);
- ptr+=table->null_bytes;
+ memcpy(record, ptr, table->s->null_bytes);
+ ptr+= table->s->null_bytes;
for (Field **field=table->field ; *field ; field++)
ptr= (*field)->unpack(record + (*field)->offset(), ptr);
}
@@ -882,7 +892,7 @@ int ha_berkeley::write_row(byte * record)
DBUG_RETURN(error); /* purecov: inspected */
table->insert_or_update= 1; // For handling of VARCHAR
- if (table->keys + test(hidden_primary_key) == 1)
+ if (table->s->keys + test(hidden_primary_key) == 1)
{
error=file->put(file, transaction, create_key(&prim_key, primary_key,
key_buff, record),
@@ -893,7 +903,8 @@ int ha_berkeley::write_row(byte * record)
{
DB_TXN *sub_trans = transaction;
/* Don't use sub transactions in temporary tables */
- ulong thd_options = table->tmp_table == NO_TMP_TABLE ? table->in_use->options : 0;
+ ulong thd_options= (table->s->tmp_table == NO_TMP_TABLE ?
+ table->in_use->options : 0);
for (uint retry=0 ; retry < berkeley_trans_retry ; retry++)
{
key_map changed_keys(0);
@@ -908,7 +919,7 @@ int ha_berkeley::write_row(byte * record)
&row, key_type[primary_key])))
{
changed_keys.set_bit(primary_key);
- for (uint keynr=0 ; keynr < table->keys ; keynr++)
+ for (uint keynr=0 ; keynr < table->s->keys ; keynr++)
{
if (keynr == primary_key)
continue;
@@ -940,7 +951,8 @@ int ha_berkeley::write_row(byte * record)
else if (!changed_keys.is_clear_all())
{
new_error = 0;
- for (uint keynr=0 ; keynr < table->keys+test(hidden_primary_key) ;
+ for (uint keynr=0;
+ keynr < table->s->keys+test(hidden_primary_key);
keynr++)
{
if (changed_keys.is_set(keynr))
@@ -1090,7 +1102,7 @@ int ha_berkeley::restore_keys(DB_TXN *trans, key_map *changed_keys,
that one just put back the old value. */
if (!changed_keys->is_clear_all())
{
- for (keynr=0 ; keynr < table->keys+test(hidden_primary_key) ; keynr++)
+ for (keynr=0 ; keynr < table->s->keys+test(hidden_primary_key) ; keynr++)
{
if (changed_keys->is_set(keynr))
{
@@ -1117,9 +1129,9 @@ int ha_berkeley::update_row(const byte * old_row, byte * new_row)
DBT prim_key, key, old_prim_key;
int error;
DB_TXN *sub_trans;
- ulong thd_options = table->tmp_table == NO_TMP_TABLE ? table->in_use->options : 0;
+ ulong thd_options= (table->s->tmp_table == NO_TMP_TABLE ?
+ table->in_use->options : 0);
bool primary_key_changed;
-
DBUG_ENTER("update_row");
LINT_INIT(error);
@@ -1163,7 +1175,7 @@ int ha_berkeley::update_row(const byte * old_row, byte * new_row)
thd_options, using_ignore)))
{
// Update all other keys
- for (uint keynr=0 ; keynr < table->keys ; keynr++)
+ for (uint keynr=0 ; keynr < table->s->keys ; keynr++)
{
if (keynr == primary_key)
continue;
@@ -1294,7 +1306,9 @@ int ha_berkeley::remove_keys(DB_TXN *trans, const byte *record,
DBT *new_record, DBT *prim_key, key_map *keys)
{
int result = 0;
- for (uint keynr=0 ; keynr < table->keys+test(hidden_primary_key) ; keynr++)
+ for (uint keynr=0;
+ keynr < table->s->keys+test(hidden_primary_key);
+ keynr++)
{
if (keys->is_set(keynr))
{
@@ -1314,8 +1328,9 @@ int ha_berkeley::delete_row(const byte * record)
{
int error;
DBT row, prim_key;
- key_map keys=table->keys_in_use;
- ulong thd_options = table->tmp_table == NO_TMP_TABLE ? table->in_use->options : 0;
+ key_map keys= table->s->keys_in_use;
+ ulong thd_options= (table->s->tmp_table == NO_TMP_TABLE ?
+ table->in_use->options : 0);
DBUG_ENTER("delete_row");
statistic_increment(table->in_use->status_var.ha_delete_count,&LOCK_status);
@@ -1374,7 +1389,7 @@ int ha_berkeley::index_init(uint keynr)
{
int error;
DBUG_ENTER("ha_berkeley::index_init");
- DBUG_PRINT("enter",("table: '%s' key: %d", table->real_name, keynr));
+ DBUG_PRINT("enter",("table: '%s' key: %d", table->s->table_name, keynr));
/*
Under some very rare conditions (like full joins) we may already have
@@ -1401,7 +1416,7 @@ int ha_berkeley::index_end()
DBUG_ENTER("ha_berkely::index_end");
if (cursor)
{
- DBUG_PRINT("enter",("table: '%s'", table->real_name));
+ DBUG_PRINT("enter",("table: '%s'", table->s->table_name));
error=cursor->c_close(cursor);
cursor=0;
}
@@ -1756,14 +1771,14 @@ void ha_berkeley::info(uint flag)
if ((flag & HA_STATUS_CONST) || version != share->version)
{
version=share->version;
- for (uint i=0 ; i < table->keys ; i++)
+ for (uint i=0 ; i < table->s->keys ; i++)
{
table->key_info[i].rec_per_key[table->key_info[i].key_parts-1]=
share->rec_per_key[i];
}
}
/* Don't return key if we got an error for the internal primary key */
- if (flag & HA_STATUS_ERRKEY && last_dup_key < table->keys)
+ if (flag & HA_STATUS_ERRKEY && last_dup_key < table->s->keys)
errkey= last_dup_key;
DBUG_VOID_RETURN;
}
@@ -2005,9 +2020,9 @@ int ha_berkeley::create(const char *name, register TABLE *form,
if ((error= create_sub_table(name_buff,"main",DB_BTREE,0)))
DBUG_RETURN(error); /* purecov: inspected */
- primary_key=table->primary_key;
+ primary_key= table->s->primary_key;
/* Create the keys */
- for (uint i=0; i < form->keys; i++)
+ for (uint i=0; i < form->s->keys; i++)
{
if (i != primary_key)
{
@@ -2029,7 +2044,7 @@ int ha_berkeley::create(const char *name, register TABLE *form,
"status", DB_BTREE, DB_CREATE, 0))))
{
char rec_buff[4+MAX_KEY*4];
- uint length= 4+ table->keys*4;
+ uint length= 4+ table->s->keys*4;
bzero(rec_buff, length);
error= write_status(status_block, rec_buff, length);
status_block->close(status_block,0);
@@ -2149,9 +2164,9 @@ ulonglong ha_berkeley::get_auto_increment()
(void) ha_berkeley::extra(HA_EXTRA_KEYREAD);
/* Set 'active_index' */
- ha_berkeley::index_init(table->next_number_index);
+ ha_berkeley::index_init(table->s->next_number_index);
- if (!table->next_number_key_offset)
+ if (!table->s->next_number_key_offset)
{ // Autoincrement at key-start
error=ha_berkeley::index_last(table->record[1]);
}
@@ -2164,7 +2179,7 @@ ulonglong ha_berkeley::get_auto_increment()
/* Reading next available number for a sub key */
ha_berkeley::create_key(&last_key, active_index,
key_buff, table->record[0],
- table->next_number_key_offset);
+ table->s->next_number_key_offset);
/* Store for compare */
memcpy(old_key.data=key_buff2, key_buff, (old_key.size=last_key.size));
old_key.app_private=(void*) key_info;
@@ -2193,8 +2208,8 @@ ulonglong ha_berkeley::get_auto_increment()
}
}
if (!error)
- nr=(ulonglong)
- table->next_number_field->val_int_offset(table->rec_buff_length)+1;
+ nr= (ulonglong)
+ table->next_number_field->val_int_offset(table->s->rec_buff_length)+1;
ha_berkeley::index_end();
(void) ha_berkeley::extra(HA_EXTRA_NO_KEYREAD);
return nr;
@@ -2279,7 +2294,7 @@ int ha_berkeley::analyze(THD* thd, HA_CHECK_OPT* check_opt)
free(txn_stat_ptr);
}
- for (i=0 ; i < table->keys ; i++)
+ for (i=0 ; i < table->s->keys ; i++)
{
if (stat)
{
@@ -2414,14 +2429,15 @@ static BDB_SHARE *get_share(const char *table_name, TABLE *table)
char *tmp_name;
DB **key_file;
u_int32_t *key_type;
+ uint keys= table->s->keys;
if ((share=(BDB_SHARE *)
my_multi_malloc(MYF(MY_WME | MY_ZEROFILL),
&share, sizeof(*share),
- &rec_per_key, table->keys * sizeof(ha_rows),
+ &rec_per_key, keys * sizeof(ha_rows),
&tmp_name, length+1,
- &key_file, (table->keys+1) * sizeof(*key_file),
- &key_type, (table->keys+1) * sizeof(u_int32_t),
+ &key_file, (keys+1) * sizeof(*key_file),
+ &key_type, (keys+1) * sizeof(u_int32_t),
NullS)))
{
share->rec_per_key = rec_per_key;
@@ -2448,7 +2464,7 @@ static int free_share(BDB_SHARE *share, TABLE *table, uint hidden_primary_key,
bool mutex_is_locked)
{
int error, result = 0;
- uint keys=table->keys + test(hidden_primary_key);
+ uint keys= table->s->keys + test(hidden_primary_key);
pthread_mutex_lock(&bdb_mutex);
if (mutex_is_locked)
pthread_mutex_unlock(&share->mutex); /* purecov: inspected */
@@ -2512,8 +2528,8 @@ void ha_berkeley::get_status()
}
if (!(share->status & STATUS_ROW_COUNT_INIT) && share->status_block)
{
- share->org_rows=share->rows=
- table->max_rows ? table->max_rows : HA_BERKELEY_MAX_ROWS;
+ share->org_rows= share->rows=
+ table->s->max_rows ? table->s->max_rows : HA_BERKELEY_MAX_ROWS;
if (!share->status_block->cursor(share->status_block, 0, &cursor, 0))
{
DBT row;
@@ -2528,9 +2544,10 @@ void ha_berkeley::get_status()
uint i;
uchar *pos=(uchar*) row.data;
share->org_rows=share->rows=uint4korr(pos); pos+=4;
- for (i=0 ; i < table->keys ; i++)
+ for (i=0 ; i < table->s->keys ; i++)
{
- share->rec_per_key[i]=uint4korr(pos); pos+=4;
+ share->rec_per_key[i]=uint4korr(pos);
+ pos+=4;
}
}
cursor->c_close(cursor);
@@ -2588,7 +2605,7 @@ static void update_status(BDB_SHARE *share, TABLE *table)
{
char rec_buff[4+MAX_KEY*4], *pos=rec_buff;
int4store(pos,share->rows); pos+=4;
- for (uint i=0 ; i < table->keys ; i++)
+ for (uint i=0 ; i < table->s->keys ; i++)
{
int4store(pos,share->rec_per_key[i]); pos+=4;
}
@@ -2622,7 +2639,7 @@ int ha_berkeley::cmp_ref(const byte *ref1, const byte *ref2)
int result;
Field *field;
- KEY *key_info=table->key_info+table->primary_key;
+ KEY *key_info=table->key_info+table->s->primary_key;
KEY_PART_INFO *key_part=key_info->key_part;
KEY_PART_INFO *end=key_part+key_info->key_parts;
diff --git a/sql/ha_heap.cc b/sql/ha_heap.cc
index 1556a18bfca..b5742699d7e 100644
--- a/sql/ha_heap.cc
+++ b/sql/ha_heap.cc
@@ -60,7 +60,7 @@ int ha_heap::open(const char *name, int mode, uint test_if_locked)
{
/* Initialize variables for the opened table */
set_keys_for_scanning();
- if (table->tmp_table == NO_TMP_TABLE)
+ if (table->s->tmp_table == NO_TMP_TABLE)
update_key_stats();
}
return (file ? 0 : 1);
@@ -91,7 +91,7 @@ int ha_heap::close(void)
void ha_heap::set_keys_for_scanning(void)
{
btree_keys.clear_all();
- for (uint i= 0 ; i < table->keys ; i++)
+ for (uint i= 0 ; i < table->s->keys ; i++)
{
if (table->key_info[i].algorithm == HA_KEY_ALG_BTREE)
btree_keys.set_bit(i);
@@ -101,7 +101,7 @@ void ha_heap::set_keys_for_scanning(void)
void ha_heap::update_key_stats()
{
- for (uint i= 0; i < table->keys; i++)
+ for (uint i= 0; i < table->s->keys; i++)
{
KEY *key=table->key_info+i;
if (key->algorithm != HA_KEY_ALG_BTREE)
@@ -124,7 +124,7 @@ int ha_heap::write_row(byte * buf)
if (table->next_number_field && buf == table->record[0])
update_auto_increment();
res= heap_write(file,buf);
- if (!res && table->tmp_table == NO_TMP_TABLE &&
+ if (!res && table->s->tmp_table == NO_TMP_TABLE &&
++records_changed*HEAP_STATS_UPDATE_THRESHOLD > file->s->records)
update_key_stats();
return res;
@@ -137,7 +137,7 @@ int ha_heap::update_row(const byte * old_data, byte * new_data)
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE)
table->timestamp_field->set_time();
res= heap_update(file,old_data,new_data);
- if (!res && table->tmp_table == NO_TMP_TABLE &&
+ if (!res && table->s->tmp_table == NO_TMP_TABLE &&
++records_changed*HEAP_STATS_UPDATE_THRESHOLD > file->s->records)
update_key_stats();
return res;
@@ -148,7 +148,7 @@ int ha_heap::delete_row(const byte * buf)
int res;
statistic_increment(table->in_use->status_var.ha_delete_count,&LOCK_status);
res= heap_delete(file,buf);
- if (!res && table->tmp_table == NO_TMP_TABLE &&
+ if (!res && table->s->tmp_table == NO_TMP_TABLE &&
++records_changed*HEAP_STATS_UPDATE_THRESHOLD > file->s->records)
update_key_stats();
return res;
@@ -282,7 +282,7 @@ int ha_heap::extra(enum ha_extra_function operation)
int ha_heap::delete_all_rows()
{
heap_clear(file);
- if (table->tmp_table == NO_TMP_TABLE)
+ if (table->s->tmp_table == NO_TMP_TABLE)
update_key_stats();
return 0;
}
@@ -448,23 +448,24 @@ ha_rows ha_heap::records_in_range(uint inx, key_range *min_key,
int ha_heap::create(const char *name, TABLE *table_arg,
HA_CREATE_INFO *create_info)
{
- uint key, parts, mem_per_row= 0;
+ uint key, parts, mem_per_row= 0, keys= table_arg->s->keys;
uint auto_key= 0, auto_key_type= 0;
ha_rows max_rows;
HP_KEYDEF *keydef;
HA_KEYSEG *seg;
char buff[FN_REFLEN];
int error;
+ TABLE_SHARE *share= table_arg->s;
- for (key= parts= 0; key < table_arg->keys; key++)
+ for (key= parts= 0; key < keys; key++)
parts+= table_arg->key_info[key].key_parts;
- if (!(keydef= (HP_KEYDEF*) my_malloc(table_arg->keys * sizeof(HP_KEYDEF) +
+ if (!(keydef= (HP_KEYDEF*) my_malloc(keys * sizeof(HP_KEYDEF) +
parts * sizeof(HA_KEYSEG),
MYF(MY_WME))))
return my_errno;
- seg= my_reinterpret_cast(HA_KEYSEG*) (keydef + table_arg->keys);
- for (key= 0; key < table_arg->keys; key++)
+ seg= my_reinterpret_cast(HA_KEYSEG*) (keydef + keys);
+ for (key= 0; key < keys; key++)
{
KEY *pos= table_arg->key_info+key;
KEY_PART_INFO *key_part= pos->key_part;
@@ -516,7 +517,7 @@ int ha_heap::create(const char *name, TABLE *table_arg,
}
}
}
- mem_per_row+= MY_ALIGN(table_arg->reclength + 1, sizeof(char*));
+ mem_per_row+= MY_ALIGN(share->reclength + 1, sizeof(char*));
max_rows = (ha_rows) (table->in_use->variables.max_heap_table_size /
mem_per_row);
HP_CREATE_INFO hp_create_info;
@@ -525,11 +526,11 @@ int ha_heap::create(const char *name, TABLE *table_arg,
hp_create_info.auto_increment= (create_info->auto_increment_value ?
create_info->auto_increment_value - 1 : 0);
error= heap_create(fn_format(buff,name,"","",4+2),
- table_arg->keys,keydef, table_arg->reclength,
- (ulong) ((table_arg->max_rows < max_rows &&
- table_arg->max_rows) ?
- table_arg->max_rows : max_rows),
- (ulong) table_arg->min_rows, &hp_create_info);
+ keys,keydef, share->reclength,
+ (ulong) ((share->max_rows < max_rows &&
+ share->max_rows) ?
+ share->max_rows : max_rows),
+ (ulong) share->min_rows, &hp_create_info);
my_free((gptr) keydef, MYF(0));
if (file)
info(HA_STATUS_NO_LOCK | HA_STATUS_CONST | HA_STATUS_VARIABLE);
diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc
index 91517770d04..31b15f89806 100644
--- a/sql/ha_innodb.cc
+++ b/sql/ha_innodb.cc
@@ -1768,7 +1768,7 @@ ha_innobase::open(
fields when packed actually became 1 byte longer, when we also
stored the string length as the first byte. */
- upd_and_key_val_buff_len = table->reclength + table->max_key_length
+ upd_and_key_val_buff_len = table->s->reclength + table->s->max_key_length
+ MAX_REF_PARTS * 3;
if (!(mysql_byte*) my_multi_malloc(MYF(MY_WME),
&upd_buff, upd_and_key_val_buff_len,
@@ -1820,11 +1820,11 @@ ha_innobase::open(
innobase_prebuilt = row_create_prebuilt(ib_table);
- ((row_prebuilt_t*)innobase_prebuilt)->mysql_row_len = table->reclength;
+ ((row_prebuilt_t*)innobase_prebuilt)->mysql_row_len = table->s->reclength;
/* Looks like MySQL-3.23 sometimes has primary key number != 0 */
- primary_key = table->primary_key;
+ primary_key = table->s->primary_key;
key_used_on_scan = primary_key;
/* Allocate a buffer for a 'row reference'. A row reference is
@@ -1995,7 +1995,7 @@ reset_null_bits(
TABLE* table, /* in: MySQL table object */
char* record) /* in: a row in MySQL format */
{
- bzero(record, table->null_bytes);
+ bzero(record, table->s->null_bytes);
}
extern "C" {
@@ -2349,7 +2349,7 @@ build_template(
the clustered index */
}
- n_fields = (ulint)table->fields; /* number of columns */
+ n_fields = (ulint)table->s->fields; /* number of columns */
if (!prebuilt->mysql_template) {
prebuilt->mysql_template = (mysql_row_templ_t*)
@@ -2358,7 +2358,7 @@ build_template(
}
prebuilt->template_type = templ_type;
- prebuilt->null_bitmap_len = table->null_bytes;
+ prebuilt->null_bitmap_len = table->s->null_bytes;
prebuilt->templ_contains_blob = FALSE;
@@ -2725,7 +2725,7 @@ calc_row_difference(
ulint n_changed = 0;
uint i;
- n_fields = table->fields;
+ n_fields = table->s->fields;
/* We use upd_buff to convert changed fields */
buf = (byte*) upd_buff;
@@ -3215,7 +3215,7 @@ ha_innobase::change_active_index(
active_index = keynr;
- if (keynr != MAX_KEY && table->keys > 0) {
+ if (keynr != MAX_KEY && table->s->keys > 0) {
key = table->key_info + active_index;
prebuilt->index = dict_table_get_index_noninline(
@@ -3635,7 +3635,7 @@ create_table_def(
DBUG_ENTER("create_table_def");
DBUG_PRINT("enter", ("table_name: %s", table_name));
- n_cols = form->fields;
+ n_cols = form->s->fields;
/* We pass 0 as the space id, and determine at a lower level the space
id where to store the table */
@@ -3727,7 +3727,7 @@ create_index(
ind_type = 0;
- if (key_num == form->primary_key) {
+ if (key_num == form->s->primary_key) {
ind_type = ind_type | DICT_CLUSTERED;
}
@@ -3750,7 +3750,7 @@ create_index(
the length of the key part versus the column. */
field = NULL;
- for (j = 0; j < form->fields; j++) {
+ for (j = 0; j < form->s->fields; j++) {
field = form->field[j];
@@ -3763,7 +3763,7 @@ create_index(
}
}
- ut_a(j < form->fields);
+ ut_a(j < form->s->fields);
col_type = get_innobase_type_from_mysql_type(key_part->field);
@@ -3857,7 +3857,7 @@ ha_innobase::create(
DBUG_ASSERT(thd != NULL);
- if (form->fields > 1000) {
+ if (form->s->fields > 1000) {
/* The limit probably should be REC_MAX_N_FIELDS - 3 = 1020,
but we play safe here */
@@ -3907,7 +3907,7 @@ ha_innobase::create(
error = create_table_def(trx, form, norm_name,
create_info->options & HA_LEX_CREATE_TMP_TABLE ? name2 : NULL,
- !(form->db_options_in_use & HA_OPTION_PACK_RECORD));
+ !(form->s->db_options_in_use & HA_OPTION_PACK_RECORD));
if (error) {
innobase_commit_low(trx);
@@ -3921,8 +3921,8 @@ ha_innobase::create(
/* Look for a primary key */
- primary_key_no= (table->primary_key != MAX_KEY ?
- (int) table->primary_key :
+ primary_key_no= (table->s->primary_key != MAX_KEY ?
+ (int) table->s->primary_key :
-1);
/* Our function row_get_mysql_key_number_for_index assumes
@@ -3932,7 +3932,7 @@ ha_innobase::create(
/* Create the keys */
- if (form->keys == 0 || primary_key_no == -1) {
+ if (form->s->keys == 0 || primary_key_no == -1) {
/* Create an index which is used as the clustered index;
order the rows by their row id which is internally generated
by InnoDB */
@@ -3965,7 +3965,7 @@ ha_innobase::create(
}
}
- for (i = 0; i < form->keys; i++) {
+ for (i = 0; i < form->s->keys; i++) {
if (i != (uint) primary_key_no) {
@@ -4330,11 +4330,11 @@ ha_innobase::records_in_range(
KEY* key;
dict_index_t* index;
mysql_byte* key_val_buff2 = (mysql_byte*) my_malloc(
- table->reclength
- + table->max_key_length + 100,
+ table->s->reclength
+ + table->s->max_key_length + 100,
MYF(MY_WME));
- ulint buff2_len = table->reclength
- + table->max_key_length + 100;
+ ulint buff2_len = table->s->reclength
+ + table->s->max_key_length + 100;
dtuple_t* range_start;
dtuple_t* range_end;
ib_longlong n_rows;
@@ -4491,7 +4491,7 @@ ha_innobase::read_time(
ha_rows total_rows;
double time_for_scan;
- if (index != table->primary_key)
+ if (index != table->s->primary_key)
return handler::read_time(index, ranges, rows); // Not clustered
if (rows <= 2)
@@ -4610,7 +4610,7 @@ ha_innobase::info(
index = dict_table_get_next_index_noninline(index);
}
- for (i = 0; i < table->keys; i++) {
+ for (i = 0; i < table->s->keys; i++) {
if (index == NULL) {
ut_print_timestamp(stderr);
fprintf(stderr,
@@ -5803,7 +5803,7 @@ ha_innobase::innobase_read_and_init_auto_inc(
}
(void) extra(HA_EXTRA_KEYREAD);
- index_init(table->next_number_index);
+ index_init(table->s->next_number_index);
/* We use an exclusive lock when we read the max key value from the
auto-increment column index. This is because then build_template will
@@ -5838,7 +5838,7 @@ ha_innobase::innobase_read_and_init_auto_inc(
} else {
/* Initialize to max(col) + 1 */
auto_inc = (longlong) table->next_number_field->
- val_int_offset(table->rec_buff_length) + 1;
+ val_int_offset(table->s->rec_buff_length) + 1;
}
dict_table_autoinc_initialize(prebuilt->table, auto_inc);
@@ -5925,9 +5925,9 @@ ha_innobase::cmp_ref(
/* Do type-aware comparison of Primary Key members. PK members
are always NOT NULL, so no checks for NULL are performed */
- KEY_PART_INFO *key_part= table->key_info[table->primary_key].key_part;
+ KEY_PART_INFO *key_part= table->key_info[table->s->primary_key].key_part;
KEY_PART_INFO *key_part_end=
- key_part + table->key_info[table->primary_key].key_parts;
+ key_part + table->key_info[table->s->primary_key].key_parts;
for (; key_part != key_part_end; ++key_part) {
field = key_part->field;
mysql_type = field->type();
diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc
index c89eb4426ff..87329c6f4af 100644
--- a/sql/ha_myisam.cc
+++ b/sql/ha_myisam.cc
@@ -233,7 +233,7 @@ int ha_myisam::open(const char *name, int mode, uint test_if_locked)
info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST);
if (!(test_if_locked & HA_OPEN_WAIT_IF_LOCKED))
VOID(mi_extra(file, HA_EXTRA_WAIT_LOCK, 0));
- if (!table->db_record_offset)
+ if (!table->s->db_record_offset)
int_table_flags|=HA_REC_NOT_IN_SEQ;
if (file->s->options & (HA_OPTION_CHECKSUM | HA_OPTION_COMPRESS_RECORD))
int_table_flags|=HA_HAS_CHECKSUM;
@@ -275,9 +275,9 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt)
thd->proc_info="Checking table";
myisamchk_init(&param);
param.thd = thd;
- param.op_name = (char*)"check";
- param.db_name = table->table_cache_key;
- param.table_name = table->table_name;
+ param.op_name = "check";
+ param.db_name= table->s->db;
+ param.table_name= table->alias;
param.testflag = check_opt->flags | T_CHECK | T_SILENT;
if (!(table->db_stat & HA_READ_ONLY))
@@ -362,11 +362,11 @@ int ha_myisam::analyze(THD *thd, HA_CHECK_OPT* check_opt)
myisamchk_init(&param);
param.thd = thd;
- param.op_name = (char*) "analyze";
- param.db_name = table->table_cache_key;
- param.table_name = table->table_name;
- param.testflag=(T_FAST | T_CHECK | T_SILENT | T_STATISTICS |
- T_DONT_CHECK_CHECKSUM);
+ param.op_name= "analyze";
+ param.db_name= table->s->db;
+ param.table_name= table->alias;
+ param.testflag= (T_FAST | T_CHECK | T_SILENT | T_STATISTICS |
+ T_DONT_CHECK_CHECKSUM);
param.using_global_keycache = 1;
if (!(share->state.changed & STATE_NOT_ANALYZED))
@@ -388,9 +388,9 @@ int ha_myisam::analyze(THD *thd, HA_CHECK_OPT* check_opt)
int ha_myisam::restore(THD* thd, HA_CHECK_OPT *check_opt)
{
HA_CHECK_OPT tmp_check_opt;
- char* backup_dir= thd->lex->backup_dir;
+ char *backup_dir= thd->lex->backup_dir;
char src_path[FN_REFLEN], dst_path[FN_REFLEN];
- char* table_name = table->real_name;
+ const char *table_name= table->s->table_name;
int error;
const char* errmsg;
DBUG_ENTER("restore");
@@ -399,11 +399,11 @@ int ha_myisam::restore(THD* thd, HA_CHECK_OPT *check_opt)
MI_NAME_DEXT))
DBUG_RETURN(HA_ADMIN_INVALID);
- if (my_copy(src_path, fn_format(dst_path, table->path, "",
+ if (my_copy(src_path, fn_format(dst_path, table->s->path, "",
MI_NAME_DEXT, 4), MYF(MY_WME)))
{
- error = HA_ADMIN_FAILED;
- errmsg = "Failed in my_copy (Error %d)";
+ error= HA_ADMIN_FAILED;
+ errmsg= "Failed in my_copy (Error %d)";
goto err;
}
@@ -415,11 +415,11 @@ int ha_myisam::restore(THD* thd, HA_CHECK_OPT *check_opt)
{
MI_CHECK param;
myisamchk_init(&param);
- param.thd = thd;
- param.op_name = (char*)"restore";
- param.db_name = table->table_cache_key;
- param.table_name = table->table_name;
- param.testflag = 0;
+ param.thd= thd;
+ param.op_name= "restore";
+ param.db_name= table->s->db;
+ param.table_name= table->s->table_name;
+ param.testflag= 0;
mi_check_print_error(&param, errmsg, my_errno);
DBUG_RETURN(error);
}
@@ -428,9 +428,9 @@ int ha_myisam::restore(THD* thd, HA_CHECK_OPT *check_opt)
int ha_myisam::backup(THD* thd, HA_CHECK_OPT *check_opt)
{
- char* backup_dir= thd->lex->backup_dir;
+ char *backup_dir= thd->lex->backup_dir;
char src_path[FN_REFLEN], dst_path[FN_REFLEN];
- char* table_name = table->real_name;
+ const char *table_name= table->s->table_name;
int error;
const char *errmsg;
DBUG_ENTER("ha_myisam::backup");
@@ -438,12 +438,13 @@ int ha_myisam::backup(THD* thd, HA_CHECK_OPT *check_opt)
if (fn_format_relative_to_data_home(dst_path, table_name, backup_dir,
reg_ext))
{
- errmsg = "Failed in fn_format() for .frm file (errno: %d)";
- error = HA_ADMIN_INVALID;
+ errmsg= "Failed in fn_format() for .frm file (errno: %d)";
+ error= HA_ADMIN_INVALID;
goto err;
}
- if (my_copy(fn_format(src_path, table->path,"", reg_ext, MY_UNPACK_FILENAME),
+ if (my_copy(fn_format(src_path, table->s->path, "", reg_ext,
+ MY_UNPACK_FILENAME),
dst_path,
MYF(MY_WME | MY_HOLD_ORIGINAL_MODES | MY_DONT_OVERWRITE_FILE)))
{
@@ -461,7 +462,7 @@ int ha_myisam::backup(THD* thd, HA_CHECK_OPT *check_opt)
goto err;
}
- if (my_copy(fn_format(src_path, table->path,"", MI_NAME_DEXT,
+ if (my_copy(fn_format(src_path, table->s->path, "", MI_NAME_DEXT,
MY_UNPACK_FILENAME),
dst_path,
MYF(MY_WME | MY_HOLD_ORIGINAL_MODES | MY_DONT_OVERWRITE_FILE)))
@@ -476,11 +477,11 @@ int ha_myisam::backup(THD* thd, HA_CHECK_OPT *check_opt)
{
MI_CHECK param;
myisamchk_init(&param);
- param.thd = thd;
- param.op_name = (char*)"backup";
- param.db_name = table->table_cache_key;
- param.table_name = table->table_name;
- param.testflag = 0;
+ param.thd= thd;
+ param.op_name= "backup";
+ param.db_name= table->s->db;
+ param.table_name= table->s->table_name;
+ param.testflag = 0;
mi_check_print_error(&param,errmsg, my_errno);
DBUG_RETURN(error);
}
@@ -497,10 +498,10 @@ int ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt)
myisamchk_init(&param);
param.thd = thd;
- param.op_name = (char*) "repair";
- param.testflag = ((check_opt->flags & ~(T_EXTEND)) |
- T_SILENT | T_FORCE_CREATE | T_CALC_CHECKSUM |
- (check_opt->flags & T_EXTEND ? T_REP : T_REP_BY_SORT));
+ param.op_name= "repair";
+ param.testflag= ((check_opt->flags & ~(T_EXTEND)) |
+ T_SILENT | T_FORCE_CREATE | T_CALC_CHECKSUM |
+ (check_opt->flags & T_EXTEND ? T_REP : T_REP_BY_SORT));
param.sort_buffer_length= check_opt->sort_buffer_size;
start_records=file->state->records;
while ((error=repair(thd,param,0)) && param.retry_repair)
@@ -511,7 +512,7 @@ int ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt)
{
param.testflag&= ~T_RETRY_WITHOUT_QUICK;
sql_print_information("Retrying repair of: '%s' without quick",
- table->path);
+ table->s->path);
continue;
}
param.testflag&= ~T_QUICK;
@@ -519,7 +520,7 @@ int ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt)
{
param.testflag= (param.testflag & ~T_REP_BY_SORT) | T_REP;
sql_print_information("Retrying repair of: '%s' with keycache",
- table->path);
+ table->s->path);
continue;
}
break;
@@ -531,7 +532,7 @@ int ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt)
sql_print_information("Found %s of %s rows when repairing '%s'",
llstr(file->state->records, llbuff),
llstr(start_records, llbuff2),
- table->path);
+ table->s->path);
}
return error;
}
@@ -544,9 +545,9 @@ int ha_myisam::optimize(THD* thd, HA_CHECK_OPT *check_opt)
myisamchk_init(&param);
param.thd = thd;
- param.op_name = (char*) "optimize";
- param.testflag = (check_opt->flags | T_SILENT | T_FORCE_CREATE |
- T_REP_BY_SORT | T_STATISTICS | T_SORT_INDEX);
+ param.op_name= "optimize";
+ param.testflag= (check_opt->flags | T_SILENT | T_FORCE_CREATE |
+ T_REP_BY_SORT | T_STATISTICS | T_SORT_INDEX);
param.sort_buffer_length= check_opt->sort_buffer_size;
if ((error= repair(thd,param,1)) && param.retry_repair)
{
@@ -570,18 +571,18 @@ int ha_myisam::repair(THD *thd, MI_CHECK &param, bool optimize)
ha_rows rows= file->state->records;
DBUG_ENTER("ha_myisam::repair");
- param.db_name = table->table_cache_key;
- param.table_name = table->table_name;
+ param.db_name= table->s->db;
+ param.table_name= table->alias;
param.tmpfile_createflag = O_RDWR | O_TRUNC;
param.using_global_keycache = 1;
- param.thd=thd;
- param.tmpdir=&mysql_tmpdir_list;
- param.out_flag=0;
+ param.thd= thd;
+ param.tmpdir= &mysql_tmpdir_list;
+ param.out_flag= 0;
strmov(fixed_name,file->filename);
// Don't lock tables if we have used LOCK TABLE
if (!thd->locked_tables &&
- mi_lock_database(file, table->tmp_table ? F_EXTRA_LCK : F_WRLCK))
+ mi_lock_database(file, table->s->tmp_table ? F_EXTRA_LCK : F_WRLCK))
{
mi_check_print_error(&param,ER(ER_CANT_LOCK),my_errno);
DBUG_RETURN(HA_ADMIN_FAILED);
@@ -740,9 +741,9 @@ int ha_myisam::assign_to_keycache(THD* thd, HA_CHECK_OPT *check_opt)
MI_CHECK param;
myisamchk_init(&param);
param.thd= thd;
- param.op_name= (char*)"assign_to_keycache";
- param.db_name= table->table_cache_key;
- param.table_name= table->table_name;
+ param.op_name= "assign_to_keycache";
+ param.db_name= table->s->db;
+ param.table_name= table->s->table_name;
param.testflag= 0;
mi_check_print_error(&param, errmsg);
}
@@ -808,10 +809,10 @@ int ha_myisam::preload_keys(THD* thd, HA_CHECK_OPT *check_opt)
MI_CHECK param;
myisamchk_init(&param);
param.thd= thd;
- param.op_name= (char*)"preload_keys";
- param.db_name= table->table_cache_key;
- param.table_name= table->table_name;
- param.testflag= 0;
+ param.op_name= "preload_keys";
+ param.db_name= table->s->db;
+ param.table_name= table->s->table_name;
+ param.testflag= 0;
mi_check_print_error(&param, errmsg);
DBUG_RETURN(error);
}
@@ -916,9 +917,9 @@ int ha_myisam::enable_indexes(uint mode)
const char *save_proc_info=thd->proc_info;
thd->proc_info="Creating index";
myisamchk_init(&param);
- param.op_name = (char*) "recreating_index";
- param.testflag = (T_SILENT | T_REP_BY_SORT | T_QUICK |
- T_CREATE_MISSING_KEYS);
+ param.op_name= "recreating_index";
+ param.testflag= (T_SILENT | T_REP_BY_SORT | T_QUICK |
+ T_CREATE_MISSING_KEYS);
param.myf_rw&= ~MY_WAIT_IF_FULL;
param.sort_buffer_length= thd->variables.myisam_sort_buff_size;
param.tmpdir=&mysql_tmpdir_list;
@@ -983,8 +984,9 @@ int ha_myisam::indexes_are_disabled(void)
void ha_myisam::start_bulk_insert(ha_rows rows)
{
DBUG_ENTER("ha_myisam::start_bulk_insert");
- THD *thd=current_thd;
- ulong size= min(thd->variables.read_buff_size, table->avg_row_length*rows);
+ THD *thd= current_thd;
+ ulong size= min(thd->variables.read_buff_size,
+ table->s->avg_row_length*rows);
DBUG_PRINT("info",("start_bulk_insert: rows %lu size %lu",
(ulong) rows, size));
@@ -1052,18 +1054,18 @@ bool ha_myisam::check_and_repair(THD *thd)
// Don't use quick if deleted rows
if (!file->state->del && (myisam_recover_options & HA_RECOVER_QUICK))
check_opt.flags|=T_QUICK;
- sql_print_warning("Checking table: '%s'",table->path);
+ sql_print_warning("Checking table: '%s'",table->s->path);
old_query= thd->query;
old_query_length= thd->query_length;
pthread_mutex_lock(&LOCK_thread_count);
- thd->query= table->real_name;
- thd->query_length= strlen(table->real_name);
+ thd->query= (char*) table->s->table_name;
+ thd->query_length= strlen(table->s->table_name);
pthread_mutex_unlock(&LOCK_thread_count);
if ((marked_crashed= mi_is_crashed(file)) || check(thd, &check_opt))
{
- sql_print_warning("Recovering table: '%s'",table->path);
+ sql_print_warning("Recovering table: '%s'",table->s->path);
check_opt.flags=
((myisam_recover_options & HA_RECOVER_BACKUP ? T_BACKUP_DATA : 0) |
(marked_crashed ? 0 : T_QUICK) |
@@ -1237,25 +1239,25 @@ void ha_myisam::info(uint flag)
}
if (flag & HA_STATUS_CONST)
{
- max_data_file_length=info.max_data_file_length;
- max_index_file_length=info.max_index_file_length;
- create_time = info.create_time;
- sortkey = info.sortkey;
- ref_length=info.reflength;
- table->db_options_in_use = info.options;
- block_size=myisam_block_size;
- table->keys_in_use.set_prefix(table->keys);
- table->keys_in_use.intersect(info.key_map);
- table->keys_for_keyread= table->keys_in_use;
- table->keys_for_keyread.subtract(table->read_only_keys);
- table->db_record_offset=info.record_offset;
- if (table->key_parts)
+ TABLE_SHARE *share= table->s;
+ max_data_file_length= info.max_data_file_length;
+ max_index_file_length= info.max_index_file_length;
+ create_time= info.create_time;
+ sortkey= info.sortkey;
+ ref_length= info.reflength;
+ share->db_options_in_use= info.options;
+ block_size= myisam_block_size;
+ share->keys_in_use.set_prefix(share->keys);
+ share->keys_in_use.intersect(info.key_map);
+ share->keys_for_keyread.intersect(share->keys_in_use);
+ share->db_record_offset= info.record_offset;
+ if (share->key_parts)
memcpy((char*) table->key_info[0].rec_per_key,
(char*) info.rec_per_key,
- sizeof(table->key_info[0].rec_per_key)*table->key_parts);
- raid_type=info.raid_type;
- raid_chunks=info.raid_chunks;
- raid_chunksize=info.raid_chunksize;
+ sizeof(table->key_info[0].rec_per_key)*share->key_parts);
+ raid_type= info.raid_type;
+ raid_chunks= info.raid_chunks;
+ raid_chunksize= info.raid_chunksize;
/*
Set data_file_name and index_file_name to point at the symlink value
@@ -1311,7 +1313,7 @@ int ha_myisam::delete_table(const char *name)
int ha_myisam::external_lock(THD *thd, int lock_type)
{
- return mi_lock_database(file, !table->tmp_table ?
+ return mi_lock_database(file, !table->s->tmp_table ?
lock_type : ((lock_type == F_UNLCK) ?
F_UNLCK : F_EXTRA_LCK));
}
@@ -1356,21 +1358,23 @@ int ha_myisam::create(const char *name, register TABLE *table_arg,
MI_KEYDEF *keydef;
MI_COLUMNDEF *recinfo,*recinfo_pos;
HA_KEYSEG *keyseg;
- uint options=table_arg->db_options_in_use;
+ TABLE_SHARE *share= table->s;
+ uint options= share->db_options_in_use;
DBUG_ENTER("ha_myisam::create");
type=HA_KEYTYPE_BINARY; // Keep compiler happy
if (!(my_multi_malloc(MYF(MY_WME),
- &recinfo,(table_arg->fields*2+2)*sizeof(MI_COLUMNDEF),
- &keydef, table_arg->keys*sizeof(MI_KEYDEF),
+ &recinfo,(share->fields*2+2)*
+ sizeof(MI_COLUMNDEF),
+ &keydef, share->keys*sizeof(MI_KEYDEF),
&keyseg,
- ((table_arg->key_parts + table_arg->keys) *
+ ((share->key_parts + share->keys) *
sizeof(HA_KEYSEG)),
NullS)))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
pos=table_arg->key_info;
- for (i=0; i < table_arg->keys ; i++, pos++)
+ for (i=0; i < share->keys ; i++, pos++)
{
keydef[i].flag= (pos->flags & (HA_NOSAME | HA_FULLTEXT | HA_SPATIAL));
keydef[i].key_alg= pos->algorithm == HA_KEY_ALG_UNDEF ?
@@ -1431,7 +1435,7 @@ int ha_myisam::create(const char *name, register TABLE *table_arg,
keydef[i].seg[j].flag|=HA_BLOB_PART;
/* save number of bytes used to pack length */
keydef[i].seg[j].bit_start= (uint) (field->pack_length() -
- table_arg->blob_ptr_size);
+ share->blob_ptr_size);
}
else if (field->type() == FIELD_TYPE_BIT)
{
@@ -1446,15 +1450,16 @@ int ha_myisam::create(const char *name, register TABLE *table_arg,
if (table_arg->found_next_number_field)
{
- keydef[table_arg->next_number_index].flag|= HA_AUTO_KEY;
- found_real_auto_increment= table_arg->next_number_key_offset == 0;
+ keydef[share->next_number_index].flag|= HA_AUTO_KEY;
+ found_real_auto_increment= share->next_number_key_offset == 0;
}
recpos=0; recinfo_pos=recinfo;
- while (recpos < (uint) table_arg->reclength)
+ while (recpos < (uint) share->reclength)
{
Field **field,*found=0;
- minpos=table_arg->reclength; length=0;
+ minpos= share->reclength;
+ length=0;
for (field=table_arg->field ; *field ; field++)
{
@@ -1517,25 +1522,25 @@ int ha_myisam::create(const char *name, register TABLE *table_arg,
}
MI_CREATE_INFO create_info;
bzero((char*) &create_info,sizeof(create_info));
- create_info.max_rows=table_arg->max_rows;
- create_info.reloc_rows=table_arg->min_rows;
+ create_info.max_rows= share->max_rows;
+ create_info.reloc_rows= share->min_rows;
create_info.with_auto_increment=found_real_auto_increment;
create_info.auto_increment=(info->auto_increment_value ?
info->auto_increment_value -1 :
(ulonglong) 0);
- create_info.data_file_length= ((ulonglong) table_arg->max_rows *
- table_arg->avg_row_length);
+ create_info.data_file_length= ((ulonglong) share->max_rows *
+ share->avg_row_length);
create_info.raid_type=info->raid_type;
create_info.raid_chunks= (info->raid_chunks ? info->raid_chunks :
RAID_DEFAULT_CHUNKS);
- create_info.raid_chunksize=(info->raid_chunksize ? info->raid_chunksize :
- RAID_DEFAULT_CHUNKSIZE);
- create_info.data_file_name= info->data_file_name;
- create_info.index_file_name=info->index_file_name;
+ create_info.raid_chunksize= (info->raid_chunksize ? info->raid_chunksize :
+ RAID_DEFAULT_CHUNKSIZE);
+ create_info.data_file_name= info->data_file_name;
+ create_info.index_file_name= info->index_file_name;
/* TODO: Check that the following fn_format is really needed */
error=mi_create(fn_format(buff,name,"","",2+4),
- table_arg->keys,keydef,
+ share->keys,keydef,
(uint) (recinfo_pos-recinfo), recinfo,
0, (MI_UNIQUEDEF*) 0,
&create_info,
@@ -1562,26 +1567,29 @@ ulonglong ha_myisam::get_auto_increment()
int error;
byte key[MI_MAX_KEY_LENGTH];
- if (!table->next_number_key_offset)
+ if (!table->s->next_number_key_offset)
{ // Autoincrement at key-start
ha_myisam::info(HA_STATUS_AUTO);
return auto_increment_value;
}
/* it's safe to call the following if bulk_insert isn't on */
- mi_flush_bulk_insert(file, table->next_number_index);
+ mi_flush_bulk_insert(file, table->s->next_number_index);
(void) extra(HA_EXTRA_KEYREAD);
key_copy(key, table->record[0],
- table->key_info + table->next_number_index,
- table->next_number_key_offset);
- error=mi_rkey(file,table->record[1],(int) table->next_number_index,
- key,table->next_number_key_offset,HA_READ_PREFIX_LAST);
+ table->key_info + table->s->next_number_index,
+ table->s->next_number_key_offset);
+ error= mi_rkey(file,table->record[1],(int) table->s->next_number_index,
+ key,table->s->next_number_key_offset,HA_READ_PREFIX_LAST);
if (error)
nr= 1;
else
+ {
+ /* Get data from record[1] */
nr= ((ulonglong) table->next_number_field->
- val_int_offset(table->rec_buff_length)+1);
+ val_int_offset(table->s->rec_buff_length)+1);
+ }
extra(HA_EXTRA_NO_KEYREAD);
return nr;
}
diff --git a/sql/ha_myisammrg.cc b/sql/ha_myisammrg.cc
index 744128faf69..4cd39660728 100644
--- a/sql/ha_myisammrg.cc
+++ b/sql/ha_myisammrg.cc
@@ -67,15 +67,15 @@ int ha_myisammrg::open(const char *name, int mode, uint test_if_locked)
if (!(test_if_locked & HA_OPEN_WAIT_IF_LOCKED))
myrg_extra(file,HA_EXTRA_WAIT_LOCK,0);
- if (table->reclength != mean_rec_length && mean_rec_length)
+ if (table->s->reclength != mean_rec_length && mean_rec_length)
{
DBUG_PRINT("error",("reclength: %d mean_rec_length: %d",
- table->reclength, mean_rec_length));
+ table->s->reclength, mean_rec_length));
goto err;
}
#if !defined(BIG_TABLES) || SIZEOF_OFF_T == 4
/* Merge table has more than 2G rows */
- if (table->crashed)
+ if (table->s->crashed)
goto err;
#endif
return (0);
@@ -241,14 +241,14 @@ void ha_myisammrg::info(uint flag)
#if !defined(BIG_TABLES) || SIZEOF_OFF_T == 4
if ((info.records >= (ulonglong) 1 << 32) ||
(info.deleted >= (ulonglong) 1 << 32))
- table->crashed=1;
+ table->s->crashed= 1;
#endif
data_file_length=info.data_file_length;
errkey = info.errkey;
- table->keys_in_use.set_prefix(table->keys);
- table->db_options_in_use = info.options;
- table->is_view=1;
- mean_rec_length=info.reclength;
+ table->s->keys_in_use.set_prefix(table->s->keys);
+ table->s->db_options_in_use= info.options;
+ table->s->is_view= 1;
+ mean_rec_length= info.reclength;
block_size=0;
update_time=0;
#if SIZEOF_OFF_T > 4
@@ -258,10 +258,10 @@ void ha_myisammrg::info(uint flag)
#endif
if (flag & HA_STATUS_CONST)
{
- if (table->key_parts && info.rec_per_key)
+ if (table->s->key_parts && info.rec_per_key)
memcpy((char*) table->key_info[0].rec_per_key,
(char*) info.rec_per_key,
- sizeof(table->key_info[0].rec_per_key)*table->key_parts);
+ sizeof(table->key_info[0].rec_per_key)*table->s->key_parts);
}
}
@@ -361,7 +361,7 @@ void ha_myisammrg::update_create_info(HA_CREATE_INFO *create_info)
if (!(ptr = (TABLE_LIST *) thd->calloc(sizeof(TABLE_LIST))))
goto err;
split_file_name(open_table->table->filename, &db, &name);
- if (!(ptr->real_name= thd->strmake(name.str, name.length)))
+ if (!(ptr->table_name= thd->strmake(name.str, name.length)))
goto err;
if (db.length && !(ptr->db= thd->strmake(db.str, db.length)))
goto err;
@@ -388,35 +388,36 @@ err:
int ha_myisammrg::create(const char *name, register TABLE *form,
HA_CREATE_INFO *create_info)
{
- char buff[FN_REFLEN],**table_names,**pos;
+ char buff[FN_REFLEN];
+ const char **table_names, **pos;
TABLE_LIST *tables= (TABLE_LIST*) create_info->merge_list.first;
THD *thd= current_thd;
DBUG_ENTER("ha_myisammrg::create");
- if (!(table_names= (char**) thd->alloc((create_info->merge_list.elements+1)*
- sizeof(char*))))
+ if (!(table_names= (const char**)
+ thd->alloc((create_info->merge_list.elements+1) * sizeof(char*))))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
for (pos= table_names; tables; tables= tables->next_local)
{
- char *table_name;
+ const char *table_name;
TABLE **tbl= 0;
if (create_info->options & HA_LEX_CREATE_TMP_TABLE)
- tbl= find_temporary_table(thd, tables->db, tables->real_name);
+ tbl= find_temporary_table(thd, tables->db, tables->table_name);
if (!tbl)
{
uint length= my_snprintf(buff,FN_REFLEN,"%s%s/%s",
mysql_real_data_home,
- tables->db, tables->real_name);
+ tables->db, tables->table_name);
if (!(table_name= thd->strmake(buff, length)))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
}
else
- table_name=(*tbl)->path;
+ table_name= (*tbl)->s->path;
*pos++= table_name;
}
*pos=0;
DBUG_RETURN(myrg_create(fn_format(buff,name,"","",2+4+16),
- (const char **) table_names,
+ table_names,
create_info->merge_insert_method,
(my_bool) 0));
}
@@ -436,7 +437,7 @@ void ha_myisammrg::append_create_info(String *packet)
packet->append(" UNION=(",8);
MYRG_TABLE *open_table,*first;
- current_db= table->table_cache_key;
+ current_db= table->s->db;
db_length= strlen(current_db);
for (first=open_table=file->open_tables ;
diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc
index d8616092dca..200c7ae1bc5 100644
--- a/sql/ha_ndbcluster.cc
+++ b/sql/ha_ndbcluster.cc
@@ -234,7 +234,7 @@ struct Ndb_table_local_info {
void ha_ndbcluster::set_rec_per_key()
{
DBUG_ENTER("ha_ndbcluster::get_status_const");
- for (uint i=0 ; i < table->keys ; i++)
+ for (uint i=0 ; i < table->s->keys ; i++)
{
table->key_info[i].rec_per_key[table->key_info[i].key_parts-1]= 1;
}
@@ -343,7 +343,7 @@ int ha_ndbcluster::ndb_err(NdbConnection *trans)
NDBDICT *dict= ndb->getDictionary();
DBUG_PRINT("info", ("invalidateTable %s", m_tabname));
dict->invalidateTable(m_tabname);
- table->version=0L; /* Free when thread is ready */
+ table->s->version= 0L; /* Free when thread is ready */
break;
}
default:
@@ -353,7 +353,7 @@ int ha_ndbcluster::ndb_err(NdbConnection *trans)
DBUG_PRINT("info", ("transformed ndbcluster error %d to mysql error %d",
err.code, res));
if (res == HA_ERR_FOUND_DUPP_KEY)
- m_dupkey= table->primary_key;
+ m_dupkey= table->s->primary_key;
DBUG_RETURN(res);
}
@@ -565,7 +565,7 @@ int ha_ndbcluster::get_ndb_blobs_value(NdbBlob *last_ndb_blob)
for (int loop= 0; loop <= 1; loop++)
{
uint32 offset= 0;
- for (uint i= 0; i < table->fields; i++)
+ for (uint i= 0; i < table->s->fields; i++)
{
Field *field= table->field[i];
NdbValue value= m_value[i];
@@ -667,12 +667,12 @@ int ha_ndbcluster::get_ndb_value(NdbOperation *ndb_op, Field *field,
*/
bool ha_ndbcluster::uses_blob_value(bool all_fields)
{
- if (table->blob_fields == 0)
+ if (table->s->blob_fields == 0)
return FALSE;
if (all_fields)
return TRUE;
{
- uint no_fields= table->fields;
+ uint no_fields= table->s->fields;
int i;
THD *thd= table->in_use;
// They always put blobs at the end..
@@ -776,13 +776,13 @@ int ha_ndbcluster::build_index_list(TABLE *tab, enum ILBP phase)
char unique_index_name[FN_LEN];
static const char* unique_suffix= "$unique";
KEY* key_info= tab->key_info;
- const char **key_name= tab->keynames.type_names;
+ const char **key_name= tab->s->keynames.type_names;
Ndb *ndb= get_ndb();
NdbDictionary::Dictionary *dict= ndb->getDictionary();
DBUG_ENTER("build_index_list");
// Save information about all known indexes
- for (i= 0; i < tab->keys; i++, key_info++, key_name++)
+ for (i= 0; i < tab->s->keys; i++, key_info++, key_name++)
{
index_name= *key_name;
NDB_INDEX_TYPE idx_type= get_index_type_from_table(i);
@@ -855,12 +855,12 @@ int ha_ndbcluster::build_index_list(TABLE *tab, enum ILBP phase)
NDB_INDEX_TYPE ha_ndbcluster::get_index_type_from_table(uint inx) const
{
bool is_hash_index= (table->key_info[inx].algorithm == HA_KEY_ALG_HASH);
- if (inx == table->primary_key)
+ if (inx == table->s->primary_key)
return is_hash_index ? PRIMARY_KEY_INDEX : PRIMARY_KEY_ORDERED_INDEX;
- else
- return ((table->key_info[inx].flags & HA_NOSAME) ?
- (is_hash_index ? UNIQUE_INDEX : UNIQUE_ORDERED_INDEX) :
- ORDERED_INDEX);
+
+ return ((table->key_info[inx].flags & HA_NOSAME) ?
+ (is_hash_index ? UNIQUE_INDEX : UNIQUE_ORDERED_INDEX) :
+ ORDERED_INDEX);
}
int ha_ndbcluster::check_index_fields_not_null(uint inx)
@@ -975,7 +975,7 @@ inline ulong ha_ndbcluster::index_flags(uint idx_no, uint part,
int ha_ndbcluster::set_primary_key(NdbOperation *op, const byte *key)
{
- KEY* key_info= table->key_info + table->primary_key;
+ KEY* key_info= table->key_info + table->s->primary_key;
KEY_PART_INFO* key_part= key_info->key_part;
KEY_PART_INFO* end= key_part+key_info->key_parts;
DBUG_ENTER("set_primary_key");
@@ -994,7 +994,7 @@ int ha_ndbcluster::set_primary_key(NdbOperation *op, const byte *key)
int ha_ndbcluster::set_primary_key_from_old_data(NdbOperation *op, const byte *old_data)
{
- KEY* key_info= table->key_info + table->primary_key;
+ KEY* key_info= table->key_info + table->s->primary_key;
KEY_PART_INFO* key_part= key_info->key_part;
KEY_PART_INFO* end= key_part+key_info->key_parts;
DBUG_ENTER("set_primary_key_from_old_data");
@@ -1013,7 +1013,7 @@ int ha_ndbcluster::set_primary_key_from_old_data(NdbOperation *op, const byte *o
int ha_ndbcluster::set_primary_key(NdbOperation *op)
{
DBUG_ENTER("set_primary_key");
- KEY* key_info= table->key_info + table->primary_key;
+ KEY* key_info= table->key_info + table->s->primary_key;
KEY_PART_INFO* key_part= key_info->key_part;
KEY_PART_INFO* end= key_part+key_info->key_parts;
@@ -1034,7 +1034,7 @@ int ha_ndbcluster::set_primary_key(NdbOperation *op)
int ha_ndbcluster::pk_read(const byte *key, uint key_len, byte *buf)
{
- uint no_fields= table->fields, i;
+ uint no_fields= table->s->fields, i;
NdbConnection *trans= m_active_trans;
NdbOperation *op;
THD *thd= current_thd;
@@ -1048,7 +1048,7 @@ int ha_ndbcluster::pk_read(const byte *key, uint key_len, byte *buf)
op->readTuple(lm) != 0)
ERR_RETURN(trans->getNdbError());
- if (table->primary_key == MAX_KEY)
+ if (table->s->primary_key == MAX_KEY)
{
// This table has no primary key, use "hidden" primary key
DBUG_PRINT("info", ("Using hidden key"));
@@ -1104,7 +1104,7 @@ int ha_ndbcluster::pk_read(const byte *key, uint key_len, byte *buf)
int ha_ndbcluster::complemented_pk_read(const byte *old_data, byte *new_data)
{
- uint no_fields= table->fields, i;
+ uint no_fields= table->s->fields, i;
NdbConnection *trans= m_active_trans;
NdbOperation *op;
THD *thd= current_thd;
@@ -1218,7 +1218,7 @@ int ha_ndbcluster::unique_index_read(const byte *key,
}
// Get non-index attribute(s)
- for (i= 0; i < table->fields; i++)
+ for (i= 0; i < table->s->fields; i++)
{
Field *field= table->field[i];
if ((thd->query_id == field->query_id) ||
@@ -1502,7 +1502,7 @@ int ha_ndbcluster::define_read_attrs(byte* buf, NdbOperation* op)
DBUG_ENTER("define_read_attrs");
// Define attributes to read
- for (i= 0; i < table->fields; i++)
+ for (i= 0; i < table->s->fields; i++)
{
Field *field= table->field[i];
if ((thd->query_id == field->query_id) ||
@@ -1518,11 +1518,11 @@ int ha_ndbcluster::define_read_attrs(byte* buf, NdbOperation* op)
}
}
- if (table->primary_key == MAX_KEY)
+ if (table->s->primary_key == MAX_KEY)
{
DBUG_PRINT("info", ("Getting hidden key"));
// Scanning table with no primary key
- int hidden_no= table->fields;
+ int hidden_no= table->s->fields;
#ifndef DBUG_OFF
const NDBTAB *tab= (const NDBTAB *) m_table;
if (!tab->getColumn(hidden_no))
@@ -1722,13 +1722,13 @@ int ha_ndbcluster::write_row(byte *record)
DBUG_ENTER("write_row");
- if(m_ignore_dup_key && table->primary_key != MAX_KEY)
+ if (m_ignore_dup_key && table->s->primary_key != MAX_KEY)
{
int peek_res= peek_row();
if (!peek_res)
{
- m_dupkey= table->primary_key;
+ m_dupkey= table->s->primary_key;
DBUG_RETURN(HA_ERR_FOUND_DUPP_KEY);
}
if (peek_res != HA_ERR_KEY_NOT_FOUND)
@@ -1747,12 +1747,12 @@ int ha_ndbcluster::write_row(byte *record)
if (res != 0)
ERR_RETURN(trans->getNdbError());
- if (table->primary_key == MAX_KEY)
+ if (table->s->primary_key == MAX_KEY)
{
// Table has hidden primary key
Ndb *ndb= get_ndb();
Uint64 auto_value= ndb->getAutoIncrementValue((const NDBTAB *) m_table);
- if (set_hidden_key(op, table->fields, (const byte*)&auto_value))
+ if (set_hidden_key(op, table->s->fields, (const byte*)&auto_value))
ERR_RETURN(op->getNdbError());
}
else
@@ -1772,7 +1772,7 @@ int ha_ndbcluster::write_row(byte *record)
// Set non-key attribute(s)
bool set_blob_value= FALSE;
- for (i= 0; i < table->fields; i++)
+ for (i= 0; i < table->s->fields; i++)
{
Field *field= table->field[i];
if (!(field->flags & PRI_KEY_FLAG) &&
@@ -1895,8 +1895,8 @@ int ha_ndbcluster::update_row(const byte *old_data, byte *new_data)
table->timestamp_field->set_time();
/* Check for update of primary key for special handling */
- if ((table->primary_key != MAX_KEY) &&
- (key_cmp(table->primary_key, old_data, new_data)))
+ if ((table->s->primary_key != MAX_KEY) &&
+ (key_cmp(table->s->primary_key, old_data, new_data)))
{
int read_res, insert_res, delete_res;
@@ -1952,14 +1952,14 @@ int ha_ndbcluster::update_row(const byte *old_data, byte *new_data)
op->updateTuple() != 0)
ERR_RETURN(trans->getNdbError());
- if (table->primary_key == MAX_KEY)
+ if (table->s->primary_key == MAX_KEY)
{
// This table has no primary key, use "hidden" primary key
DBUG_PRINT("info", ("Using hidden key"));
// Require that the PK for this record has previously been
// read into m_value
- uint no_fields= table->fields;
+ uint no_fields= table->s->fields;
NdbRecAttr* rec= m_value[no_fields].rec;
DBUG_ASSERT(rec);
DBUG_DUMP("key", (char*)rec->aRef(), NDB_HIDDEN_PRIMARY_KEY_LENGTH);
@@ -1976,7 +1976,7 @@ int ha_ndbcluster::update_row(const byte *old_data, byte *new_data)
}
// Set non-key attribute(s)
- for (i= 0; i < table->fields; i++)
+ for (i= 0; i < table->s->fields; i++)
{
Field *field= table->field[i];
if (((thd->query_id == field->query_id) || m_retrieve_all_fields) &&
@@ -2037,11 +2037,11 @@ int ha_ndbcluster::delete_row(const byte *record)
no_uncommitted_rows_update(-1);
- if (table->primary_key == MAX_KEY)
+ if (table->s->primary_key == MAX_KEY)
{
// This table has no primary key, use "hidden" primary key
DBUG_PRINT("info", ("Using hidden key"));
- uint no_fields= table->fields;
+ uint no_fields= table->s->fields;
NdbRecAttr* rec= m_value[no_fields].rec;
DBUG_ASSERT(rec != NULL);
@@ -2088,8 +2088,8 @@ void ha_ndbcluster::unpack_record(byte* buf)
DBUG_ENTER("unpack_record");
// Set null flag(s)
- bzero(buf, table->null_bytes);
- for (field= table->field, end= field+table->fields;
+ bzero(buf, table->s->null_bytes);
+ for (field= table->field, end= field+table->s->fields;
field < end;
field++, value++)
{
@@ -2114,10 +2114,10 @@ void ha_ndbcluster::unpack_record(byte* buf)
#ifndef DBUG_OFF
// Read and print all values that was fetched
- if (table->primary_key == MAX_KEY)
+ if (table->s->primary_key == MAX_KEY)
{
// Table with hidden primary key
- int hidden_no= table->fields;
+ int hidden_no= table->s->fields;
const NDBTAB *tab= (const NDBTAB *) m_table;
const NDBCOL *hidden_col= tab->getColumn(hidden_no);
NdbRecAttr* rec= m_value[hidden_no].rec;
@@ -2143,7 +2143,7 @@ void ha_ndbcluster::print_results()
if (!_db_on_)
DBUG_VOID_RETURN;
- for (uint f=0; f<table->fields;f++)
+ for (uint f=0; f<table->s->fields;f++)
{
Field *field;
const NDBCOL *col;
@@ -2532,7 +2532,7 @@ int ha_ndbcluster::rnd_init(bool scan)
int res= cursor->restart(m_force_send);
DBUG_ASSERT(res == 0);
}
- index_init(table->primary_key);
+ index_init(table->s->primary_key);
DBUG_RETURN(0);
}
@@ -2616,9 +2616,9 @@ void ha_ndbcluster::position(const byte *record)
byte *buff;
DBUG_ENTER("position");
- if (table->primary_key != MAX_KEY)
+ if (table->s->primary_key != MAX_KEY)
{
- key_info= table->key_info + table->primary_key;
+ key_info= table->key_info + table->s->primary_key;
key_part= key_info->key_part;
end= key_part + key_info->key_parts;
buff= ref;
@@ -2642,7 +2642,7 @@ void ha_ndbcluster::position(const byte *record)
{
// No primary key, get hidden key
DBUG_PRINT("info", ("Getting hidden key"));
- int hidden_no= table->fields;
+ int hidden_no= table->s->fields;
NdbRecAttr* rec= m_value[hidden_no].rec;
const NDBTAB *tab= (const NDBTAB *) m_table;
const NDBCOL *hidden_col= tab->getColumn(hidden_no);
@@ -3470,7 +3470,7 @@ int ha_ndbcluster::create(const char *name,
NDBCOL col;
uint pack_length, length, i, pk_length= 0;
const void *data, *pack_data;
- const char **key_names= form->keynames.type_names;
+ const char **key_names= form->s->keynames.type_names;
char name2[FN_HEADLEN];
bool create_from_engine= (info->table_options & HA_CREATE_FROM_ENGINE);
@@ -3506,7 +3506,7 @@ int ha_ndbcluster::create(const char *name,
my_free((char*)data, MYF(0));
my_free((char*)pack_data, MYF(0));
- for (i= 0; i < form->fields; i++)
+ for (i= 0; i < form->s->fields; i++)
{
Field *field= form->field[i];
DBUG_PRINT("info", ("name: %s, type: %u, pack_length: %d",
@@ -3520,7 +3520,7 @@ int ha_ndbcluster::create(const char *name,
}
// No primary key, create shadow key as 64 bit, auto increment
- if (form->primary_key == MAX_KEY)
+ if (form->s->primary_key == MAX_KEY)
{
DBUG_PRINT("info", ("Generating shadow key"));
col.setName("$PK");
@@ -3534,7 +3534,7 @@ int ha_ndbcluster::create(const char *name,
}
// Make sure that blob tables don't have to big part size
- for (i= 0; i < form->fields; i++)
+ for (i= 0; i < form->s->fields; i++)
{
/**
* The extra +7 concists
@@ -3896,9 +3896,9 @@ int ha_ndbcluster::open(const char *name, int mode, uint test_if_locked)
// Setup ref_length to make room for the whole
// primary key to be written in the ref variable
- if (table->primary_key != MAX_KEY)
+ if (table->s->primary_key != MAX_KEY)
{
- key= table->key_info+table->primary_key;
+ key= table->key_info+table->s->primary_key;
ref_length= key->key_length;
DBUG_PRINT("info", (" ref_length: %d", ref_length));
}
@@ -4237,7 +4237,7 @@ int ndbcluster_find_files(THD *thd,const char *db,const char *path,
TABLE_LIST table_list;
bzero((char*) &table_list,sizeof(table_list));
table_list.db= (char*) db;
- table_list.alias=table_list.real_name=(char*)file_name;
+ table_list.alias= table_list.table_name= (char*)file_name;
(void)mysql_rm_table_part2(thd, &table_list,
/* if_exists */ TRUE,
/* drop_temporary */ FALSE,
@@ -4372,7 +4372,7 @@ void ndbcluster_print_error(int error, const NdbOperation *error_op)
DBUG_ENTER("ndbcluster_print_error");
TABLE tab;
const char *tab_name= (error_op) ? error_op->getTableName() : "";
- tab.table_name= (char *) tab_name;
+ tab.alias= (char *) tab_name;
ha_ndbcluster error_handler(&tab);
tab.file= &error_handler;
error_handler.print_error(error, MYF(0));
diff --git a/sql/handler.cc b/sql/handler.cc
index cde2c7b02a8..bbe01dd93d5 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -1017,7 +1017,7 @@ int handler::ha_open(const char *name, int mode, int test_if_locked)
int error;
DBUG_ENTER("handler::ha_open");
DBUG_PRINT("enter",("name: %s db_type: %d db_stat: %d mode: %d lock_test: %d",
- name, table->db_type, table->db_stat, mode,
+ name, table->s->db_type, table->db_stat, mode,
test_if_locked));
if ((error=open(name,mode,test_if_locked)))
@@ -1036,7 +1036,7 @@ int handler::ha_open(const char *name, int mode, int test_if_locked)
}
else
{
- if (table->db_options_in_use & HA_OPTION_READ_ONLY_DATA)
+ if (table->s->db_options_in_use & HA_OPTION_READ_ONLY_DATA)
table->db_stat|=HA_READ_ONLY;
(void) extra(HA_EXTRA_NO_READCHECK); // Not needed in SQL
@@ -1214,7 +1214,7 @@ void handler::update_auto_increment()
first key part, as there is no guarantee that the first parts will be in
sequence
*/
- if (!table->next_number_key_offset)
+ if (!table->s->next_number_key_offset)
{
/*
Set next insert id to point to next auto-increment value to be able to
@@ -1252,8 +1252,8 @@ ulonglong handler::get_auto_increment()
int error;
(void) extra(HA_EXTRA_KEYREAD);
- index_init(table->next_number_index);
- if (!table->next_number_key_offset)
+ index_init(table->s->next_number_index);
+ if (!table->s->next_number_key_offset)
{ // Autoincrement at key-start
error=index_last(table->record[1]);
}
@@ -1261,17 +1261,17 @@ ulonglong handler::get_auto_increment()
{
byte key[MAX_KEY_LENGTH];
key_copy(key, table->record[0],
- table->key_info + table->next_number_index,
- table->next_number_key_offset);
- error=index_read(table->record[1], key, table->next_number_key_offset,
- HA_READ_PREFIX_LAST);
+ table->key_info + table->s->next_number_index,
+ table->s->next_number_key_offset);
+ error= index_read(table->record[1], key, table->s->next_number_key_offset,
+ HA_READ_PREFIX_LAST);
}
if (error)
nr=1;
else
- nr=((ulonglong) table->next_number_field->
- val_int_offset(table->rec_buff_length)+1);
+ nr= ((ulonglong) table->next_number_field->
+ val_int_offset(table->s->rec_buff_length)+1);
index_end();
(void) extra(HA_EXTRA_NO_KEYREAD);
return nr;
@@ -1396,10 +1396,10 @@ void handler::print_error(int error, myf errflag)
*/
char *db;
char buff[FN_REFLEN];
- uint length=dirname_part(buff,table->path);
+ uint length= dirname_part(buff,table->s->path);
buff[length-1]=0;
db=buff+dirname_length(buff);
- my_error(ER_NO_SUCH_TABLE, MYF(0), db, table->table_name);
+ my_error(ER_NO_SUCH_TABLE, MYF(0), db, table->alias);
break;
}
default:
@@ -1422,7 +1422,7 @@ void handler::print_error(int error, myf errflag)
DBUG_VOID_RETURN;
}
}
- my_error(textno, errflag, table->table_name, error);
+ my_error(textno, errflag, table->alias, error);
DBUG_VOID_RETURN;
}
diff --git a/sql/item.cc b/sql/item.cc
index 7dba1f3a66a..c84496f8eb7 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -569,7 +569,7 @@ bool DTCollation::aggregate(DTCollation &dt, uint flags)
}
Item_field::Item_field(Field *f)
- :Item_ident(NullS, f->table_name, f->field_name),
+ :Item_ident(NullS, *f->table_name, f->field_name),
item_equal(0), no_const_subst(0),
have_privileges(0), any_privileges(0)
{
@@ -582,7 +582,7 @@ Item_field::Item_field(Field *f)
}
Item_field::Item_field(THD *thd, Field *f)
- :Item_ident(f->table->table_cache_key, f->table_name, f->field_name),
+ :Item_ident(f->table->s->db, *f->table_name, f->field_name),
item_equal(0), no_const_subst(0),
have_privileges(0), any_privileges(0)
{
@@ -636,9 +636,9 @@ void Item_field::set_field(Field *field_par)
maybe_null=field->maybe_null();
max_length=field_par->field_length;
decimals= field->decimals();
- table_name=field_par->table_name;
- field_name=field_par->field_name;
- db_name=field_par->table->table_cache_key;
+ table_name= *field_par->table_name;
+ field_name= field_par->field_name;
+ db_name= field_par->table->s->db;
alias_name_used= field_par->table->alias_name_used;
unsigned_flag=test(field_par->flags & UNSIGNED_FLAG);
collation.set(field_par->charset(), DERIVATION_IMPLICIT);
@@ -1576,16 +1576,18 @@ bool Item_ref_null_helper::get_date(TIME *ltime, uint fuzzydate)
static void mark_as_dependent(THD *thd, SELECT_LEX *last, SELECT_LEX *current,
Item_ident *item)
{
- // store pointer on SELECT_LEX from which item is dependent
+ const char *db_name= item->db_name ? item->db_name : "";
+ const char *table_name= item->table_name ? item->table_name : "";
+ /* store pointer on SELECT_LEX from which item is dependent */
item->depended_from= last;
current->mark_as_dependent(last);
if (thd->lex->describe & DESCRIBE_EXTENDED)
{
char warn_buff[MYSQL_ERRMSG_SIZE];
sprintf(warn_buff, ER(ER_WARN_FIELD_RESOLVED),
- (item->db_name?item->db_name:""), (item->db_name?".":""),
- (item->table_name?item->table_name:""), (item->table_name?".":""),
- item->field_name,
+ db_name, (db_name[0] ? "." : ""),
+ table_name, (table_name [0] ? "." : ""),
+ item->field_name,
current->select_number, last->select_number);
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
ER_WARN_FIELD_RESOLVED, warn_buff);
@@ -1745,8 +1747,9 @@ resolve_ref_in_select_and_group(THD *thd, Item_ident *ref, SELECT_LEX *select)
Search for a column or derived column named as 'ref' in the SELECT
clause of the current select.
*/
- if (!(select_ref= find_item_in_list(ref, *(select->get_item_list()), &counter,
- REPORT_EXCEPT_NOT_FOUND, &not_used)))
+ if (!(select_ref= find_item_in_list(ref, *(select->get_item_list()),
+ &counter, REPORT_EXCEPT_NOT_FOUND,
+ &not_used)))
return NULL; /* Some error occurred. */
/* If this is a non-aggregated field inside HAVING, search in GROUP BY. */
@@ -2053,7 +2056,7 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **reference)
else
{
db= cached_table->db;
- tab= cached_table->real_name;
+ tab= cached_table->table_name;
}
if (!(have_privileges= (get_column_grant(thd, &field->table->grant,
db, tab, field_name) &
@@ -3195,7 +3198,7 @@ bool Item_default_value::fix_fields(THD *thd,
if (!(def_field= (Field*) sql_alloc(field_arg->field->size_of())))
return TRUE;
memcpy(def_field, field_arg->field, field_arg->field->size_of());
- def_field->move_field(def_field->table->default_values -
+ def_field->move_field(def_field->table->s->default_values -
def_field->table->record[0]);
set_field(def_field);
return FALSE;
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 69ddd21f913..7768caa2507 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -3198,7 +3198,7 @@ bool Item_func_match::fix_index()
if (key == NO_SUCH_KEY)
return 0;
- for (keynr=0 ; keynr < table->keys ; keynr++)
+ for (keynr=0 ; keynr < table->s->keys ; keynr++)
{
if ((table->key_info[keynr].flags & HA_FULLTEXT) &&
(table->keys_in_use_for_query.is_set(keynr)))
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index dbf30d7d793..2d4f88ed57b 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -1497,7 +1497,7 @@ void subselect_uniquesubquery_engine::print(String *str)
str->append("<primary_index_lookup>(", 23);
tab->ref.items[0]->print(str);
str->append(" in ", 4);
- str->append(tab->table->real_name);
+ str->append(tab->table->s->table_name);
KEY *key_info= tab->table->key_info+ tab->ref.key;
str->append(" on ", 4);
str->append(key_info->name);
@@ -1515,7 +1515,7 @@ void subselect_indexsubquery_engine::print(String *str)
str->append("<index_lookup>(", 15);
tab->ref.items[0]->print(str);
str->append(" in ", 4);
- str->append(tab->table->real_name);
+ str->append(tab->table->s->table_name);
KEY *key_info= tab->table->key_info+ tab->ref.key;
str->append(" on ", 4);
str->append(key_info->name);
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index 1c005cf60a9..168c68ad706 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -1225,7 +1225,7 @@ int composite_key_cmp(void* arg, byte* key1, byte* key2)
{
Item_sum_count_distinct* item = (Item_sum_count_distinct*)arg;
Field **field = item->table->field;
- Field **field_end= field + item->table->fields;
+ Field **field_end= field + item->table->s->fields;
uint32 *lengths=item->field_lengths;
for (; field < field_end; ++field)
{
@@ -1344,15 +1344,15 @@ bool Item_sum_count_distinct::setup(THD *thd)
// no blobs, otherwise it would be MyISAM
- if (table->db_type == DB_TYPE_HEAP)
+ if (table->s->db_type == DB_TYPE_HEAP)
{
qsort_cmp2 compare_key;
void* cmp_arg;
// to make things easier for dump_leaf if we ever have to dump to MyISAM
- restore_record(table,default_values);
+ restore_record(table,s->default_values);
- if (table->fields == 1)
+ if (table->s->fields == 1)
{
/*
If we have only one field, which is the most common use of
@@ -1396,10 +1396,10 @@ bool Item_sum_count_distinct::setup(THD *thd)
{
bool all_binary = 1;
Field** field, **field_end;
- field_end = (field = table->field) + table->fields;
+ field_end = (field = table->field) + table->s->fields;
uint32 *lengths;
if (!(field_lengths=
- (uint32*) thd->alloc(sizeof(uint32) * table->fields)))
+ (uint32*) thd->alloc(sizeof(uint32) * table->s->fields)))
return 1;
for (key_length = 0, lengths=field_lengths; field < field_end; ++field)
@@ -1410,7 +1410,7 @@ bool Item_sum_count_distinct::setup(THD *thd)
if (!(*field)->binary())
all_binary = 0; // Can't break loop here
}
- rec_offset = table->reclength - key_length;
+ rec_offset= table->s->reclength - key_length;
if (all_binary)
{
compare_key = (qsort_cmp2)simple_raw_key_cmp;
@@ -1781,7 +1781,7 @@ int dump_leaf_key(byte* key, uint32 count __attribute__((unused)),
String *res;
char *save_ptr= field->ptr;
uint offset= (uint) (save_ptr - record);
- DBUG_ASSERT(offset < item->table->reclength);
+ DBUG_ASSERT(offset < item->table->s->reclength);
field->ptr= (char *) key + offset;
res= field->val_str(&tmp,&tmp2);
item->result.append(*res);
@@ -2124,10 +2124,10 @@ bool Item_func_group_concat::setup(THD *thd)
table->file->extra(HA_EXTRA_NO_ROWS);
table->no_rows= 1;
- key_length= table->reclength;
+ key_length= table->s->reclength;
/* Offset to first result field in table */
- field_list_offset= table->fields - (list.elements - const_fields);
+ field_list_offset= table->s->fields - (list.elements - const_fields);
if (tree_mode)
delete_tree(tree);
diff --git a/sql/key.cc b/sql/key.cc
index d54b8721cab..aec294e370a 100644
--- a/sql/key.cc
+++ b/sql/key.cc
@@ -38,7 +38,9 @@ int find_ref_key(TABLE *table,Field *field, uint *key_length)
/* Test if some key starts as fieldpos */
- for (i=0, key_info=table->key_info ; i < (int) table->keys ; i++, key_info++)
+ for (i= 0, key_info= table->key_info ;
+ i < (int) table->s->keys ;
+ i++, key_info++)
{
if (key_info->key_part[0].offset == fieldpos)
{ /* Found key. Calc keylength */
@@ -48,7 +50,9 @@ int find_ref_key(TABLE *table,Field *field, uint *key_length)
}
/* Test if some key contains fieldpos */
- for (i=0, key_info=table->key_info ; i < (int) table->keys ; i++, key_info++)
+ for (i= 0, key_info= table->key_info ;
+ i < (int) table->s->keys ;
+ i++, key_info++)
{
uint j;
KEY_PART_INFO *key_part;
@@ -373,9 +377,9 @@ bool check_if_key_used(TABLE *table, uint idx, List<Item> &fields)
If table handler has primary key as part of the index, check that primary
key is not updated
*/
- if (idx != table->primary_key && table->primary_key < MAX_KEY &&
+ if (idx != table->s->primary_key && table->s->primary_key < MAX_KEY &&
(table->file->table_flags() & HA_PRIMARY_KEY_IN_READ_INDEX))
- return check_if_key_used(table, table->primary_key, fields);
+ return check_if_key_used(table, table->s->primary_key, fields);
return 0;
}
diff --git a/sql/lock.cc b/sql/lock.cc
index 973e82b7b10..fffd48d5305 100644
--- a/sql/lock.cc
+++ b/sql/lock.cc
@@ -401,7 +401,7 @@ static MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count,
*write_lock_used=0;
for (i=tables=lock_count=0 ; i < count ; i++)
{
- if (table_ptr[i]->tmp_table != TMP_TABLE)
+ if (table_ptr[i]->s->tmp_table != TMP_TABLE)
{
tables+=table_ptr[i]->file->lock_count();
lock_count++;
@@ -421,7 +421,7 @@ static MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count,
for (i=0 ; i < count ; i++)
{
TABLE *table;
- if ((table=table_ptr[i])->tmp_table == TMP_TABLE)
+ if ((table=table_ptr[i])->s->tmp_table == TMP_TABLE)
continue;
*to++=table;
enum thr_lock_type lock_type= table->reginfo.lock_type;
@@ -430,7 +430,7 @@ static MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count,
*write_lock_used=table;
if (table->db_stat & HA_READ_ONLY)
{
- my_error(ER_OPEN_AS_READONLY, MYF(0), table->table_name);
+ my_error(ER_OPEN_AS_READONLY, MYF(0), table->alias);
my_free((gptr) sql_lock,MYF(0));
return 0;
}
@@ -526,11 +526,11 @@ int lock_table_name(THD *thd, TABLE_LIST *table_list)
char *db= table_list->db;
uint key_length;
DBUG_ENTER("lock_table_name");
- DBUG_PRINT("enter",("db: %s name: %s", db, table_list->real_name));
+ DBUG_PRINT("enter",("db: %s name: %s", db, table_list->table_name));
safe_mutex_assert_owner(&LOCK_open);
- key_length=(uint) (strmov(strmov(key,db)+1,table_list->real_name)
+ key_length=(uint) (strmov(strmov(key,db)+1,table_list->table_name)
-key)+ 1;
@@ -549,8 +549,9 @@ int lock_table_name(THD *thd, TABLE_LIST *table_list)
if (!(table= (TABLE*) my_malloc(sizeof(*table)+key_length,
MYF(MY_WME | MY_ZEROFILL))))
DBUG_RETURN(-1);
- memcpy((table->table_cache_key= (char*) (table+1)), key, key_length);
- table->key_length=key_length;
+ table->s= &table->share_not_to_be_used;
+ memcpy((table->s->table_cache_key= (char*) (table+1)), key, key_length);
+ table->s->key_length=key_length;
table->in_use=thd;
table->locked_by_name=1;
table_list->table=table;
@@ -560,7 +561,7 @@ int lock_table_name(THD *thd, TABLE_LIST *table_list)
my_free((gptr) table,MYF(0));
DBUG_RETURN(-1);
}
- if (remove_table_from_cache(thd, db, table_list->real_name))
+ if (remove_table_from_cache(thd, db, table_list->table_name))
DBUG_RETURN(1); // Table is in use
DBUG_RETURN(0);
}
diff --git a/sql/log_event.cc b/sql/log_event.cc
index adebf446a82..2fa4e09913e 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -2495,7 +2495,7 @@ int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli,
TABLE_LIST tables;
bzero((char*) &tables,sizeof(tables));
tables.db = thd->db;
- tables.alias = tables.real_name = (char*)table_name;
+ tables.alias = tables.table_name = (char*) table_name;
tables.lock_type = TL_WRITE;
tables.updating= 1;
@@ -2516,11 +2516,11 @@ int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli,
user in SHOW PROCESSLIST. Note that db is known in the 'db' column.
*/
if ((load_data_query= (char *) my_alloca(18 + strlen(fname) + 14 +
- strlen(tables.real_name) + 8)))
+ strlen(tables.table_name) + 8)))
{
thd->query_length= (uint)(strxmov(load_data_query,
"LOAD DATA INFILE '", fname,
- "' INTO TABLE `", tables.real_name,
+ "' INTO TABLE `", tables.table_name,
"` <...>", NullS) - load_data_query);
thd->query= load_data_query;
}
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index 01e2510328d..6f569ea3ef4 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -1269,7 +1269,7 @@ inline void mark_as_null_row(TABLE *table)
{
table->null_row=1;
table->status|=STATUS_NULL_ROW;
- bfill(table->null_flags,table->null_bytes,255);
+ bfill(table->null_flags,table->s->null_bytes,255);
}
inline void table_case_convert(char * name, uint length)
@@ -1319,7 +1319,7 @@ inline void setup_table_map(TABLE *table, TABLE_LIST *table_list, uint tablenr)
table->const_table= 0;
table->null_row= 0;
table->status= STATUS_NO_RECORD;
- table->keys_in_use_for_query= table->keys_in_use;
+ table->keys_in_use_for_query= table->s->keys_in_use;
table->maybe_null= test(table->outer_join= table_list->outer_join);
table->tablenr= tablenr;
table->map= (table_map) 1 << tablenr;
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index e7f03b51fc0..7e05e51e182 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -712,7 +712,7 @@ QUICK_SELECT_I::QUICK_SELECT_I()
QUICK_RANGE_SELECT::QUICK_RANGE_SELECT(THD *thd, TABLE *table, uint key_nr,
bool no_alloc, MEM_ROOT *parent_alloc)
- :dont_free(0),error(0),free_file(0),cur_range(NULL),range(0),in_range(0)
+ :dont_free(0),error(0),free_file(0),in_range(0),cur_range(NULL),range(0)
{
sorted= 0;
index= key_nr;
@@ -822,7 +822,7 @@ QUICK_INDEX_MERGE_SELECT::push_quick_back(QUICK_RANGE_SELECT *quick_sel_range)
processed separately.
*/
if (head->file->primary_key_is_clustered() &&
- quick_sel_range->index == head->primary_key)
+ quick_sel_range->index == head->s->primary_key)
pk_quick_select= quick_sel_range;
else
return quick_selects.push_back(quick_sel_range);
@@ -927,10 +927,10 @@ int QUICK_RANGE_SELECT::init_ror_merged_scan(bool reuse_handler)
DBUG_RETURN(0);
}
- if (!(file= get_new_handler(head, head->db_type)))
+ if (!(file= get_new_handler(head, head->s->db_type)))
goto failure;
DBUG_PRINT("info", ("Allocated new handler %p", file));
- if (file->ha_open(head->path, head->db_stat, HA_OPEN_IGNORE_IF_LOCKED))
+ if (file->ha_open(head->s->path, head->db_stat, HA_OPEN_IGNORE_IF_LOCKED))
{
/* Caller will free the memory */
goto failure;
@@ -1551,7 +1551,7 @@ public:
static int fill_used_fields_bitmap(PARAM *param)
{
TABLE *table= param->table;
- param->fields_bitmap_size= (table->fields/8 + 1);
+ param->fields_bitmap_size= (table->s->fields/8 + 1);
uchar *tmp;
uint pk;
if (!(tmp= (uchar*)alloc_root(param->mem_root,param->fields_bitmap_size)) ||
@@ -1560,13 +1560,13 @@ static int fill_used_fields_bitmap(PARAM *param)
return 1;
bitmap_clear_all(&param->needed_fields);
- for (uint i= 0; i < table->fields; i++)
+ for (uint i= 0; i < table->s->fields; i++)
{
if (param->thd->query_id == table->field[i]->query_id)
bitmap_set_bit(&param->needed_fields, i+1);
}
- pk= param->table->primary_key;
+ pk= param->table->s->primary_key;
if (param->table->file->primary_key_is_clustered() && pk != MAX_KEY)
{
/* The table uses clustered PK and it is not internally generated */
@@ -1674,10 +1674,10 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use,
thd->no_errors=1; // Don't warn about NULL
init_sql_alloc(&alloc, thd->variables.range_alloc_block_size, 0);
- if (!(param.key_parts = (KEY_PART*) alloc_root(&alloc,
- sizeof(KEY_PART)*
- head->key_parts))
- || fill_used_fields_bitmap(&param))
+ if (!(param.key_parts= (KEY_PART*) alloc_root(&alloc,
+ sizeof(KEY_PART)*
+ head->s->key_parts)) ||
+ fill_used_fields_bitmap(&param))
{
thd->no_errors=0;
free_root(&alloc,MYF(0)); // Return memory & allocator
@@ -1692,7 +1692,7 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use,
This is used in get_mm_parts function.
*/
key_info= head->key_info;
- for (idx=0 ; idx < head->keys ; idx++, key_info++)
+ for (idx=0 ; idx < head->s->keys ; idx++, key_info++)
{
KEY_PART_INFO *key_part_info;
if (!keys_to_use.is_set(idx))
@@ -1876,7 +1876,7 @@ double get_sweep_read_cost(const PARAM *param, ha_rows records)
double result;
if (param->table->file->primary_key_is_clustered())
{
- result= param->table->file->read_time(param->table->primary_key,
+ result= param->table->file->read_time(param->table->s->primary_key,
records, records);
}
else
@@ -2040,7 +2040,8 @@ TABLE_READ_PLAN *get_best_disjunct_quick(PARAM *param, SEL_IMERGE *imerge,
all_scans_ror_able &= ((*ptree)->n_ror_scans > 0);
all_scans_rors &= (*cur_child)->is_ror;
if (pk_is_clustered &&
- param->real_keynr[(*cur_child)->key_idx] == param->table->primary_key)
+ param->real_keynr[(*cur_child)->key_idx] ==
+ param->table->s->primary_key)
{
cpk_scan= cur_child;
cpk_scan_records= (*cur_child)->records;
@@ -2763,13 +2764,15 @@ TRP_ROR_INTERSECT *get_best_ror_intersect(const PARAM *param, SEL_TREE *tree,
*/
ROR_SCAN_INFO **cur_ror_scan;
ROR_SCAN_INFO *cpk_scan= NULL;
+ uint cpk_no;
bool cpk_scan_used= FALSE;
+
if (!(tree->ror_scans= (ROR_SCAN_INFO**)alloc_root(param->mem_root,
sizeof(ROR_SCAN_INFO*)*
param->keys)))
return NULL;
- uint cpk_no= (param->table->file->primary_key_is_clustered())?
- param->table->primary_key : MAX_KEY;
+ cpk_no= ((param->table->file->primary_key_is_clustered()) ?
+ param->table->s->primary_key : MAX_KEY);
for (idx= 0, cur_ror_scan= tree->ror_scans; idx < param->keys; idx++)
{
@@ -3128,7 +3131,7 @@ static TRP_RANGE *get_key_scans_params(PARAM *param, SEL_TREE *tree,
read_index_only &&
(param->table->file->index_flags(keynr, param->max_key_part,1) &
HA_KEYREAD_ONLY) &&
- !(pk_is_clustered && keynr == param->table->primary_key))
+ !(pk_is_clustered && keynr == param->table->s->primary_key))
/* We can resolve this by only reading through this key. */
found_read_time= get_index_only_read_time(param,found_records,keynr) +
cpu_cost;
@@ -4975,8 +4978,8 @@ check_quick_select(PARAM *param,uint idx,SEL_ARG *tree)
Clustered PK scan is a special case, check_quick_keys doesn't recognize
CPK scans as ROR scans (while actually any CPK scan is a ROR scan).
*/
- cpk_scan= (param->table->primary_key == param->real_keynr[idx]) &&
- param->table->file->primary_key_is_clustered();
+ cpk_scan= ((param->table->s->primary_key == param->real_keynr[idx]) &&
+ param->table->file->primary_key_is_clustered());
param->is_ror_scan= !cpk_scan;
}
@@ -5237,12 +5240,13 @@ static bool is_key_scan_ror(PARAM *param, uint keynr, uint8 nparts)
{
KEY *table_key= param->table->key_info + keynr;
KEY_PART_INFO *key_part= table_key->key_part + nparts;
- KEY_PART_INFO *key_part_end= table_key->key_part +
- table_key->key_parts;
+ KEY_PART_INFO *key_part_end= (table_key->key_part +
+ table_key->key_parts);
+ uint pk_number;
if (key_part == key_part_end)
return TRUE;
- uint pk_number= param->table->primary_key;
+ pk_number= param->table->s->primary_key;
if (!param->table->file->primary_key_is_clustered() || pk_number == MAX_KEY)
return FALSE;
@@ -5947,7 +5951,7 @@ int QUICK_RANGE_SELECT::get_next_init(void)
if (file->table_flags() & HA_NEED_READ_RANGE_BUFFER)
{
mrange_bufsiz= min(multi_range_bufsiz,
- QUICK_SELECT_I::records * head->reclength);
+ QUICK_SELECT_I::records * head->s->reclength);
while (mrange_bufsiz &&
! my_multi_malloc(MYF(MY_WME),
@@ -6795,7 +6799,6 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree)
ORDER *tmp_group;
Item *item;
Item_field *item_field;
-
DBUG_ENTER("get_best_group_min_max");
/* Perform few 'cheap' tests whether this access method is applicable. */
@@ -6805,7 +6808,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree)
((!join->group_list) && /* Neither GROUP BY nor a DISTINCT query. */
(!join->select_distinct)))
DBUG_RETURN(NULL);
- if(table->keys == 0) /* There are no indexes to use. */
+ if (table->s->keys == 0) /* There are no indexes to use. */
DBUG_RETURN(NULL);
/* Analyze the query in more detail. */
@@ -6863,7 +6866,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree)
first one. Here we set the variables: group_prefix_len and index_info.
*/
KEY *cur_index_info= table->key_info;
- KEY *cur_index_info_end= cur_index_info + table->keys;
+ KEY *cur_index_info_end= cur_index_info + table->s->keys;
KEY_PART_INFO *cur_part= NULL;
KEY_PART_INFO *end_part; /* Last part for loops. */
/* Last index part. */
@@ -8279,21 +8282,26 @@ int QUICK_GROUP_MIN_MAX_SELECT::next_min_in_range()
(cur_range->flag & (EQ_RANGE | NULL_RANGE)))
continue; /* Check the next range. */
else if (result)
- /*
- In all other cases (HA_ERR_*, HA_READ_KEY_EXACT with NO_MIN_RANGE,
- HA_READ_AFTER_KEY, HA_READ_KEY_OR_NEXT) if the lookup failed for this
- range, it can't succeed for any other subsequent range.
- */
+ {
+ /*
+ In all other cases (HA_ERR_*, HA_READ_KEY_EXACT with NO_MIN_RANGE,
+ HA_READ_AFTER_KEY, HA_READ_KEY_OR_NEXT) if the lookup failed for this
+ range, it can't succeed for any other subsequent range.
+ */
break;
+ }
/* A key was found. */
if (cur_range->flag & EQ_RANGE)
break; /* No need to perform the checks below for equal keys. */
if (cur_range->flag & NULL_RANGE)
- { /* Remember this key, and continue looking for a non-NULL key that */
- /* satisfies some other condition. */
- memcpy(tmp_record, record, head->rec_buff_length);
+ {
+ /*
+ Remember this key, and continue looking for a non-NULL key that
+ satisfies some other condition.
+ */
+ memcpy(tmp_record, record, head->s->rec_buff_length);
found_null= TRUE;
continue;
}
@@ -8334,7 +8342,7 @@ int QUICK_GROUP_MIN_MAX_SELECT::next_min_in_range()
*/
if (found_null && result)
{
- memcpy(record, tmp_record, head->rec_buff_length);
+ memcpy(record, tmp_record, head->s->rec_buff_length);
result= 0;
}
return result;
diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc
index 80226dcfa2c..ef9babf7713 100644
--- a/sql/opt_sum.cc
+++ b/sql/opt_sum.cc
@@ -644,7 +644,7 @@ static bool find_key_for_maxmin(bool max_fl, TABLE_REF *ref,
uint idx= 0;
KEY *keyinfo,*keyinfo_end;
- for (keyinfo= table->key_info, keyinfo_end= keyinfo+table->keys ;
+ for (keyinfo= table->key_info, keyinfo_end= keyinfo+table->s->keys ;
keyinfo != keyinfo_end;
keyinfo++,idx++)
{
diff --git a/sql/records.cc b/sql/records.cc
index 3c0143d2307..9a506cadf0c 100644
--- a/sql/records.cc
+++ b/sql/records.cc
@@ -26,7 +26,7 @@ static int rr_unpack_from_tempfile(READ_RECORD *info);
static int rr_unpack_from_buffer(READ_RECORD *info);
static int rr_from_pointers(READ_RECORD *info);
static int rr_from_cache(READ_RECORD *info);
-static int init_rr_cache(READ_RECORD *info);
+static int init_rr_cache(THD *thd, READ_RECORD *info);
static int rr_cmp(uchar *a,uchar *b);
/* init struct for read with info->read_record */
@@ -84,14 +84,14 @@ void init_read_record(READ_RECORD *info,THD *thd, TABLE *table,
!(table->file->table_flags() & HA_FAST_KEY_READ) &&
(table->db_stat & HA_READ_ONLY ||
table->reginfo.lock_type <= TL_READ_NO_INSERT) &&
- (ulonglong) table->reclength*(table->file->records+
- table->file->deleted) >
+ (ulonglong) table->s->reclength* (table->file->records+
+ table->file->deleted) >
(ulonglong) MIN_FILE_LENGTH_TO_USE_ROW_CACHE &&
- info->io_cache->end_of_file/info->ref_length*table->reclength >
+ info->io_cache->end_of_file/info->ref_length * table->s->reclength >
(my_off_t) MIN_ROWS_TO_USE_TABLE_CACHE &&
- !table->blob_fields)
+ !table->s->blob_fields)
{
- if (! init_rr_cache(info))
+ if (! init_rr_cache(thd, info))
{
DBUG_PRINT("info",("using rr_from_cache"));
info->read_record=rr_from_cache;
@@ -133,7 +133,7 @@ void init_read_record(READ_RECORD *info,THD *thd, TABLE *table,
if (!table->no_cache &&
(use_record_cache > 0 ||
(int) table->reginfo.lock_type <= (int) TL_READ_HIGH_PRIORITY ||
- !(table->db_options_in_use & HA_OPTION_PACK_RECORD) ||
+ !(table->s->db_options_in_use & HA_OPTION_PACK_RECORD) ||
(use_record_cache < 0 &&
!(table->file->table_flags() & HA_NOT_DELETE_WITH_CACHE))))
VOID(table->file->extra_opt(HA_EXTRA_CACHE,
@@ -329,23 +329,21 @@ static int rr_unpack_from_buffer(READ_RECORD *info)
}
/* cacheing of records from a database */
-static int init_rr_cache(READ_RECORD *info)
+static int init_rr_cache(THD *thd, READ_RECORD *info)
{
uint rec_cache_size;
- THD *thd= current_thd;
-
DBUG_ENTER("init_rr_cache");
- info->struct_length=3+MAX_REFLENGTH;
- info->reclength=ALIGN_SIZE(info->table->reclength+1);
+ info->struct_length= 3+MAX_REFLENGTH;
+ info->reclength= ALIGN_SIZE(info->table->s->reclength+1);
if (info->reclength < info->struct_length)
- info->reclength=ALIGN_SIZE(info->struct_length);
+ info->reclength= ALIGN_SIZE(info->struct_length);
- info->error_offset=info->table->reclength;
- info->cache_records= thd->variables.read_rnd_buff_size /
- (info->reclength+info->struct_length);
- rec_cache_size=info->cache_records*info->reclength;
- info->rec_cache_size=info->cache_records*info->ref_length;
+ info->error_offset= info->table->s->reclength;
+ info->cache_records= (thd->variables.read_rnd_buff_size /
+ (info->reclength+info->struct_length));
+ rec_cache_size= info->cache_records*info->reclength;
+ info->rec_cache_size= info->cache_records*info->ref_length;
// We have to allocate one more byte to use uint3korr (see comments for it)
if (info->cache_records <= 2 ||
@@ -385,7 +383,8 @@ static int rr_from_cache(READ_RECORD *info)
else
{
error=0;
- memcpy(info->record,info->cache_pos,(size_t) info->table->reclength);
+ memcpy(info->record,info->cache_pos,
+ (size_t) info->table->s->reclength);
}
info->cache_pos+=info->reclength;
return ((int) error);
diff --git a/sql/repl_failsafe.cc b/sql/repl_failsafe.cc
index 7852993b95b..de4ad83fdbb 100644
--- a/sql/repl_failsafe.cc
+++ b/sql/repl_failsafe.cc
@@ -739,7 +739,7 @@ static int fetch_db_tables(THD *thd, MYSQL *mysql, const char *db,
{
bzero((char*) &table, sizeof(table)); //just for safe
table.db= (char*) db;
- table.real_name= (char*) table_name;
+ table.table_name= (char*) table_name;
table.updating= 1;
if (!tables_ok(thd, &table))
diff --git a/sql/slave.cc b/sql/slave.cc
index 6b8559859fc..0bcc1b7e852 100644
--- a/sql/slave.cc
+++ b/sql/slave.cc
@@ -893,7 +893,7 @@ bool tables_ok(THD* thd, TABLE_LIST* tables)
some_tables_updating= 1;
end= strmov(hash_key, tables->db ? tables->db : thd->db);
*end++= '.';
- len= (uint) (strmov(end, tables->real_name) - hash_key);
+ len= (uint) (strmov(end, tables->table_name) - hash_key);
if (do_table_inited) // if there are any do's
{
if (hash_search(&replicate_do_table, (byte*) hash_key, len))
@@ -1520,7 +1520,7 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db,
bzero((char*) &tables,sizeof(tables));
tables.db = (char*)db;
- tables.alias= tables.real_name= (char*)table_name;
+ tables.alias= tables.table_name= (char*)table_name;
/* Drop the table if 'overwrite' is true */
if (overwrite && mysql_rm_table(thd,&tables,1,0)) /* drop if exists */
@@ -1580,7 +1580,7 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db,
error=file->repair(thd,&check_opt) != 0;
thd->net.vio = save_vio;
if (error)
- my_error(ER_INDEX_REBUILD, MYF(0), tables.table->real_name);
+ my_error(ER_INDEX_REBUILD, MYF(0), tables.table->s->table_name);
err:
close_thread_tables(thd);
diff --git a/sql/sp.cc b/sql/sp.cc
index 65dad60cda7..84b126e5ecd 100644
--- a/sql/sp.cc
+++ b/sql/sp.cc
@@ -97,8 +97,8 @@ db_find_routine_aux(THD *thd, int type, sp_name *name,
else
{
for (table= thd->open_tables ; table ; table= table->next)
- if (strcmp(table->table_cache_key, "mysql") == 0 &&
- strcmp(table->real_name, "proc") == 0)
+ if (strcmp(table->s->db, "mysql") == 0 &&
+ strcmp(table->s->table_name, "proc") == 0)
break;
}
if (table)
@@ -109,7 +109,7 @@ db_find_routine_aux(THD *thd, int type, sp_name *name,
memset(&tables, 0, sizeof(tables));
tables.db= (char*)"mysql";
- tables.real_name= tables.alias= (char*)"proc";
+ tables.table_name= tables.alias= (char*)"proc";
if (! (table= open_ltable(thd, &tables, ltype)))
{
*tablep= NULL;
@@ -158,7 +158,7 @@ db_find_routine(THD *thd, int type, sp_name *name, sp_head **sphp)
if (ret != SP_OK)
goto done;
- if (table->fields != MYSQL_PROC_FIELD_COUNT)
+ if (table->s->fields != MYSQL_PROC_FIELD_COUNT)
{
ret= SP_GET_FIELD_FAILED;
goto done;
@@ -356,16 +356,16 @@ db_create_routine(THD *thd, int type, sp_head *sp)
memset(&tables, 0, sizeof(tables));
tables.db= (char*)"mysql";
- tables.real_name= tables.alias= (char*)"proc";
+ tables.table_name= tables.alias= (char*)"proc";
if (! (table= open_ltable(thd, &tables, TL_WRITE)))
ret= SP_OPEN_TABLE_FAILED;
else
{
- restore_record(table, default_values); // Get default values for fields
+ restore_record(table, s->default_values); // Get default values for fields
strxmov(definer, thd->priv_user, "@", thd->priv_host, NullS);
- if (table->fields != MYSQL_PROC_FIELD_COUNT)
+ if (table->s->fields != MYSQL_PROC_FIELD_COUNT)
{
ret= SP_GET_FIELD_FAILED;
goto done;
@@ -562,7 +562,7 @@ db_show_routine_status(THD *thd, int type, const char *wild)
memset(&tables, 0, sizeof(tables));
tables.db= (char*)"mysql";
- tables.real_name= tables.alias= (char*)"proc";
+ tables.table_name= tables.alias= (char*)"proc";
if (! (table= open_ltable(thd, &tables, TL_READ)))
{
@@ -668,8 +668,8 @@ sp_drop_db_routines(THD *thd, char *db)
keylen= sizeof(key);
for (table= thd->open_tables ; table ; table= table->next)
- if (strcmp(table->table_cache_key, "mysql") == 0 &&
- strcmp(table->real_name, "proc") == 0)
+ if (strcmp(table->s->db, "mysql") == 0 &&
+ strcmp(table->s->table_name, "proc") == 0)
break;
if (! table)
{
@@ -677,7 +677,7 @@ sp_drop_db_routines(THD *thd, char *db)
memset(&tables, 0, sizeof(tables));
tables.db= (char*)"mysql";
- tables.real_name= tables.alias= (char*)"proc";
+ tables.table_name= tables.alias= (char*)"proc";
if (! (table= open_ltable(thd, &tables, TL_WRITE)))
DBUG_RETURN(SP_OPEN_TABLE_FAILED);
}
@@ -749,9 +749,9 @@ sp_exists_routine(THD *thd, TABLE_LIST *tables, bool any, bool no_error)
LEX_STRING lex_db;
LEX_STRING lex_name;
lex_db.length= strlen(table->db);
- lex_name.length= strlen(table->real_name);
+ lex_name.length= strlen(table->table_name);
lex_db.str= thd->strmake(table->db, lex_db.length);
- lex_name.str= thd->strmake(table->real_name, lex_name.length);
+ lex_name.str= thd->strmake(table->table_name, lex_name.length);
name= new sp_name(lex_db, lex_name);
name->init_qname(thd);
if (sp_find_procedure(thd, name) != NULL ||
@@ -766,7 +766,7 @@ sp_exists_routine(THD *thd, TABLE_LIST *tables, bool any, bool no_error)
if (!no_error)
{
my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION or PROCEDURE",
- table->real_name);
+ table->table_name);
DBUG_RETURN(-1);
}
DBUG_RETURN(0);
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index 9afc0c04631..3f2969768c5 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -834,10 +834,10 @@ sp_head::restore_lex(THD *thd)
char **tb;
while ((tb= li++))
- if (my_strcasecmp(system_charset_info, tables->real_name, *tb) == 0)
+ if (my_strcasecmp(system_charset_info, tables->table_name, *tb) == 0)
break;
if (! tb)
- m_tables.push_back(&tables->real_name);
+ m_tables.push_back(&tables->table_name);
}
}
#endif
diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc
index ba00c1d3fa7..4628f6746b2 100644
--- a/sql/sql_acl.cc
+++ b/sql/sql_acl.cc
@@ -166,9 +166,9 @@ my_bool acl_init(THD *org_thd, bool dont_read_acl_tables)
thd->db= my_strdup("mysql",MYF(0));
thd->db_length=5; // Safety
bzero((char*) &tables,sizeof(tables));
- tables[0].alias=tables[0].real_name=(char*) "host";
- tables[1].alias=tables[1].real_name=(char*) "user";
- tables[2].alias=tables[2].real_name=(char*) "db";
+ tables[0].alias=tables[0].table_name=(char*) "host";
+ tables[1].alias=tables[1].table_name=(char*) "user";
+ tables[2].alias=tables[2].table_name=(char*) "db";
tables[0].next_local= tables[0].next_global= tables+1;
tables[1].next_local= tables[1].next_global= tables+2;
tables[0].lock_type=tables[1].lock_type=tables[2].lock_type=TL_READ;
@@ -210,7 +210,7 @@ my_bool acl_init(THD *org_thd, bool dont_read_acl_tables)
continue;
}
#ifndef TO_BE_REMOVED
- if (table->fields == 8)
+ if (table->s->fields == 8)
{ // Without grant
if (host.access & CREATE_ACL)
host.access|=REFERENCES_ACL | INDEX_ACL | ALTER_ACL | CREATE_TMP_ACL;
@@ -233,7 +233,7 @@ my_bool acl_init(THD *org_thd, bool dont_read_acl_tables)
}
DBUG_PRINT("info",("user table fields: %d, password length: %d",
- table->fields, table->field[2]->field_length));
+ table->s->fields, table->field[2]->field_length));
pthread_mutex_lock(&LOCK_global_system_variables);
if (table->field[2]->field_length < SCRAMBLED_PASSWORD_CHAR_LENGTH)
@@ -306,23 +306,24 @@ my_bool acl_init(THD *org_thd, bool dont_read_acl_tables)
if it is pre 5.0.1 privilege table then map CREATE privilege on
CREATE VIEW & SHOW VIEW privileges
*/
- if (table->fields <= 31 && (user.access & CREATE_ACL))
+ if (table->s->fields <= 31 && (user.access & CREATE_ACL))
user.access|= (CREATE_VIEW_ACL | SHOW_VIEW_ACL);
/*
if it is pre 5.0.2 privilege table then map CREATE/ALTER privilege on
CREATE PROCEDURE & ALTER PROCEDURE privileges
*/
- if (table->fields <= 33 && (user.access & CREATE_ACL))
+ if (table->s->fields <= 33 && (user.access & CREATE_ACL))
user.access|= CREATE_PROC_ACL;
- if (table->fields <= 33 && (user.access & ALTER_ACL))
+ if (table->s->fields <= 33 && (user.access & ALTER_ACL))
user.access|= ALTER_PROC_ACL;
user.sort= get_sort(2,user.host.hostname,user.user);
user.hostname_length= (user.host.hostname ?
(uint) strlen(user.host.hostname) : 0);
- if (table->fields >= 31) /* Starting from 4.0.2 we have more fields */
+ /* Starting from 4.0.2 we have more fields */
+ if (table->s->fields >= 31)
{
char *ssl_type=get_field(&mem, table->field[next_field++]);
if (!ssl_type)
@@ -348,7 +349,7 @@ my_bool acl_init(THD *org_thd, bool dont_read_acl_tables)
user.user_resource.conn_per_hour)
mqh_used=1;
- if (table->fields >= 36)
+ if (table->s->fields >= 36)
{
/* Starting from 5.0.3 we have max_user_connections field */
ptr= get_field(&mem, table->field[next_field++]);
@@ -362,7 +363,7 @@ my_bool acl_init(THD *org_thd, bool dont_read_acl_tables)
user.ssl_type=SSL_TYPE_NONE;
bzero((char *)&(user.user_resource),sizeof(user.user_resource));
#ifndef TO_BE_REMOVED
- if (table->fields <= 13)
+ if (table->s->fields <= 13)
{ // Without grant
if (user.access & CREATE_ACL)
user.access|=REFERENCES_ACL | INDEX_ACL | ALTER_ACL;
@@ -410,7 +411,7 @@ my_bool acl_init(THD *org_thd, bool dont_read_acl_tables)
db.access=fix_rights_for_db(db.access);
db.sort=get_sort(3,db.host.hostname,db.db,db.user);
#ifndef TO_BE_REMOVED
- if (table->fields <= 9)
+ if (table->s->fields <= 9)
{ // Without grant
if (db.access & CREATE_ACL)
db.access|=REFERENCES_ACL | INDEX_ACL | ALTER_ACL;
@@ -1464,7 +1465,7 @@ static bool update_user_table(THD *thd, const char *host, const char *user,
DBUG_PRINT("enter",("user: %s host: %s",user,host));
bzero((char*) &tables,sizeof(tables));
- tables.alias=tables.real_name=(char*) "user";
+ tables.alias=tables.table_name=(char*) "user";
tables.db=(char*) "mysql";
#ifdef HAVE_REPLICATION
@@ -1527,7 +1528,7 @@ static bool test_if_create_new_users(THD *thd)
ulong db_access;
bzero((char*) &tl,sizeof(tl));
tl.db= (char*) "mysql";
- tl.real_name= (char*) "user";
+ tl.table_name= (char*) "user";
db_access=acl_get(thd->host, thd->ip,
thd->priv_user, tl.db, 0);
@@ -1607,7 +1608,7 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo,
goto end;
}
old_row_exists = 0;
- restore_record(table,default_values); // cp empty row from default_values
+ restore_record(table,s->default_values);
table->field[0]->store(combo.host.str,combo.host.length,
system_charset_info);
table->field[1]->store(combo.user.str,combo.user.length,
@@ -1654,8 +1655,8 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo,
(*tmp_field)->store(&what, 1, &my_charset_latin1);
}
rights= get_access(table, 3, &next_field);
- DBUG_PRINT("info",("table->fields: %d",table->fields));
- if (table->fields >= 31) /* From 4.0.0 we have more fields */
+ DBUG_PRINT("info",("table fields: %d",table->s->fields));
+ if (table->s->fields >= 31) /* From 4.0.0 we have more fields */
{
/* We write down SSL related ACL stuff */
switch (lex->ssl_type) {
@@ -1704,7 +1705,7 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo,
table->field[next_field+1]->store((longlong) mqh.updates);
if (mqh.specified_limits & USER_RESOURCES::CONNECTIONS_PER_HOUR)
table->field[next_field+2]->store((longlong) mqh.conn_per_hour);
- if (table->fields >= 36 &&
+ if (table->s->fields >= 36 &&
(mqh.specified_limits & USER_RESOURCES::USER_CONNECTIONS))
table->field[next_field+3]->store((longlong) mqh.user_conn);
mqh_used= mqh_used || mqh.questions || mqh.updates || mqh.conn_per_hour;
@@ -1808,7 +1809,7 @@ static int replace_db_table(TABLE *table, const char *db,
goto abort;
}
old_row_exists = 0;
- restore_record(table,default_values); // cp empty row from default_values
+ restore_record(table, s->default_values);
table->field[0]->store(combo.host.str,combo.host.length, system_charset_info);
table->field[1]->store(db,(uint) strlen(db), system_charset_info);
table->field[2]->store(combo.user.str,combo.user.length, system_charset_info);
@@ -1820,7 +1821,7 @@ static int replace_db_table(TABLE *table, const char *db,
}
store_rights=get_rights_for_db(rights);
- for (i= 3, priv= 1; i < table->fields; i++, priv <<= 1)
+ for (i= 3, priv= 1; i < table->s->fields; i++, priv <<= 1)
{
if (priv & store_rights) // do it if priv is chosen
table->field [i]->store(&what,1, &my_charset_latin1);// set requested privileges
@@ -2191,7 +2192,7 @@ static int replace_column_table(GRANT_TABLE *g_t,
continue; /* purecov: inspected */
}
old_row_exists = 0;
- restore_record(table,default_values); // Get empty record
+ restore_record(table, s->default_values); // Get empty record
key_restore(table->record[0],key,table->key_info,
key_prefix_length);
table->field[4]->store(xx->column.ptr(),xx->column.length(),
@@ -2343,7 +2344,7 @@ static int replace_table_table(THD *thd, GRANT_TABLE *grant_table,
DBUG_RETURN(-1); /* purecov: deadcode */
}
- restore_record(table,default_values); // Get empty record
+ restore_record(table, s->default_values); // Get empty record
table->field[0]->store(combo.host.str,combo.host.length, system_charset_info);
table->field[1]->store(db,(uint) strlen(db), system_charset_info);
table->field[2]->store(combo.user.str,combo.user.length, system_charset_info);
@@ -2464,7 +2465,7 @@ static int replace_proc_table(THD *thd, GRANT_NAME *grant_name,
DBUG_RETURN(-1);
}
- restore_record(table,default_values); // Get empty record
+ restore_record(table, s->default_values); // Get empty record
table->field[0]->store(combo.host.str,combo.host.length, &my_charset_latin1);
table->field[1]->store(db,(uint) strlen(db), &my_charset_latin1);
table->field[2]->store(combo.user.str,combo.user.length, &my_charset_latin1);
@@ -2573,7 +2574,7 @@ bool mysql_table_grant(THD *thd, TABLE_LIST *table_list,
LEX_USER *Str;
TABLE_LIST tables[3];
bool create_new_users=0;
- char *db_name, *real_name;
+ char *db_name, *table_name;
DBUG_ENTER("mysql_table_grant");
if (!initialized)
@@ -2625,7 +2626,7 @@ bool mysql_table_grant(THD *thd, TABLE_LIST *table_list,
{
char buf[FN_REFLEN];
sprintf(buf,"%s/%s/%s.frm",mysql_data_home, table_list->db,
- table_list->real_name);
+ table_list->table_name);
fn_format(buf,buf,"","",4+16+32);
if (access(buf,F_OK))
{
@@ -2648,9 +2649,9 @@ bool mysql_table_grant(THD *thd, TABLE_LIST *table_list,
/* open the mysql.tables_priv and mysql.columns_priv tables */
bzero((char*) &tables,sizeof(tables));
- tables[0].alias=tables[0].real_name= (char*) "user";
- tables[1].alias=tables[1].real_name= (char*) "tables_priv";
- tables[2].alias=tables[2].real_name= (char*) "columns_priv";
+ tables[0].alias=tables[0].table_name= (char*) "user";
+ tables[1].alias=tables[1].table_name= (char*) "tables_priv";
+ tables[2].alias=tables[2].table_name= (char*) "columns_priv";
tables[0].next_local= tables[0].next_global= tables+1;
/* Don't open column table if we don't need it ! */
tables[1].next_local=
@@ -2717,24 +2718,24 @@ bool mysql_table_grant(THD *thd, TABLE_LIST *table_list,
db_name= (table_list->view_db.length ?
table_list->view_db.str :
table_list->db);
- real_name= (table_list->view_name.length ?
+ table_name= (table_list->view_name.length ?
table_list->view_name.str :
- table_list->real_name);
+ table_list->table_name);
/* Find/create cached table grant */
grant_table= table_hash_search(Str->host.str, NullS, db_name,
- Str->user.str, real_name, 1);
+ Str->user.str, table_name, 1);
if (!grant_table)
{
if (revoke_grant)
{
my_error(ER_NONEXISTING_TABLE_GRANT, MYF(0),
- Str->user.str, Str->host.str, table_list->real_name);
+ Str->user.str, Str->host.str, table_list->table_name);
result= TRUE;
continue;
}
grant_table = new GRANT_TABLE (Str->host.str, db_name,
- Str->user.str, real_name,
+ Str->user.str, table_name,
rights,
column_priv);
if (!grant_table) // end of memory
@@ -2780,7 +2781,7 @@ bool mysql_table_grant(THD *thd, TABLE_LIST *table_list,
/* update table and columns */
if (replace_table_table(thd, grant_table, tables[1].table, *Str,
- db_name, real_name,
+ db_name, table_name,
rights, column_priv, revoke_grant))
{
/* Should only happen if table is crashed */
@@ -2790,7 +2791,7 @@ bool mysql_table_grant(THD *thd, TABLE_LIST *table_list,
{
if ((replace_column_table(grant_table, tables[2].table, *Str,
columns,
- db_name, real_name,
+ db_name, table_name,
rights, revoke_grant)))
{
result= TRUE;
@@ -2831,7 +2832,7 @@ bool mysql_procedure_grant(THD *thd, TABLE_LIST *table_list,
LEX_USER *Str;
TABLE_LIST tables[2];
bool create_new_users=0, result=0;
- char *db_name, *real_name;
+ char *db_name, *table_name;
DBUG_ENTER("mysql_procedure_grant");
if (!initialized)
@@ -2858,8 +2859,8 @@ bool mysql_procedure_grant(THD *thd, TABLE_LIST *table_list,
/* open the mysql.user and mysql.procs_priv tables */
bzero((char*) &tables,sizeof(tables));
- tables[0].alias=tables[0].real_name= (char*) "user";
- tables[1].alias=tables[1].real_name= (char*) "procs_priv";
+ tables[0].alias=tables[0].table_name= (char*) "user";
+ tables[1].alias=tables[1].table_name= (char*) "procs_priv";
tables[0].next_local= tables[0].next_global= tables+1;
tables[0].lock_type=tables[1].lock_type=TL_WRITE;
tables[0].db=tables[1].db=(char*) "mysql";
@@ -2920,22 +2921,22 @@ bool mysql_procedure_grant(THD *thd, TABLE_LIST *table_list,
}
db_name= table_list->db;
- real_name= table_list->real_name;
+ table_name= table_list->table_name;
grant_name= proc_hash_search(Str->host.str, NullS, db_name,
- Str->user.str, real_name, 1);
+ Str->user.str, table_name, 1);
if (!grant_name)
{
if (revoke_grant)
{
if (!no_error)
my_error(ER_NONEXISTING_PROC_GRANT, MYF(0),
- Str->user.str, Str->host.str, real_name);
+ Str->user.str, Str->host.str, table_name);
result= TRUE;
continue;
}
grant_name= new GRANT_NAME(Str->host.str, db_name,
- Str->user.str, real_name,
+ Str->user.str, table_name,
rights);
if (!grant_name)
{
@@ -2946,7 +2947,7 @@ bool mysql_procedure_grant(THD *thd, TABLE_LIST *table_list,
}
if (replace_proc_table(thd, grant_name, tables[1].table, *Str,
- db_name, real_name, rights, revoke_grant))
+ db_name, table_name, rights, revoke_grant))
{
result= TRUE;
continue;
@@ -2987,8 +2988,8 @@ bool mysql_grant(THD *thd, const char *db, List <LEX_USER> &list,
/* open the mysql.user and mysql.db tables */
bzero((char*) &tables,sizeof(tables));
- tables[0].alias=tables[0].real_name=(char*) "user";
- tables[1].alias=tables[1].real_name=(char*) "db";
+ tables[0].alias=tables[0].table_name=(char*) "user";
+ tables[1].alias=tables[1].table_name=(char*) "db";
tables[0].next_local= tables[0].next_global= tables+1;
tables[0].lock_type=tables[1].lock_type=TL_WRITE;
tables[0].db=tables[1].db=(char*) "mysql";
@@ -3112,9 +3113,9 @@ my_bool grant_init(THD *org_thd)
thd->db= my_strdup("mysql",MYF(0));
thd->db_length=5; // Safety
bzero((char*) &tables, sizeof(tables));
- tables[0].alias=tables[0].real_name= (char*) "tables_priv";
- tables[1].alias=tables[1].real_name= (char*) "columns_priv";
- tables[2].alias=tables[2].real_name= (char*) "procs_priv";
+ tables[0].alias=tables[0].table_name= (char*) "tables_priv";
+ tables[1].alias=tables[1].table_name= (char*) "columns_priv";
+ tables[2].alias=tables[2].table_name= (char*) "procs_priv";
tables[0].next_local= tables[0].next_global= tables+1;
tables[1].next_local= tables[1].next_global= tables+2;
tables[0].lock_type=tables[1].lock_type=tables[2].lock_type=TL_READ;
@@ -3327,7 +3328,7 @@ bool check_grant(THD *thd, ulong want_access, TABLE_LIST *tables,
continue; // Already checked
}
if (!(grant_table= table_hash_search(thd->host,thd->ip,
- table->db,user, table->real_name,0)))
+ table->db,user, table->table_name,0)))
{
want_access &= ~table->grant.privilege;
goto err; // No grants
@@ -3363,14 +3364,14 @@ err:
command,
thd->priv_user,
thd->host_or_ip,
- table ? table->real_name : "unknown");
+ table ? table->table_name : "unknown");
}
DBUG_RETURN(1);
}
bool check_grant_column(THD *thd, GRANT_INFO *grant,
- char *db_name, char *table_name,
+ const char *db_name, const char *table_name,
const char *name, uint length, uint show_tables)
{
GRANT_TABLE *grant_table;
@@ -3429,7 +3430,7 @@ err:
bool check_grant_all_columns(THD *thd, ulong want_access, GRANT_INFO *grant,
- char* db_name, char *table_name,
+ const char* db_name, const char *table_name,
Field_iterator *fields)
{
GRANT_TABLE *grant_table;
@@ -3552,7 +3553,7 @@ bool check_grant_procedure(THD *thd, ulong want_access,
{
GRANT_NAME *grant_proc;
if ((grant_proc= proc_hash_search(host,thd->ip,
- table->db, user, table->real_name, 0)))
+ table->db, user, table->table_name, 0)))
table->grant.privilege|= grant_proc->privs;
if (want_access & ~table->grant.privilege)
@@ -3570,7 +3571,7 @@ err:
char buff[1024];
const char *command="";
if (table)
- strxmov(buff, table->db, ".", table->real_name, NullS);
+ strxmov(buff, table->db, ".", table->table_name, NullS);
if (want_access & EXECUTE_ACL)
command= "execute";
else if (want_access & ALTER_PROC_ACL)
@@ -3600,7 +3601,7 @@ ulong get_table_grant(THD *thd, TABLE_LIST *table)
grant_table= NULL;
#else
grant_table= table_hash_search(thd->host, thd->ip, db, user,
- table->real_name, 0);
+ table->table_name, 0);
#endif
table->grant.grant_table=grant_table; // Remember for column test
table->grant.version=grant_version;
@@ -4169,11 +4170,11 @@ int open_grant_tables(THD *thd, TABLE_LIST *tables)
}
bzero((char*) tables, GRANT_TABLES*sizeof(*tables));
- tables->alias= tables->real_name= (char*) "user";
- (tables+1)->alias= (tables+1)->real_name= (char*) "db";
- (tables+2)->alias= (tables+2)->real_name= (char*) "tables_priv";
- (tables+3)->alias= (tables+3)->real_name= (char*) "columns_priv";
- (tables+4)->alias= (tables+4)->real_name= (char*) "procs_priv";
+ tables->alias= tables->table_name= (char*) "user";
+ (tables+1)->alias= (tables+1)->table_name= (char*) "db";
+ (tables+2)->alias= (tables+2)->table_name= (char*) "tables_priv";
+ (tables+3)->alias= (tables+3)->table_name= (char*) "columns_priv";
+ (tables+4)->alias= (tables+4)->table_name= (char*) "procs_priv";
tables->next_local= tables->next_global= tables+1;
(tables+1)->next_local= (tables+1)->next_global= tables+2;
(tables+2)->next_local= (tables+2)->next_global= tables+3;
@@ -4347,7 +4348,7 @@ static int handle_grant_table(TABLE_LIST *tables, uint table_no, bool drop,
by the searched record, if it exists.
*/
DBUG_PRINT("info",("read table: '%s' search: '%s'@'%s'",
- table->real_name, user_str, host_str));
+ table->s->table_name, user_str, host_str));
host_field->store(host_str, user_from->host.length, system_charset_info);
user_field->store(user_str, user_from->user.length, system_charset_info);
@@ -4390,7 +4391,7 @@ static int handle_grant_table(TABLE_LIST *tables, uint table_no, bool drop,
{
#ifdef EXTRA_DEBUG
DBUG_PRINT("info",("scan table: '%s' search: '%s'@'%s'",
- table->real_name, user_str, host_str));
+ table->s->table_name, user_str, host_str));
#endif
while ((error= table->file->rnd_next(table->record[0])) !=
HA_ERR_END_OF_FILE)
@@ -4439,7 +4440,7 @@ static int handle_grant_table(TABLE_LIST *tables, uint table_no, bool drop,
SYNOPSIS
handle_grant_struct()
- struct_no The number of the structure to handle (0..2).
+ struct_no The number of the structure to handle (0..3).
drop If user_from is to be dropped.
user_from The the user to be searched/dropped/renamed.
user_to The new name for the user if to be renamed,
@@ -4460,6 +4461,7 @@ static int handle_grant_table(TABLE_LIST *tables, uint table_no, bool drop,
RETURN
> 0 At least one element matched.
0 OK, but no element matched.
+ -1 Wrong arguments to function
*/
static int handle_grant_struct(uint struct_no, bool drop,
@@ -4481,8 +4483,7 @@ static int handle_grant_struct(uint struct_no, bool drop,
struct_no, user_from->user.str, user_from->host.str));
/* Get the number of elements in the in-memory structure. */
- switch (struct_no)
- {
+ switch (struct_no) {
case 0:
elements= acl_users.elements;
break;
@@ -4496,7 +4497,6 @@ static int handle_grant_struct(uint struct_no, bool drop,
elements= proc_priv_hash.records;
break;
default:
- DBUG_ASSERT((struct_no < 0) || (struct_no > 3));
return -1;
}
@@ -4511,8 +4511,7 @@ static int handle_grant_struct(uint struct_no, bool drop,
Get a pointer to the element.
Unfortunaltely, the host default differs for the structures.
*/
- switch (struct_no)
- {
+ switch (struct_no) {
case 0:
acl_user= dynamic_element(&acl_users, idx, ACL_USER*);
user= acl_user->user;
@@ -4539,9 +4538,9 @@ static int handle_grant_struct(uint struct_no, bool drop,
break;
}
if (! user)
- user= "";
+ user= "";
if (! host)
- host= "";
+ host= "";
#ifdef EXTRA_DEBUG
DBUG_PRINT("loop",("scan struct: %u index: %u user: '%s' host: '%s'",
struct_no, idx, user, host));
@@ -4576,8 +4575,7 @@ static int handle_grant_struct(uint struct_no, bool drop,
}
else if ( user_to )
{
- switch ( struct_no )
- {
+ switch ( struct_no ) {
case 0:
acl_user->user= strdup_root(&mem, user_to->user.str);
acl_user->host.hostname= strdup_root(&mem, user_to->host.str);
@@ -5186,7 +5184,7 @@ bool sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name)
user_list.empty();
tables->db= (char*)sp_db;
- tables->real_name= tables->alias= (char*)sp_name;
+ tables->table_name= tables->alias= (char*)sp_name;
combo->host.length= strlen(combo->host.str);
combo->user.length= strlen(combo->user.str);
@@ -5271,7 +5269,7 @@ void update_schema_privilege(TABLE *table, char *buff, const char* db,
{
int i= 2;
CHARSET_INFO *cs= system_charset_info;
- restore_record(table, default_values);
+ restore_record(table, s->default_values);
table->field[0]->store(buff, strlen(buff), cs);
if (db)
table->field[i++]->store(db, strlen(db), cs);
diff --git a/sql/sql_acl.h b/sql/sql_acl.h
index 4ebc3ad7707..b129ffcdcf8 100644
--- a/sql/sql_acl.h
+++ b/sql/sql_acl.h
@@ -193,10 +193,10 @@ void grant_reload(THD *thd);
bool check_grant(THD *thd, ulong want_access, TABLE_LIST *tables,
uint show_command, uint number, bool dont_print_error);
bool check_grant_column (THD *thd, GRANT_INFO *grant,
- char *db_name, char *table_name,
+ const char *db_name, const char *table_name,
const char *name, uint length, uint show_command=0);
bool check_grant_all_columns(THD *thd, ulong want_access, GRANT_INFO *grant,
- char* db_name, char *table_name,
+ const char* db_name, const char *table_name,
Field_iterator *fields);
bool check_grant_procedure(THD *thd, ulong want_access,
TABLE_LIST *procs, bool no_error);
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 0b0bf6df7ad..5e9a1f9eb55 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -49,8 +49,8 @@ extern "C" byte *table_cache_key(const byte *record,uint *length,
my_bool not_used __attribute__((unused)))
{
TABLE *entry=(TABLE*) record;
- *length=entry->key_length;
- return (byte*) entry->table_cache_key;
+ *length= entry->s->key_length;
+ return (byte*) entry->s->table_cache_key;
}
bool table_cache_init(void)
@@ -148,20 +148,21 @@ OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *wild)
{
OPEN_TABLE_LIST *table;
TABLE *entry=(TABLE*) hash_element(&open_cache,idx);
+ TABLE_SHARE *share= entry->s;
- DBUG_ASSERT(entry->real_name);
- if ((!entry->real_name)) // To be removed
+ DBUG_ASSERT(share->table_name);
+ if ((!share->table_name)) // To be removed
continue; // Shouldn't happen
if (wild)
{
- strxmov(name,entry->table_cache_key,".",entry->real_name,NullS);
+ strxmov(name,share->table_cache_key,".",share->table_name,NullS);
if (wild_compare(name,wild,0))
continue;
}
/* Check if user has SELECT privilege for any column in the table */
- table_list.db= (char*) entry->table_cache_key;
- table_list.real_name= entry->real_name;
+ table_list.db= (char*) share->db;
+ table_list.table_name= (char*) share->table_name;
table_list.grant.privilege=0;
if (check_table_access(thd,SELECT_ACL | EXTRA_ACL,&table_list,1))
@@ -169,8 +170,8 @@ OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *wild)
/* need to check if we haven't already listed it */
for (table= open_list ; table ; table=table->next)
{
- if (!strcmp(table->table,entry->real_name) &&
- !strcmp(table->db,entry->table_cache_key))
+ if (!strcmp(table->table,share->table_name) &&
+ !strcmp(table->db,entry->s->db))
{
if (entry->in_use)
table->in_use++;
@@ -182,15 +183,15 @@ OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *wild)
if (table)
continue;
if (!(*start_list = (OPEN_TABLE_LIST *)
- sql_alloc(sizeof(**start_list)+entry->key_length)))
+ sql_alloc(sizeof(**start_list)+share->key_length)))
{
open_list=0; // Out of memory
break;
}
strmov((*start_list)->table=
strmov(((*start_list)->db= (char*) ((*start_list)+1)),
- entry->table_cache_key)+1,
- entry->real_name);
+ entry->s->db)+1,
+ entry->s->table_name);
(*start_list)->in_use= entry->in_use ? 1 : 0;
(*start_list)->locked= entry->locked_by_name ? 1 : 0;
start_list= &(*start_list)->next;
@@ -287,7 +288,7 @@ bool close_cached_tables(THD *thd, bool if_wait_for_refresh,
bool found=0;
for (TABLE_LIST *table= tables; table; table= table->next_local)
{
- if (remove_table_from_cache(thd, table->db, table->real_name, 1))
+ if (remove_table_from_cache(thd, table->db, table->table_name, 1))
found=1;
}
if (!found)
@@ -319,7 +320,7 @@ bool close_cached_tables(THD *thd, bool if_wait_for_refresh,
for (uint idx=0 ; idx < open_cache.records ; idx++)
{
TABLE *table=(TABLE*) hash_element(&open_cache,idx);
- if ((table->version) < refresh_version && table->db_stat)
+ if ((table->s->version) < refresh_version && table->db_stat)
{
found=1;
pthread_cond_wait(&COND_refresh,&LOCK_open);
@@ -337,7 +338,7 @@ bool close_cached_tables(THD *thd, bool if_wait_for_refresh,
thd->in_lock_tables=0;
/* Set version for table */
for (TABLE *table=thd->open_tables; table ; table= table->next)
- table->version=refresh_version;
+ table->s->version= refresh_version;
}
VOID(pthread_mutex_unlock(&LOCK_open));
if (if_wait_for_refresh)
@@ -439,7 +440,7 @@ bool close_thread_table(THD *thd, TABLE **table_ptr)
DBUG_ASSERT(table->file->inited == handler::NONE);
*table_ptr=table->next;
- if (table->version != refresh_version ||
+ if (table->s->version != refresh_version ||
thd->version != refresh_version || !table->db_stat)
{
VOID(hash_delete(&open_cache,(byte*) table));
@@ -447,9 +448,9 @@ bool close_thread_table(THD *thd, TABLE **table_ptr)
}
else
{
- if (table->flush_version != flush_version)
+ if (table->s->flush_version != flush_version)
{
- table->flush_version=flush_version;
+ table->s->flush_version= flush_version;
table->file->extra(HA_EXTRA_FLUSH);
}
else
@@ -477,8 +478,8 @@ void close_temporary(TABLE *table,bool delete_table)
{
DBUG_ENTER("close_temporary");
char path[FN_REFLEN];
- db_type table_type=table->db_type;
- strmov(path,table->path);
+ db_type table_type=table->s->db_type;
+ strmov(path,table->s->path);
free_io_cache(table);
closefrm(table);
my_free((char*) table,MYF(0));
@@ -507,7 +508,7 @@ void close_temporary_tables(THD *thd)
enough; indeed it is enough, because table->key_length is greater (by 8,
because of server_id and thread_id) than db||table.
*/
- query_buf_size+= table->key_length+1;
+ query_buf_size+= table->s->key_length+1;
if ((query = alloc_root(thd->mem_root, query_buf_size)))
// Better add "if exists", in case a RESET MASTER has been done
@@ -518,14 +519,10 @@ void close_temporary_tables(THD *thd)
if (query) // we might be out of memory, but this is not fatal
{
// skip temporary tables not created directly by the user
- if (table->real_name[0] != '#')
+ if (table->s->table_name[0] != '#')
found_user_tables = 1;
- /*
- Here we assume table_cache_key always starts
- with \0 terminated db name
- */
- end = strxmov(end,"`",table->table_cache_key,"`.`",
- table->real_name,"`,", NullS);
+ end = strxmov(end,"`",table->s->db,"`.`",
+ table->s->table_name,"`,", NullS);
}
next=table->next;
close_temporary(table);
@@ -579,14 +576,14 @@ TABLE_LIST *find_table_in_list(TABLE_LIST *table,
{
for (; table; table= *(TABLE_LIST **) ((char*) table + offset))
{
- if ((table->table == 0 || table->table->tmp_table == NO_TMP_TABLE) &&
+ if ((table->table == 0 || table->table->s->tmp_table == NO_TMP_TABLE) &&
((!strcmp(table->db, db_name) &&
- !strcmp(table->real_name, table_name)) ||
+ !strcmp(table->table_name, table_name)) ||
(table->view &&
!my_strcasecmp(table_alias_charset,
- table->table->table_cache_key, db_name) &&
+ table->db, db_name) &&
!my_strcasecmp(table_alias_charset,
- table->table->table_name, table_name))))
+ table->table->alias, table_name))))
break;
}
}
@@ -594,12 +591,12 @@ TABLE_LIST *find_table_in_list(TABLE_LIST *table,
{
for (; table; table= *(TABLE_LIST **) ((char*) table + offset))
{
- if ((table->table == 0 || table->table->tmp_table == NO_TMP_TABLE) &&
+ if ((table->table == 0 || table->table->s->tmp_table == NO_TMP_TABLE) &&
((!strcmp(table->db, db_name) &&
- !strcmp(table->real_name, table_name)) ||
+ !strcmp(table->table_name, table_name)) ||
(table->view &&
- !strcmp(table->table->table_cache_key, db_name) &&
- !strcmp(table->table->table_name, table_name))))
+ !strcmp(table->table->s->db, db_name) &&
+ !strcmp(table->table->alias, table_name))))
break;
}
}
@@ -625,27 +622,27 @@ TABLE_LIST* unique_table(TABLE_LIST *table, TABLE_LIST *table_list)
DBUG_ENTER("unique_table");
DBUG_PRINT("enter", ("table alias: %s", table->alias));
TABLE_LIST *res;
- const char *d_name= table->db, *t_name= table->real_name;
+ const char *d_name= table->db, *t_name= table->table_name;
char d_name_buff[MAX_ALIAS_NAME], t_name_buff[MAX_ALIAS_NAME];
/* temporary table is always unique */
- if (table->table && table->table->tmp_table != NO_TMP_TABLE)
+ if (table->table && table->table->s->tmp_table != NO_TMP_TABLE)
return 0;
if (table->view)
{
/* it is view and table opened */
if (lower_case_table_names)
{
- strmov(t_name_buff, table->table->table_name);
+ strmov(t_name_buff, table->table->alias);
my_casedn_str(files_charset_info, t_name_buff);
t_name= t_name_buff;
- strmov(d_name_buff, table->table->table_cache_key);
+ strmov(d_name_buff, table->table->s->db);
my_casedn_str(files_charset_info, d_name_buff);
d_name= d_name_buff;
}
else
{
- d_name= table->table->table_cache_key;
- t_name= table->table->table_name;
+ d_name= table->table->s->db;
+ t_name= table->table->alias;
}
}
@@ -677,8 +674,8 @@ TABLE **find_temporary_table(THD *thd, const char *db, const char *table_name)
prev= &thd->temporary_tables;
for (table=thd->temporary_tables ; table ; table=table->next)
{
- if (table->key_length == key_length &&
- !memcmp(table->table_cache_key,key,key_length))
+ if (table->s->key_length == key_length &&
+ !memcmp(table->s->table_cache_key,key,key_length))
return prev;
prev= &table->next;
}
@@ -706,22 +703,26 @@ bool close_temporary_table(THD *thd, const char *db, const char *table_name)
Prepares a table cache key, which is the concatenation of db, table_name and
thd->slave_proxy_id, separated by '\0'.
*/
+
bool rename_temporary_table(THD* thd, TABLE *table, const char *db,
const char *table_name)
{
char *key;
+ TABLE_SHARE *share= table->s;
+
if (!(key=(char*) alloc_root(&table->mem_root,
(uint) strlen(db)+
(uint) strlen(table_name)+6+4)))
return 1; /* purecov: inspected */
- table->key_length=(uint)
- (strmov((table->real_name=strmov(table->table_cache_key=key,
- db)+1),
- table_name) - table->table_cache_key)+1;
- int4store(key+table->key_length,thd->server_id);
- table->key_length += 4;
- int4store(key+table->key_length,thd->variables.pseudo_thread_id);
- table->key_length += 4;
+ share->key_length= (uint)
+ (strmov(((char*) share->table_name= strmov(share->table_cache_key= key,
+ db)+1),
+ table_name) - share->table_cache_key)+1;
+ share->db= share->table_cache_key;
+ int4store(key+share->key_length, thd->server_id);
+ share->key_length+= 4;
+ int4store(key+share->key_length, thd->variables.pseudo_thread_id);
+ share->key_length+= 4;
return 0;
}
@@ -752,15 +753,16 @@ static void relink_unused(TABLE *table)
TABLE *unlink_open_table(THD *thd, TABLE *list, TABLE *find)
{
char key[MAX_DBKEY_LENGTH];
- uint key_length=find->key_length;
+ uint key_length= find->s->key_length;
TABLE *start=list,**prev,*next;
prev= &start;
- memcpy(key,find->table_cache_key,key_length);
+
+ memcpy(key, find->s->table_cache_key, key_length);
for (; list ; list=next)
{
next=list->next;
- if (list->key_length == key_length &&
- !memcmp(list->table_cache_key,key,key_length))
+ if (list->s->key_length == key_length &&
+ !memcmp(list->s->table_cache_key, key, key_length))
{
if (thd->locked_tables)
mysql_lock_remove(thd, thd->locked_tables,list);
@@ -811,12 +813,13 @@ TABLE *reopen_name_locked_table(THD* thd, TABLE_LIST* table_list)
DBUG_ENTER("reopen_name_locked_table");
if (thd->killed)
DBUG_RETURN(0);
- TABLE* table;
+ TABLE *table;
+ TABLE_SHARE *share;
if (!(table = table_list->table))
DBUG_RETURN(0);
char* db = thd->db ? thd->db : table_list->db;
- char* table_name = table_list->real_name;
+ char* table_name = table_list->table_name;
char key[MAX_DBKEY_LENGTH];
uint key_length;
key_length=(uint) (strmov(strmov(key,db)+1,table_name)-key)+1;
@@ -824,8 +827,8 @@ TABLE *reopen_name_locked_table(THD* thd, TABLE_LIST* table_list)
pthread_mutex_lock(&LOCK_open);
if (open_unireg_entry(thd, table, db, table_name, table_name, 0,
thd->mem_root) ||
- !(table->table_cache_key =memdup_root(&table->mem_root,(char*) key,
- key_length)))
+ !(table->s->table_cache_key= memdup_root(&table->mem_root, (char*) key,
+ key_length)))
{
delete table->triggers;
closefrm(table);
@@ -833,9 +836,11 @@ TABLE *reopen_name_locked_table(THD* thd, TABLE_LIST* table_list)
DBUG_RETURN(0);
}
- table->key_length=key_length;
- table->version=0;
- table->flush_version=0;
+ share= table->s;
+ share->db= share->table_cache_key;
+ share->key_length=key_length;
+ share->version=0;
+ share->flush_version=0;
table->in_use = thd;
check_unused();
pthread_mutex_unlock(&LOCK_open);
@@ -846,8 +851,8 @@ TABLE *reopen_name_locked_table(THD* thd, TABLE_LIST* table_list)
table->const_table=0;
table->outer_join= table->null_row= table->maybe_null= table->force_index= 0;
table->status=STATUS_NO_RECORD;
- table->keys_in_use_for_query= table->keys_in_use;
- table->used_keys= table->keys_for_keyread;
+ table->keys_in_use_for_query= share->keys_in_use;
+ table->used_keys= share->keys_for_keyread;
DBUG_RETURN(table);
}
@@ -877,7 +882,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
if (thd->killed)
DBUG_RETURN(0);
key_length= (uint) (strmov(strmov(key, table_list->db)+1,
- table_list->real_name)-key)+1;
+ table_list->table_name)-key)+1;
int4store(key + key_length, thd->server_id);
int4store(key + key_length + 4, thd->variables.pseudo_thread_id);
@@ -885,13 +890,13 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
{
for (table= thd->temporary_tables; table ; table=table->next)
{
- if (table->key_length == key_length + TMP_TABLE_KEY_EXTRA &&
- !memcmp(table->table_cache_key, key,
+ if (table->s->key_length == key_length + TMP_TABLE_KEY_EXTRA &&
+ !memcmp(table->s->table_cache_key, key,
key_length + TMP_TABLE_KEY_EXTRA))
{
if (table->query_id == thd->query_id)
{
- my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->table_name);
+ my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->alias);
DBUG_RETURN(0);
}
table->query_id= thd->query_id;
@@ -907,9 +912,9 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
{ // Using table locks
for (table=thd->open_tables; table ; table=table->next)
{
- if (table->key_length == key_length &&
- !memcmp(table->table_cache_key,key,key_length) &&
- !my_strcasecmp(system_charset_info, table->table_name, alias) &&
+ if (table->s->key_length == key_length &&
+ !memcmp(table->s->table_cache_key,key,key_length) &&
+ !my_strcasecmp(system_charset_info, table->alias, alias) &&
table->query_id != thd->query_id)
{
table->query_id=thd->query_id;
@@ -925,7 +930,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
{
char path[FN_REFLEN];
strxnmov(path, FN_REFLEN, mysql_data_home, "/", table_list->db, "/",
- table_list->real_name, reg_ext, NullS);
+ table_list->table_name, reg_ext, NullS);
(void) unpack_filename(path, path);
if (mysql_frm_type(path) == FRMTYPE_VIEW)
{
@@ -933,7 +938,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
table= &tab;
VOID(pthread_mutex_lock(&LOCK_open));
if (open_unireg_entry(thd, table, table_list->db,
- table_list->real_name,
+ table_list->table_name,
alias, table_list, mem_root))
{
table->next=table->prev=table;
@@ -972,7 +977,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
table && table->in_use ;
table = (TABLE*) hash_next(&open_cache,(byte*) key,key_length))
{
- if (table->version != refresh_version)
+ if (table->s->version != refresh_version)
{
/*
** There is a refresh in progress for this table
@@ -1004,6 +1009,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
}
else
{
+ TABLE_SHARE *share;
/* Free cache if too big */
while (open_cache.records > table_cache_size && unused_tables)
VOID(hash_delete(&open_cache,(byte*) unused_tables)); /* purecov: tested */
@@ -1014,11 +1020,12 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
VOID(pthread_mutex_unlock(&LOCK_open));
DBUG_RETURN(NULL);
}
- if (open_unireg_entry(thd, table, table_list->db, table_list->real_name,
+ if (open_unireg_entry(thd, table, table_list->db, table_list->table_name,
alias, table_list, mem_root) ||
(!table_list->view &&
- !(table->table_cache_key= memdup_root(&table->mem_root, (char*) key,
- key_length))))
+ !(table->s->table_cache_key= memdup_root(&table->mem_root,
+ (char*) key,
+ key_length))))
{
table->next=table->prev=table;
free_cache_entry(table);
@@ -1031,9 +1038,11 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
VOID(pthread_mutex_unlock(&LOCK_open));
DBUG_RETURN(0); // VIEW
}
- table->key_length=key_length;
- table->version=refresh_version;
- table->flush_version=flush_version;
+ share= table->s;
+ share->db= share->table_cache_key;
+ share->key_length= key_length;
+ share->version= refresh_version;
+ share->flush_version= flush_version;
DBUG_PRINT("info", ("inserting table %p into the cache", table));
VOID(my_hash_insert(&open_cache,(byte*) table));
}
@@ -1051,16 +1060,14 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
reset:
if (thd->lex->need_correct_ident())
table->alias_name_used= my_strcasecmp(table_alias_charset,
- table->real_name, alias);
+ table->s->table_name, alias);
/* Fix alias if table name changes */
- if (strcmp(table->table_name, alias))
+ if (strcmp(table->alias, alias))
{
uint length=(uint) strlen(alias)+1;
- table->table_name= (char*) my_realloc(table->table_name,length,
- MYF(MY_WME));
- memcpy(table->table_name,alias,length);
- for (uint i=0 ; i < table->fields ; i++)
- table->field[i]->table_name=table->table_name;
+ table->alias= (char*) my_realloc((char*) table->alias, length,
+ MYF(MY_WME));
+ memcpy((char*) table->alias, alias, length);
}
/* These variables are also set in reopen_table() */
table->tablenr=thd->current_tablenr++;
@@ -1068,9 +1075,9 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
table->const_table=0;
table->outer_join= table->null_row= table->maybe_null= table->force_index= 0;
table->status=STATUS_NO_RECORD;
- table->keys_in_use_for_query= table->keys_in_use;
+ table->keys_in_use_for_query= table->s->keys_in_use;
table->insert_values= 0;
- table->used_keys= table->keys_for_keyread;
+ table->used_keys= table->s->keys_for_keyread;
if (table->timestamp_field)
table->timestamp_field_type= table->timestamp_field->get_auto_set_type();
table_list->updatable= 1; // It is not derived table nor non-updatable VIEW
@@ -1086,8 +1093,8 @@ TABLE *find_locked_table(THD *thd, const char *db,const char *table_name)
for (TABLE *table=thd->open_tables; table ; table=table->next)
{
- if (table->key_length == key_length &&
- !memcmp(table->table_cache_key,key,key_length))
+ if (table->s->key_length == key_length &&
+ !memcmp(table->s->table_cache_key,key,key_length))
return table;
}
return(0);
@@ -1104,9 +1111,9 @@ TABLE *find_locked_table(THD *thd, const char *db,const char *table_name)
bool reopen_table(TABLE *table,bool locked)
{
TABLE tmp;
- char *db=table->table_cache_key;
- char *table_name=table->real_name;
- bool error=1;
+ char *db= table->s->table_cache_key;
+ const char *table_name= table->s->table_name;
+ bool error= 1;
Field **field;
uint key,part;
DBUG_ENTER("reopen_table");
@@ -1114,24 +1121,25 @@ bool reopen_table(TABLE *table,bool locked)
#ifdef EXTRA_DEBUG
if (table->db_stat)
sql_print_error("Table %s had a open data handler in reopen_table",
- table->table_name);
+ table->alias);
#endif
if (!locked)
VOID(pthread_mutex_lock(&LOCK_open));
safe_mutex_assert_owner(&LOCK_open);
if (open_unireg_entry(table->in_use, &tmp, db, table_name,
- table->table_name, 0, table->in_use->mem_root))
+ table->alias, 0, table->in_use->mem_root))
goto end;
free_io_cache(table);
- if (!(tmp.table_cache_key= memdup_root(&tmp.mem_root,db,
- table->key_length)))
+ if (!(tmp.s->table_cache_key= memdup_root(&tmp.mem_root,db,
+ table->s->key_length)))
{
delete tmp.triggers;
closefrm(&tmp); // End of memory
goto end;
}
+ tmp.s->db= tmp.s->table_cache_key;
/* This list copies variables set by open_table */
tmp.tablenr= table->tablenr;
@@ -1141,16 +1149,16 @@ bool reopen_table(TABLE *table,bool locked)
tmp.null_row= table->null_row;
tmp.maybe_null= table->maybe_null;
tmp.status= table->status;
- tmp.keys_in_use_for_query= tmp.keys_in_use;
- tmp.used_keys= tmp.keys_for_keyread;
+ tmp.keys_in_use_for_query= tmp.s->keys_in_use;
+ tmp.used_keys= tmp.s->keys_for_keyread;
tmp.force_index= tmp.force_index;
/* Get state */
- tmp.key_length= table->key_length;
+ tmp.s->key_length= table->s->key_length;
tmp.in_use= table->in_use;
tmp.reginfo.lock_type=table->reginfo.lock_type;
- tmp.version= refresh_version;
- tmp.tmp_table= table->tmp_table;
+ tmp.s->version= refresh_version;
+ tmp.s->tmp_table= table->s->tmp_table;
tmp.grant= table->grant;
/* Replace table in open list */
@@ -1161,16 +1169,17 @@ bool reopen_table(TABLE *table,bool locked)
if (table->file)
VOID(closefrm(table)); // close file, free everything
- *table=tmp;
+ *table= tmp;
+ table->s= &table->share_not_to_be_used;
table->file->change_table_ptr(table);
- DBUG_ASSERT(table->table_name);
+ DBUG_ASSERT(table->alias);
for (field=table->field ; *field ; field++)
{
(*field)->table= (*field)->orig_table= table;
- (*field)->table_name=table->table_name;
+ (*field)->table_name= &table->alias;
}
- for (key=0 ; key < table->keys ; key++)
+ for (key=0 ; key < table->s->keys ; key++)
for (part=0 ; part < table->key_info[key].usable_key_parts ; part++)
table->key_info[key].key_part[part].field->table= table;
VOID(pthread_cond_broadcast(&COND_refresh));
@@ -1194,8 +1203,8 @@ bool close_data_tables(THD *thd,const char *db, const char *table_name)
TABLE *table;
for (table=thd->open_tables; table ; table=table->next)
{
- if (!strcmp(table->real_name,table_name) &&
- !strcmp(table->table_cache_key,db))
+ if (!strcmp(table->s->table_name, table_name) &&
+ !strcmp(table->s->db, db))
{
mysql_lock_remove(thd, thd->locked_tables,table);
table->file->close();
@@ -1240,7 +1249,7 @@ bool reopen_tables(THD *thd,bool get_locks,bool in_refresh)
next=table->next;
if (!tables || (!db_stat && reopen_table(table,1)))
{
- my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->table_name);
+ my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->alias);
VOID(hash_delete(&open_cache,(byte*) table));
error=1;
}
@@ -1252,7 +1261,7 @@ bool reopen_tables(THD *thd,bool get_locks,bool in_refresh)
*tables_ptr++= table; // need new lock on this
if (in_refresh)
{
- table->version=0;
+ table->s->version=0;
table->locked_by_flush=0;
}
}
@@ -1291,11 +1300,11 @@ void close_old_data_files(THD *thd, TABLE *table, bool abort_locks,
bool found=send_refresh;
for (; table ; table=table->next)
{
- if (table->version != refresh_version)
+ if (table->s->version != refresh_version)
{
found=1;
if (!abort_locks) // If not from flush tables
- table->version = refresh_version; // Let other threads use table
+ table->s->version= refresh_version; // Let other threads use table
if (table->db_stat)
{
if (abort_locks)
@@ -1325,8 +1334,8 @@ bool table_is_used(TABLE *table, bool wait_for_name_lock)
{
do
{
- char *key= table->table_cache_key;
- uint key_length=table->key_length;
+ char *key= table->s->table_cache_key;
+ uint key_length= table->s->key_length;
for (TABLE *search=(TABLE*) hash_search(&open_cache,
(byte*) key,key_length) ;
search ;
@@ -1334,7 +1343,7 @@ bool table_is_used(TABLE *table, bool wait_for_name_lock)
{
if (search->locked_by_flush ||
search->locked_by_name && wait_for_name_lock ||
- search->db_stat && search->version < refresh_version)
+ search->db_stat && search->s->version < refresh_version)
return 1; // Table is used
}
} while ((table=table->next));
@@ -1381,11 +1390,11 @@ bool drop_locked_tables(THD *thd,const char *db, const char *table_name)
TABLE *table,*next,**prev;
bool found=0;
prev= &thd->open_tables;
- for (table=thd->open_tables; table ; table=next)
+ for (table= thd->open_tables; table ; table=next)
{
next=table->next;
- if (!strcmp(table->real_name,table_name) &&
- !strcmp(table->table_cache_key,db))
+ if (!strcmp(table->s->table_name, table_name) &&
+ !strcmp(table->s->db, db))
{
mysql_lock_remove(thd, thd->locked_tables,table);
VOID(hash_delete(&open_cache,(byte*) table));
@@ -1420,8 +1429,8 @@ void abort_locked_tables(THD *thd,const char *db, const char *table_name)
TABLE *table;
for (table= thd->open_tables; table ; table= table->next)
{
- if (!strcmp(table->real_name,table_name) &&
- !strcmp(table->table_cache_key,db))
+ if (!strcmp(table->s->table_name,table_name) &&
+ !strcmp(table->s->db, db))
{
mysql_lock_abort(thd,table);
break;
@@ -1475,7 +1484,7 @@ static int open_unireg_entry(THD *thd, TABLE *entry, const char *db,
thd->open_options, entry, table_desc, mem_root))))
{
- if (!entry->crashed)
+ if (!entry->s || !entry->s->crashed)
{
/*
Frm file could not be found on disk
@@ -1496,7 +1505,7 @@ static int open_unireg_entry(THD *thd, TABLE *entry, const char *db,
TABLE_LIST table_list;
bzero((char*) &table_list, sizeof(table_list)); // just for safe
table_list.db=(char*) db;
- table_list.real_name=(char*) name;
+ table_list.table_name=(char*) name;
safe_mutex_assert_owner(&LOCK_open);
@@ -1663,9 +1672,9 @@ int open_tables(THD *thd, TABLE_LIST *start, uint *counter)
for (TABLE_LIST *tmp= start; tmp; tmp= tmp->next_global)
{
/* Close normal (not temporary) changed tables */
- if (tmp->table && ! tmp->table->tmp_table)
+ if (tmp->table && ! tmp->table->s->tmp_table)
{
- if (tmp->table->version != refresh_version ||
+ if (tmp->table->s->version != refresh_version ||
! tmp->table->db_stat)
{
VOID(hash_delete(&open_cache,(byte*) tmp->table));
@@ -1724,7 +1733,7 @@ static bool check_lock_and_start_stmt(THD *thd, TABLE *table,
if ((int) lock_type >= (int) TL_WRITE_ALLOW_READ &&
(int) table->reginfo.lock_type < (int) TL_WRITE_ALLOW_READ)
{
- my_error(ER_TABLE_NOT_LOCKED_FOR_WRITE, MYF(0),table->table_name);
+ my_error(ER_TABLE_NOT_LOCKED_FOR_WRITE, MYF(0),table->alias);
DBUG_RETURN(1);
}
if ((error=table->file->start_stmt(thd)))
@@ -1911,7 +1920,7 @@ int lock_tables(THD *thd, TABLE_LIST *tables, uint count)
{
DBUG_ASSERT(thd->lock == 0); // You must lock everything at once
TABLE **start,**ptr;
- if (!(ptr=start=(TABLE**) sql_alloc(sizeof(TABLE*)*count)))
+ if (!(ptr=start=(TABLE**) thd->alloc(sizeof(TABLE*)*count)))
return -1;
for (table= tables; table; table= table->next_global)
{
@@ -1947,6 +1956,7 @@ TABLE *open_temporary_table(THD *thd, const char *path, const char *db,
const char *table_name, bool link_in_list)
{
TABLE *tmp_table;
+ TABLE_SHARE *share;
DBUG_ENTER("open_temporary_table");
/*
@@ -1971,20 +1981,22 @@ TABLE *open_temporary_table(THD *thd, const char *path, const char *db,
DBUG_RETURN(0);
}
+ share= tmp_table->s;
tmp_table->reginfo.lock_type=TL_WRITE; // Simulate locked
- tmp_table->tmp_table = (tmp_table->file->has_transactions() ?
- TRANSACTIONAL_TMP_TABLE : TMP_TABLE);
- tmp_table->table_cache_key=(char*) (tmp_table+1);
- tmp_table->key_length= (uint) (strmov((tmp_table->real_name=
- strmov(tmp_table->table_cache_key,db)
- +1), table_name)
- - tmp_table->table_cache_key)+1;
- int4store(tmp_table->table_cache_key + tmp_table->key_length,
- thd->server_id);
- tmp_table->key_length += 4;
- int4store(tmp_table->table_cache_key + tmp_table->key_length,
+ share->tmp_table= (tmp_table->file->has_transactions() ?
+ TRANSACTIONAL_TMP_TABLE : TMP_TABLE);
+ share->table_cache_key= (char*) (tmp_table+1);
+ share->db= share->table_cache_key;
+ share->key_length= (uint) (strmov(((char*) (share->table_name=
+ strmov(share->table_cache_key,
+ db)+1)),
+ table_name) -
+ share->table_cache_key) +1;
+ int4store(share->table_cache_key + share->key_length, thd->server_id);
+ share->key_length+= 4;
+ int4store(share->table_cache_key + share->key_length,
thd->variables.pseudo_thread_id);
- tmp_table->key_length += 4;
+ share->key_length+= 4;
if (link_in_list)
{
@@ -2151,13 +2163,13 @@ Field *find_field_in_real_table(THD *thd, TABLE *table,
uint cached_field_index= *cached_field_index_ptr;
/* We assume here that table->field < NO_CACHED_FIELD_INDEX = UINT_MAX */
- if (cached_field_index < table->fields &&
+ if (cached_field_index < table->s->fields &&
!my_strcasecmp(system_charset_info,
table->field[cached_field_index]->field_name, name))
field_ptr= table->field + cached_field_index;
- else if (table->name_hash.records)
- field_ptr= (Field**)hash_search(&table->name_hash,(byte*) name,
- length);
+ else if (table->s->name_hash.records)
+ field_ptr= (Field**) hash_search(&table->s->name_hash, (byte*) name,
+ length);
else
{
if (!(field_ptr= table->field))
@@ -2193,8 +2205,8 @@ Field *find_field_in_real_table(THD *thd, TABLE *table,
}
#ifndef NO_EMBEDDED_ACCESS_CHECKS
if (check_grants && check_grant_column(thd, &table->grant,
- table->table_cache_key,
- table->real_name, name, length))
+ table->s->db,
+ table->s->table_name, name, length))
return WRONG_GRANT;
#endif
return field;
@@ -2810,7 +2822,7 @@ bool setup_tables(THD *thd, TABLE_LIST *tables, Item **conds,
tablenr= 0;
}
setup_table_map(table, table_list, tablenr);
- table->used_keys= table->keys_for_keyread;
+ table->used_keys= table->s->keys_for_keyread;
if (table_list->use_index)
{
key_map map;
@@ -2874,12 +2886,13 @@ bool get_key_map_from_key_list(key_map *map, TABLE *table,
map->clear_all();
while ((name=it++))
{
- if (table->keynames.type_names == 0 ||
- (pos= find_type(&table->keynames, name->ptr(), name->length(), 1)) <=
+ if (table->s->keynames.type_names == 0 ||
+ (pos= find_type(&table->s->keynames, name->ptr(),
+ name->length(), 1)) <=
0)
{
my_error(ER_KEY_COLUMN_DOES_NOT_EXITS, MYF(0),
- name->c_ptr(), table->real_name);
+ name->c_ptr(), table->s->table_name);
map->set_all();
return 1;
}
@@ -2970,7 +2983,8 @@ insert_fields(THD *thd, TABLE_LIST *tables, const char *db_name,
DBUG_ASSERT(table != 0);
table_iter.set(tables);
if (check_grant_all_columns(thd, SELECT_ACL, &table->grant,
- table->table_cache_key, table->real_name,
+ table->s->db,
+ table->s->table_name,
&table_iter))
goto err;
}
@@ -3064,7 +3078,7 @@ insert_fields(THD *thd, TABLE_LIST *tables, const char *db_name,
else
{
db= tables->db;
- tab= tables->real_name;
+ tab= tables->table_name;
}
if (!tables->schema_table &&
!(fld->have_privileges= (get_column_grant(thd,
@@ -3115,7 +3129,7 @@ insert_fields(THD *thd, TABLE_LIST *tables, const char *db_name,
fields marked in setup_tables during fix_fields of view columns
*/
if (table)
- table->used_fields=table->fields;
+ table->used_fields= table->s->fields;
}
}
if (found)
@@ -3489,14 +3503,14 @@ void remove_db_from_cache(const my_string db)
for (uint idx=0 ; idx < open_cache.records ; idx++)
{
TABLE *table=(TABLE*) hash_element(&open_cache,idx);
- if (!strcmp(table->table_cache_key,db))
+ if (!strcmp(table->s->db, db))
{
- table->version=0L; /* Free when thread is ready */
+ table->s->version= 0L; /* Free when thread is ready */
if (!table->in_use)
relink_unused(table);
}
}
- while (unused_tables && !unused_tables->version)
+ while (unused_tables && !unused_tables->s->version)
VOID(hash_delete(&open_cache,(byte*) unused_tables));
}
@@ -3541,7 +3555,7 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table_name,
table = (TABLE*) hash_next(&open_cache,(byte*) key,key_length))
{
THD *in_use;
- table->version=0L; /* Free when thread is ready */
+ table->s->version= 0L; /* Free when thread is ready */
if (!(in_use=table->in_use))
{
DBUG_PRINT("info",("Table was not in use"));
@@ -3581,7 +3595,7 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table_name,
else
result= result || return_if_owned_by_thd;
}
- while (unused_tables && !unused_tables->version)
+ while (unused_tables && !unused_tables->s->version)
VOID(hash_delete(&open_cache,(byte*) unused_tables));
DBUG_RETURN(result);
}
diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc
index 26b1eff49e7..f4345f8ce28 100644
--- a/sql/sql_cache.cc
+++ b/sql/sql_cache.cc
@@ -1031,7 +1031,6 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length)
{
TABLE_LIST table_list;
TABLE *tmptable;
-
Query_cache_table *table = block_table->parent;
/*
@@ -1042,8 +1041,9 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length)
*/
for (tmptable= thd->temporary_tables; tmptable ; tmptable= tmptable->next)
{
- if (tmptable->key_length - TMP_TABLE_KEY_EXTRA == table->key_length() &&
- !memcmp(tmptable->table_cache_key, table->data(),
+ if (tmptable->s->key_length - TMP_TABLE_KEY_EXTRA ==
+ table->key_length() &&
+ !memcmp(tmptable->s->table_cache_key, table->data(),
table->key_length()))
{
DBUG_PRINT("qcache",
@@ -1063,7 +1063,7 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length)
bzero((char*) &table_list,sizeof(table_list));
table_list.db = table->db();
- table_list.alias= table_list.real_name= table->table();
+ table_list.alias= table_list.table_name= table->table();
#ifndef NO_EMBEDDED_ACCESS_CHECKS
if (check_table_access(thd,SELECT_ACL,&table_list,1))
{
@@ -2056,7 +2056,7 @@ void Query_cache::invalidate_table(TABLE_LIST *table_list)
uint key_length;
Query_cache_block *table_block;
key_length=(uint) (strmov(strmov(key,table_list->db)+1,
- table_list->real_name) -key)+ 1;
+ table_list->table_name) -key)+ 1;
// We don't store temporary tables => no key_length+=4 ...
if ((table_block = (Query_cache_block*)
@@ -2067,7 +2067,7 @@ void Query_cache::invalidate_table(TABLE_LIST *table_list)
void Query_cache::invalidate_table(TABLE *table)
{
- invalidate_table((byte*) table->table_cache_key, table->key_length);
+ invalidate_table((byte*) table->s->table_cache_key, table->s->key_length);
}
void Query_cache::invalidate_table(byte * key, uint32 key_length)
@@ -2116,18 +2116,18 @@ my_bool Query_cache::register_all_tables(Query_cache_block *block,
{
DBUG_PRINT("qcache",
("table %s, db %s, openinfo at 0x%lx, keylen %u, key at 0x%lx",
- tables_used->real_name, tables_used->db,
+ tables_used->table_name, tables_used->db,
(ulong) tables_used->table,
- tables_used->table->key_length,
- (ulong) tables_used->table->table_cache_key));
- block_table->n=n;
- if (!insert_table(tables_used->table->key_length,
- tables_used->table->table_cache_key, block_table,
+ tables_used->table->s->key_length,
+ (ulong) tables_used->table->s->table_cache_key));
+ block_table->n= n;
+ if (!insert_table(tables_used->table->s->key_length,
+ tables_used->table->s->table_cache_key, block_table,
tables_used->db_length,
tables_used->table->file->table_cache_type()))
break;
- if (tables_used->table->db_type == DB_TYPE_MRG_MYISAM)
+ if (tables_used->table->s->db_type == DB_TYPE_MRG_MYISAM)
{
ha_myisammrg *handler = (ha_myisammrg *) tables_used->table->file;
MYRG_INFO *file = handler->myrg_info();
@@ -2663,15 +2663,15 @@ TABLE_COUNTER_TYPE Query_cache::is_cacheable(THD *thd, uint32 query_len,
{
table_count++;
DBUG_PRINT("qcache", ("table %s, db %s, type %u",
- tables_used->real_name,
- tables_used->db, tables_used->table->db_type));
+ tables_used->table_name,
+ tables_used->db, tables_used->table->s->db_type));
*tables_type|= tables_used->table->file->table_cache_type();
/*
table_alias_charset used here because it depends of
lower_case_table_names variable
*/
- if (tables_used->table->tmp_table != NO_TMP_TABLE ||
+ if (tables_used->table->s->tmp_table != NO_TMP_TABLE ||
(*tables_type & HA_CACHE_TBL_NOCACHE) ||
(tables_used->db_length == 5 &&
my_strnncoll(table_alias_charset, (uchar*)tables_used->db, 6,
@@ -2682,7 +2682,7 @@ TABLE_COUNTER_TYPE Query_cache::is_cacheable(THD *thd, uint32 query_len,
other non-cacheable table(s)"));
DBUG_RETURN(0);
}
- if (tables_used->table->db_type == DB_TYPE_MRG_MYISAM)
+ if (tables_used->table->s->db_type == DB_TYPE_MRG_MYISAM)
{
ha_myisammrg *handler = (ha_myisammrg *)tables_used->table->file;
MYRG_INFO *file = handler->myrg_info();
@@ -2729,8 +2729,8 @@ my_bool Query_cache::ask_handler_allowance(THD *thd,
for (; tables_used; tables_used= tables_used->next_global)
{
TABLE *table= tables_used->table;
- if (!ha_caching_allowed(thd, table->table_cache_key,
- table->key_length,
+ if (!ha_caching_allowed(thd, table->s->table_cache_key,
+ table->s->key_length,
table->file->table_cache_type()))
{
DBUG_PRINT("qcache", ("Handler does not allow caching for %s.%s",
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index d369e85d775..c9545a0141e 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -650,7 +650,7 @@ void THD::add_changed_table(TABLE *table)
DBUG_ASSERT((options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) &&
table->file->has_transactions());
- add_changed_table(table->table_cache_key, table->key_length);
+ add_changed_table(table->s->table_cache_key, table->s->key_length);
DBUG_VOID_RETURN;
}
diff --git a/sql/sql_db.cc b/sql/sql_db.cc
index d3b30de0bcd..26929ebc432 100644
--- a/sql/sql_db.cc
+++ b/sql/sql_db.cc
@@ -812,8 +812,8 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db,
if (!table_list)
goto err;
table_list->db= (char*) (table_list+1);
- strmov(table_list->real_name= strmov(table_list->db,db)+1, file->name);
- table_list->alias= table_list->real_name; // If lower_case_table_names=2
+ strmov(table_list->table_name= strmov(table_list->db,db)+1, file->name);
+ table_list->alias= table_list->table_name; // If lower_case_table_names=2
/* Link into list */
(*tot_list_next)= table_list;
tot_list_next= &table_list->next_local;
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index 8edfc08fa82..15fbfcf928b 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -232,7 +232,7 @@ cleanup:
delete select;
transactional_table= table->file->has_transactions();
- log_delayed= (transactional_table || table->tmp_table);
+ log_delayed= (transactional_table || table->s->tmp_table);
/*
We write to the binary log even if we deleted no row, because maybe the
user is using this command to ensure that a table is clean on master *and
@@ -307,7 +307,7 @@ bool mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds)
}
if (unique_table(table_list, table_list->next_global))
{
- my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->real_name);
+ my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->table_name);
DBUG_RETURN(TRUE);
}
select_lex->fix_prepare_information(thd, conds);
@@ -366,7 +366,7 @@ bool mysql_multi_delete_prepare(THD *thd)
check_key_in_view(thd, target_tbl->correspondent_table))
{
my_error(ER_NON_UPDATABLE_TABLE, MYF(0),
- target_tbl->real_name, "DELETE");
+ target_tbl->table_name, "DELETE");
DBUG_RETURN(TRUE);
}
/*
@@ -381,10 +381,10 @@ bool mysql_multi_delete_prepare(THD *thd)
{
if (un->first_select()->linkage != DERIVED_TABLE_TYPE &&
un->check_updateable(target_tbl->correspondent_table->db,
- target_tbl->correspondent_table->real_name))
+ target_tbl->correspondent_table->table_name))
{
my_error(ER_UPDATE_TABLE_USED, MYF(0),
- target_tbl->correspondent_table->real_name);
+ target_tbl->correspondent_table->table_name);
DBUG_RETURN(TRUE);
}
}
@@ -445,7 +445,7 @@ multi_delete::initialize_tables(JOIN *join)
tbl->used_keys.clear_all();
if (tbl->file->has_transactions())
log_delayed= transactional_tables= 1;
- else if (tbl->tmp_table != NO_TMP_TABLE)
+ else if (tbl->s->tmp_table != NO_TMP_TABLE)
log_delayed= 1;
else
normal_tables= 1;
@@ -717,19 +717,19 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
bzero((char*) &create_info,sizeof(create_info));
/* If it is a temporary table, close and regenerate it */
if (!dont_send_ok && (table_ptr=find_temporary_table(thd,table_list->db,
- table_list->real_name)))
+ table_list->table_name)))
{
TABLE *table= *table_ptr;
table->file->info(HA_STATUS_AUTO | HA_STATUS_NO_LOCK);
- db_type table_type=table->db_type;
- strmov(path,table->path);
+ db_type table_type= table->s->db_type;
+ strmov(path, table->s->path);
*table_ptr= table->next; // Unlink table from list
close_temporary(table,0);
*fn_ext(path)=0; // Remove the .frm extension
ha_create_table(path, &create_info,1);
// We don't need to call invalidate() because this table is not in cache
if ((error= (int) !(open_temporary_table(thd, path, table_list->db,
- table_list->real_name, 1))))
+ table_list->table_name, 1))))
(void) rm_temporary_table(table_type, path);
/*
If we return here we will not have logged the truncation to the bin log
@@ -739,7 +739,7 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
}
(void) sprintf(path,"%s/%s/%s%s",mysql_data_home,table_list->db,
- table_list->real_name,reg_ext);
+ table_list->table_name,reg_ext);
fn_format(path,path,"","",4);
if (!dont_send_ok)
@@ -748,7 +748,7 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
if ((table_type=get_table_type(path)) == DB_TYPE_UNKNOWN)
{
my_error(ER_NO_SUCH_TABLE, MYF(0),
- table_list->db, table_list->real_name);
+ table_list->db, table_list->table_name);
DBUG_RETURN(TRUE);
}
if (!ha_supports_generate(table_type))
diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc
index 520393f8544..bed65f90c00 100644
--- a/sql/sql_derived.cc
+++ b/sql/sql_derived.cc
@@ -147,7 +147,7 @@ exit:
{
thd->clear_error();
my_error(ER_VIEW_INVALID, MYF(0), orig_table_list->db,
- orig_table_list->real_name);
+ orig_table_list->table_name);
}
}
@@ -168,9 +168,9 @@ exit:
delete derived_result;
orig_table_list->derived_result= derived_result;
orig_table_list->table= table;
- orig_table_list->real_name= table->real_name;
+ orig_table_list->table_name= (char*) table->s->table_name;
table->derived_select_number= first_select->select_number;
- table->tmp_table= TMP_TABLE;
+ table->s->tmp_table= TMP_TABLE;
#ifndef NO_EMBEDDED_ACCESS_CHECKS
table->grant.privilege= SELECT_ACL;
#endif
diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc
index 2ee7734e4f3..c9c21d82568 100644
--- a/sql/sql_handler.cc
+++ b/sql/sql_handler.cc
@@ -152,7 +152,7 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen)
int error;
DBUG_ENTER("mysql_ha_open");
DBUG_PRINT("enter",("'%s'.'%s' as '%s' reopen: %d",
- tables->db, tables->real_name, tables->alias,
+ tables->db, tables->table_name, tables->alias,
(int) reopen));
if (! hash_inited(&thd->handler_tables_hash))
@@ -206,7 +206,7 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen)
{
/* copy the TABLE_LIST struct */
dblen= strlen(tables->db) + 1;
- namelen= strlen(tables->real_name) + 1;
+ namelen= strlen(tables->table_name) + 1;
aliaslen= strlen(tables->alias) + 1;
if (!(my_multi_malloc(MYF(MY_WME),
&hash_tables, sizeof(*hash_tables),
@@ -218,10 +218,10 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen)
/* structure copy */
*hash_tables= *tables;
hash_tables->db= db;
- hash_tables->real_name= name;
+ hash_tables->table_name= name;
hash_tables->alias= alias;
memcpy(hash_tables->db, tables->db, dblen);
- memcpy(hash_tables->real_name, tables->real_name, namelen);
+ memcpy(hash_tables->table_name, tables->table_name, namelen);
memcpy(hash_tables->alias, tables->alias, aliaslen);
/* add to hash */
@@ -266,7 +266,7 @@ bool mysql_ha_close(THD *thd, TABLE_LIST *tables)
TABLE **table_ptr;
DBUG_ENTER("mysql_ha_close");
DBUG_PRINT("enter",("'%s'.'%s' as '%s'",
- tables->db, tables->real_name, tables->alias));
+ tables->db, tables->table_name, tables->alias));
if ((hash_tables= (TABLE_LIST*) hash_search(&thd->handler_tables_hash,
(byte*) tables->alias,
@@ -348,7 +348,7 @@ bool mysql_ha_read(THD *thd, TABLE_LIST *tables,
uint key_len;
DBUG_ENTER("mysql_ha_read");
DBUG_PRINT("enter",("'%s'.'%s' as '%s'",
- tables->db, tables->real_name, tables->alias));
+ tables->db, tables->table_name, tables->alias));
LINT_INIT(key);
LINT_INIT(key_len);
@@ -363,7 +363,7 @@ bool mysql_ha_read(THD *thd, TABLE_LIST *tables,
{
table= hash_tables->table;
DBUG_PRINT("info-in-hash",("'%s'.'%s' as '%s' tab %p",
- hash_tables->db, hash_tables->real_name,
+ hash_tables->db, hash_tables->table_name,
hash_tables->alias, table));
if (!table)
{
@@ -378,7 +378,7 @@ bool mysql_ha_read(THD *thd, TABLE_LIST *tables,
table= hash_tables->table;
DBUG_PRINT("info",("re-opened '%s'.'%s' as '%s' tab %p",
- hash_tables->db, hash_tables->real_name,
+ hash_tables->db, hash_tables->table_name,
hash_tables->alias, table));
}
@@ -398,7 +398,7 @@ bool mysql_ha_read(THD *thd, TABLE_LIST *tables,
#if MYSQL_VERSION_ID < 40100
char buff[MAX_DBKEY_LENGTH];
if (*tables->db)
- strxnmov(buff, sizeof(buff), tables->db, ".", tables->real_name, NullS);
+ strxnmov(buff, sizeof(buff), tables->db, ".", tables->table_name, NullS);
else
strncpy(buff, tables->alias, sizeof(buff));
my_error(ER_UNKNOWN_TABLE, MYF(0), buff, "HANDLER");
@@ -417,7 +417,7 @@ bool mysql_ha_read(THD *thd, TABLE_LIST *tables,
if (keyname)
{
- if ((keyno=find_type(keyname, &table->keynames, 1+2)-1)<0)
+ if ((keyno=find_type(keyname, &table->s->keynames, 1+2)-1)<0)
{
my_error(ER_KEY_DOES_NOT_EXITS, MYF(0), keyname, tables->alias);
goto err0;
@@ -527,7 +527,7 @@ bool mysql_ha_read(THD *thd, TABLE_LIST *tables,
if (error != HA_ERR_KEY_NOT_FOUND && error != HA_ERR_END_OF_FILE)
{
sql_print_error("mysql_ha_read: Got error %d when reading table '%s'",
- error, tables->real_name);
+ error, tables->table_name);
table->file->print_error(error,MYF(0));
goto err;
}
@@ -609,22 +609,22 @@ int mysql_ha_flush(THD *thd, TABLE_LIST *tables, uint mode_flags)
for (tmp_tables= tables ; tmp_tables; tmp_tables= tmp_tables->next_local)
{
DBUG_PRINT("info-in-tables-list",("'%s'.'%s' as '%s'",
- tmp_tables->db, tmp_tables->real_name,
+ tmp_tables->db, tmp_tables->table_name,
tmp_tables->alias));
/* Close all currently open handler tables with the same base table. */
table_ptr= &(thd->handler_tables);
while (*table_ptr)
{
- if ((! *tmp_tables->db ||
- ! my_strcasecmp(&my_charset_latin1, (*table_ptr)->table_cache_key,
+ if ((!*tmp_tables->db ||
+ !my_strcasecmp(&my_charset_latin1, (*table_ptr)->s->db,
tmp_tables->db)) &&
- ! my_strcasecmp(&my_charset_latin1, (*table_ptr)->real_name,
- tmp_tables->real_name))
+ ! my_strcasecmp(&my_charset_latin1, (*table_ptr)->s->table_name,
+ tmp_tables->table_name))
{
DBUG_PRINT("info",("*table_ptr '%s'.'%s' as '%s'",
- (*table_ptr)->table_cache_key,
- (*table_ptr)->real_name,
- (*table_ptr)->table_name));
+ (*table_ptr)->s->db,
+ (*table_ptr)->s->table_name,
+ (*table_ptr)->alias));
mysql_ha_flush_table(thd, table_ptr, mode_flags);
continue;
}
@@ -641,7 +641,7 @@ int mysql_ha_flush(THD *thd, TABLE_LIST *tables, uint mode_flags)
while (*table_ptr)
{
if ((mode_flags & MYSQL_HA_FLUSH_ALL) ||
- ((*table_ptr)->version != refresh_version))
+ ((*table_ptr)->s->version != refresh_version))
{
mysql_ha_flush_table(thd, table_ptr, mode_flags);
continue;
@@ -677,12 +677,12 @@ static int mysql_ha_flush_table(THD *thd, TABLE **table_ptr, uint mode_flags)
TABLE *table= *table_ptr;
DBUG_ENTER("mysql_ha_flush_table");
DBUG_PRINT("enter",("'%s'.'%s' as '%s' flags: 0x%02x",
- table->table_cache_key, table->real_name,
- table->table_name, mode_flags));
+ table->s->db, table->s->table_name,
+ table->alias, mode_flags));
if ((hash_tables= (TABLE_LIST*) hash_search(&thd->handler_tables_hash,
- (byte*) (*table_ptr)->table_name,
- strlen((*table_ptr)->table_name) + 1)))
+ (byte*) (*table_ptr)->alias,
+ strlen((*table_ptr)->alias) + 1)))
{
if (! (mode_flags & MYSQL_HA_REOPEN_ON_USAGE))
{
diff --git a/sql/sql_help.cc b/sql/sql_help.cc
index 99273b42f2a..7bf28a439b6 100644
--- a/sql/sql_help.cc
+++ b/sql/sql_help.cc
@@ -272,9 +272,9 @@ int get_topics_for_keyword(THD *thd, TABLE *topics, TABLE *relations,
DBUG_ENTER("get_topics_for_keyword");
if ((iindex_topic= find_type((char*) primary_key_name,
- &topics->keynames, 1+2)-1)<0 ||
+ &topics->s->keynames, 1+2)-1)<0 ||
(iindex_relations= find_type((char*) primary_key_name,
- &relations->keynames, 1+2)-1)<0)
+ &relations->s->keynames, 1+2)-1)<0)
{
my_message(ER_CORRUPT_HELP_DB, ER(ER_CORRUPT_HELP_DB), MYF(0));
DBUG_RETURN(-1);
@@ -620,16 +620,16 @@ bool mysqld_help(THD *thd, const char *mask)
TABLE_LIST *leaves= 0;
TABLE_LIST tables[4];
bzero((gptr)tables,sizeof(tables));
- tables[0].alias= tables[0].real_name= (char*) "help_topic";
+ tables[0].alias= tables[0].table_name= (char*) "help_topic";
tables[0].lock_type= TL_READ;
tables[0].next_global= tables[0].next_local= &tables[1];
- tables[1].alias= tables[1].real_name= (char*) "help_category";
+ tables[1].alias= tables[1].table_name= (char*) "help_category";
tables[1].lock_type= TL_READ;
tables[1].next_global= tables[1].next_local= &tables[2];
- tables[2].alias= tables[2].real_name= (char*) "help_relation";
+ tables[2].alias= tables[2].table_name= (char*) "help_relation";
tables[2].lock_type= TL_READ;
tables[2].next_global= tables[2].next_local= &tables[3];
- tables[3].alias= tables[3].real_name= (char*) "help_keyword";
+ tables[3].alias= tables[3].table_name= (char*) "help_keyword";
tables[3].lock_type= TL_READ;
tables[0].db= tables[1].db= tables[2].db= tables[3].db= (char*) "mysql";
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 45b62ef8d83..444f3dad3c0 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -71,7 +71,7 @@ check_insert_fields(THD *thd, TABLE_LIST *table_list, List<Item> &fields,
table_list->view_db.str, table_list->view_name.str);
return -1;
}
- if (values.elements != table->fields)
+ if (values.elements != table->s->fields)
{
my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), counter);
return -1;
@@ -82,7 +82,7 @@ check_insert_fields(THD *thd, TABLE_LIST *table_list, List<Item> &fields,
Field_iterator_table fields;
fields.set_table(table);
if (check_grant_all_columns(thd, INSERT_ACL, &table->grant,
- table->table_cache_key, table->real_name,
+ table->s->db, table->s->table_name,
&fields))
return -1;
}
@@ -208,10 +208,10 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
{
if (find_locked_table(thd,
table_list->db ? table_list->db : thd->db,
- table_list->real_name))
+ table_list->table_name))
{
my_error(ER_DELAYED_INSERT_TABLE_LOCKED, MYF(0),
- table_list->real_name);
+ table_list->table_name);
DBUG_RETURN(TRUE);
}
}
@@ -321,7 +321,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
{
if (fields.elements || !value_count)
{
- restore_record(table,default_values); // Get empty record
+ restore_record(table,s->default_values); // Get empty record
if (fill_record(thd, fields, *values, 0))
{
if (values_list.elements != 1 && !thd->net.report_error)
@@ -341,9 +341,9 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
else
{
if (thd->used_tables) // Column used in values()
- restore_record(table,default_values); // Get empty record
+ restore_record(table,s->default_values); // Get empty record
else
- table->record[0][0]=table->default_values[0]; // Fix delete marker
+ table->record[0][0]= table->s->default_values[0]; // Fix delete marker
if (fill_record(thd, table->field, *values, 0))
{
if (values_list.elements != 1 && ! thd->net.report_error)
@@ -442,7 +442,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
transactional_table= table->file->has_transactions();
- log_delayed= (transactional_table || table->tmp_table);
+ log_delayed= (transactional_table || table->s->tmp_table);
if ((info.copied || info.deleted || info.updated) &&
(error <= 0 || !transactional_table))
{
@@ -703,7 +703,7 @@ bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, TABLE *table,
if (!select_insert && unique_table(table_list, table_list->next_global))
{
- my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->real_name);
+ my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->table_name);
DBUG_RETURN(TRUE);
}
if (duplic == DUP_UPDATE || duplic == DUP_REPLACE)
@@ -717,7 +717,7 @@ bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, TABLE *table,
static int last_uniq_key(TABLE *table,uint keynr)
{
- while (++keynr < table->keys)
+ while (++keynr < table->s->keys)
if (table->key_info[keynr].flags & HA_NOSAME)
return 0;
return 1;
@@ -759,7 +759,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
*/
if (info->handle_duplicates == DUP_REPLACE &&
table->next_number_field &&
- key_nr == table->next_number_index &&
+ key_nr == table->s->next_number_index &&
table->file->auto_increment_column_changed)
goto err;
if (table->file->table_flags() & HA_DUPP_POS)
@@ -777,7 +777,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
if (!key)
{
- if (!(key=(char*) my_safe_alloca(table->max_unique_length,
+ if (!(key=(char*) my_safe_alloca(table->s->max_unique_length,
MAX_KEY_LENGTH)))
{
error=ENOMEM;
@@ -860,7 +860,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
else
info->copied++;
if (key)
- my_safe_afree(key,table->max_unique_length,MAX_KEY_LENGTH);
+ my_safe_afree(key,table->s->max_unique_length,MAX_KEY_LENGTH);
if (!table->file->has_transactions())
thd->no_trans_update= 1;
DBUG_RETURN(0);
@@ -1019,7 +1019,7 @@ delayed_insert *find_handler(THD *thd, TABLE_LIST *table_list)
while ((tmp=it++))
{
if (!strcmp(tmp->thd.db,table_list->db) &&
- !strcmp(table_list->real_name,tmp->table->real_name))
+ !strcmp(table_list->table_name,tmp->table->s->table_name))
{
tmp->lock();
break;
@@ -1060,7 +1060,7 @@ static TABLE *delayed_get_table(THD *thd,TABLE_LIST *table_list)
thread_count++;
pthread_mutex_unlock(&LOCK_thread_count);
if (!(tmp->thd.db=my_strdup(table_list->db,MYF(MY_WME))) ||
- !(tmp->thd.query=my_strdup(table_list->real_name,MYF(MY_WME))))
+ !(tmp->thd.query=my_strdup(table_list->table_name,MYF(MY_WME))))
{
delete tmp;
thd->fatal_error();
@@ -1070,7 +1070,7 @@ static TABLE *delayed_get_table(THD *thd,TABLE_LIST *table_list)
}
tmp->table_list= *table_list; // Needed to open table
tmp->table_list.db= tmp->thd.db;
- tmp->table_list.alias= tmp->table_list.real_name=tmp->thd.query;
+ tmp->table_list.alias= tmp->table_list.table_name= tmp->thd.query;
tmp->lock();
pthread_mutex_lock(&tmp->mutex);
if ((error=pthread_create(&tmp->thd.real_id,&connection_attrib,
@@ -1168,17 +1168,19 @@ TABLE *delayed_insert::get_local_table(THD* client_thd)
client_thd->proc_info="allocating local table";
copy= (TABLE*) client_thd->alloc(sizeof(*copy)+
- (table->fields+1)*sizeof(Field**)+
- table->reclength);
+ (table->s->fields+1)*sizeof(Field**)+
+ table->s->reclength);
if (!copy)
goto error;
*copy= *table;
- bzero((char*) &copy->name_hash,sizeof(copy->name_hash)); // No name hashing
+ copy->s= &copy->share_not_to_be_used;
+ // No name hashing
+ bzero((char*) &copy->s->name_hash,sizeof(copy->s->name_hash));
/* We don't need to change the file handler here */
field=copy->field=(Field**) (copy+1);
- copy->record[0]=(byte*) (field+table->fields+1);
- memcpy((char*) copy->record[0],(char*) table->record[0],table->reclength);
+ copy->record[0]=(byte*) (field+table->s->fields+1);
+ memcpy((char*) copy->record[0],(char*) table->record[0],table->s->reclength);
/* Make a copy of all fields */
@@ -1201,7 +1203,7 @@ TABLE *delayed_insert::get_local_table(THD* client_thd)
{
/* Restore offset as this may have been reset in handle_inserts */
copy->timestamp_field=
- (Field_timestamp*) copy->field[table->timestamp_field_offset];
+ (Field_timestamp*) copy->field[table->s->timestamp_field_offset];
copy->timestamp_field->unireg_check= table->timestamp_field->unireg_check;
copy->timestamp_field_type= copy->timestamp_field->get_auto_set_type();
}
@@ -1243,13 +1245,13 @@ static int write_delayed(THD *thd,TABLE *table,enum_duplicates duplic, bool igno
if (!query)
query_length=0;
- if (!(row->record= (char*) my_malloc(table->reclength+query_length+1,
+ if (!(row->record= (char*) my_malloc(table->s->reclength+query_length+1,
MYF(MY_WME))))
goto err;
- memcpy(row->record,table->record[0],table->reclength);
+ memcpy(row->record, table->record[0], table->s->reclength);
if (query_length)
{
- row->query=row->record+table->reclength;
+ row->query= row->record+table->s->reclength;
memcpy(row->query,query,query_length+1);
}
row->query_length= query_length;
@@ -1263,7 +1265,7 @@ static int write_delayed(THD *thd,TABLE *table,enum_duplicates duplic, bool igno
di->rows.push_back(row);
di->stacked_inserts++;
di->status=1;
- if (table->blob_fields)
+ if (table->s->blob_fields)
unlink_blobs(table);
pthread_cond_signal(&di->cond);
@@ -1380,7 +1382,7 @@ extern "C" pthread_handler_decl(handle_delayed_insert,arg)
if (!(di->table->file->table_flags() & HA_CAN_INSERT_DELAYED))
{
thd->fatal_error();
- my_error(ER_ILLEGAL_HA, MYF(0), di->table_list.real_name);
+ my_error(ER_ILLEGAL_HA, MYF(0), di->table_list.table_name);
goto end;
}
di->table->copy_blobs=1;
@@ -1568,13 +1570,13 @@ bool delayed_insert::handle_inserts(void)
if (thr_upgrade_write_delay_lock(*thd.lock->locks))
{
/* This can only happen if thread is killed by shutdown */
- sql_print_error(ER(ER_DELAYED_CANT_CHANGE_LOCK),table->real_name);
+ sql_print_error(ER(ER_DELAYED_CANT_CHANGE_LOCK),table->s->table_name);
goto err;
}
thd.proc_info="insert";
max_rows=delayed_insert_limit;
- if (thd.killed || table->version != refresh_version)
+ if (thd.killed || table->s->version != refresh_version)
{
thd.killed= THD::KILL_CONNECTION;
max_rows= ~0; // Do as much as possible
@@ -1592,7 +1594,7 @@ bool delayed_insert::handle_inserts(void)
{
stacked_inserts--;
pthread_mutex_unlock(&mutex);
- memcpy(table->record[0],row->record,table->reclength);
+ memcpy(table->record[0],row->record,table->s->reclength);
thd.start_time=row->start_time;
thd.query_start_used=row->query_start_used;
@@ -1626,7 +1628,7 @@ bool delayed_insert::handle_inserts(void)
Query_log_event qinfo(&thd, row->query, row->query_length, 0, FALSE);
mysql_bin_log.write(&qinfo);
}
- if (table->blob_fields)
+ if (table->s->blob_fields)
free_delayed_insert_blobs(table);
thread_safe_sub(delayed_rows_in_use,1,&LOCK_delayed_status);
thread_safe_increment(delayed_insert_writes,&LOCK_delayed_status);
@@ -1661,7 +1663,7 @@ bool delayed_insert::handle_inserts(void)
if (thr_reschedule_write_lock(*thd.lock->locks))
{
/* This should never happen */
- sql_print_error(ER(ER_DELAYED_CANT_CHANGE_LOCK),table->real_name);
+ sql_print_error(ER(ER_DELAYED_CANT_CHANGE_LOCK),table->s->table_name);
}
if (!using_bin_log)
table->file->extra(HA_EXTRA_WRITE_CACHE);
@@ -1803,7 +1805,7 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
thd->lex->current_select->join->select_options|= OPTION_BUFFER_RESULT;
}
- restore_record(table,default_values); // Get empty record
+ restore_record(table,s->default_values); // Get empty record
table->next_number_field=table->found_next_number_field;
thd->cuted_fields=0;
if (info.ignore || info.handle_duplicates == DUP_REPLACE)
@@ -1914,7 +1916,7 @@ void select_insert::send_error(uint errcode,const char *err)
table->file->has_transactions(), FALSE);
mysql_bin_log.write(&qinfo);
}
- if (!table->tmp_table)
+ if (!table->s->tmp_table)
thd->options|=OPTION_STATUS_NO_TRANS_UPDATE;
}
if (info.copied || info.deleted || info.updated)
@@ -1942,7 +1944,7 @@ bool select_insert::send_eof()
if (info.copied || info.deleted || info.updated)
{
query_cache_invalidate3(thd, table, 1);
- if (!(table->file->has_transactions() || table->tmp_table))
+ if (!(table->file->has_transactions() || table->s->tmp_table))
thd->options|=OPTION_STATUS_NO_TRANS_UPDATE;
}
@@ -1992,21 +1994,21 @@ select_create::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
if (!table)
DBUG_RETURN(-1); // abort() deletes table
- if (table->fields < values.elements)
+ if (table->s->fields < values.elements)
{
my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), 1);
DBUG_RETURN(-1);
}
/* First field to copy */
- field=table->field+table->fields - values.elements;
+ field=table->field+table->s->fields - values.elements;
/* Don't set timestamp if used */
table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
table->next_number_field=table->found_next_number_field;
- restore_record(table,default_values); // Get empty record
+ restore_record(table,s->default_values); // Get empty record
thd->cuted_fields=0;
if (info.ignore || info.handle_duplicates == DUP_REPLACE)
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
@@ -2053,9 +2055,9 @@ bool select_create::send_eof()
Check if we can remove the following two rows.
We should be able to just keep the table in the table cache.
*/
- if (!table->tmp_table)
+ if (!table->s->tmp_table)
{
- ulong version= table->version;
+ ulong version= table->s->version;
hash_delete(&open_cache,(byte*) table);
/* Tell threads waiting for refresh that something has happened */
if (version != refresh_version)
@@ -2079,19 +2081,19 @@ void select_create::abort()
if (table)
{
table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
- enum db_type table_type=table->db_type;
- if (!table->tmp_table)
+ enum db_type table_type=table->s->db_type;
+ if (!table->s->tmp_table)
{
- ulong version= table->version;
+ ulong version= table->s->version;
hash_delete(&open_cache,(byte*) table);
if (!create_info->table_existed)
- quick_rm_table(table_type, create_table->db, create_table->real_name);
+ quick_rm_table(table_type, create_table->db, create_table->table_name);
/* Tell threads waiting for refresh that something has happened */
if (version != refresh_version)
VOID(pthread_cond_broadcast(&COND_refresh));
}
else if (!create_info->table_existed)
- close_temporary_table(thd, create_table->db, create_table->real_name);
+ close_temporary_table(thd, create_table->db, create_table->table_name);
table=0;
}
VOID(pthread_mutex_unlock(&LOCK_open));
diff --git a/sql/sql_load.cc b/sql/sql_load.cc
index 6c29a0184fa..7858632fff2 100644
--- a/sql/sql_load.cc
+++ b/sql/sql_load.cc
@@ -133,7 +133,7 @@ bool mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
}
table= table_list->table;
transactional_table= table->file->has_transactions();
- log_delayed= (transactional_table || table->tmp_table);
+ log_delayed= (transactional_table || table->s->tmp_table);
if (!fields.elements)
{
@@ -257,7 +257,7 @@ bool mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
lf_info.thd = thd;
lf_info.ex = ex;
lf_info.db = db;
- lf_info.table_name = table_list->real_name;
+ lf_info.table_name = table_list->table_name;
lf_info.fields = &fields;
lf_info.ignore= ignore;
lf_info.handle_dup = handle_duplicates;
@@ -268,7 +268,7 @@ bool mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
}
#endif /*!EMBEDDED_LIBRARY*/
- restore_record(table,default_values);
+ restore_record(table, s->default_values);
thd->count_cuted_fields= CHECK_FIELD_WARN; /* calc cuted fields */
thd->cuted_fields=0L;
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 442d398889f..f74b3b587a9 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -1228,7 +1228,7 @@ int mysql_table_dump(THD* thd, char* db, char* tbl_name, int fd)
if (!(table_list = (TABLE_LIST*) thd->calloc(sizeof(TABLE_LIST))))
DBUG_RETURN(1); // out of memory
table_list->db= db;
- table_list->real_name= table_list->alias= tbl_name;
+ table_list->table_name= table_list->alias= tbl_name;
table_list->lock_type= TL_READ_NO_INSERT;
table_list->prev_global= &table_list; // can be removed after merge with 4.1
@@ -1239,7 +1239,7 @@ int mysql_table_dump(THD* thd, char* db, char* tbl_name, int fd)
}
if (lower_case_table_names)
my_casedn_str(files_charset_info, tbl_name);
- remove_escape(table_list->real_name);
+ remove_escape(table_list->table_name);
if (!(table=open_ltable(thd, table_list, TL_READ_NO_INSERT)))
DBUG_RETURN(1);
@@ -1601,7 +1601,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
pend= strend(packet);
thd->convert_string(&conv_name, system_charset_info,
packet, (uint) (pend-packet), thd->charset());
- table_list.alias= table_list.real_name= conv_name.str;
+ table_list.alias= table_list.table_name= conv_name.str;
packet= pend+1;
if (!my_strcasecmp(system_charset_info, table_list.db,
@@ -1615,10 +1615,10 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
/* command not cachable => no gap for data base name */
if (!(thd->query=fields=thd->memdup(packet,thd->query_length+1)))
break;
- mysql_log.write(thd,command,"%s %s",table_list.real_name,fields);
+ mysql_log.write(thd,command,"%s %s",table_list.table_name, fields);
if (lower_case_table_names)
- my_casedn_str(files_charset_info, table_list.real_name);
- remove_escape(table_list.real_name); // This can't have wildcards
+ my_casedn_str(files_charset_info, table_list.table_name);
+ remove_escape(table_list.table_name); // This can't have wildcards
if (check_access(thd,SELECT_ACL,table_list.db,&table_list.grant.privilege,
0, 0))
@@ -1975,7 +1975,7 @@ int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident,
TABLE_LIST *table_list= (TABLE_LIST*) sel->table_list.first;
char *db= table_list->db;
remove_escape(db); // Fix escaped '_'
- remove_escape(table_list->real_name);
+ remove_escape(table_list->table_name);
if (check_access(thd,SELECT_ACL | EXTRA_ACL,db,
&table_list->grant.privilege, 0, 0))
DBUG_RETURN(1); /* purecov: inspected */
@@ -2534,9 +2534,9 @@ mysql_execute_command(THD *thd)
if (check_grant(thd, CREATE_ACL, all_tables, 0, 1, 0))
goto error;
}
- if (strlen(first_table->real_name) > NAME_LEN)
+ if (strlen(first_table->table_name) > NAME_LEN)
{
- my_error(ER_WRONG_TABLE_NAME, MYF(0), first_table->real_name);
+ my_error(ER_WRONG_TABLE_NAME, MYF(0), first_table->table_name);
break;
}
pthread_mutex_lock(&LOCK_active_mi);
@@ -2544,7 +2544,7 @@ mysql_execute_command(THD *thd)
fetch_master_table will send the error to the client on failure.
Give error if the table already exists.
*/
- if (!fetch_master_table(thd, first_table->db, first_table->real_name,
+ if (!fetch_master_table(thd, first_table->db, first_table->table_name,
active_mi, 0, 0))
{
send_ok(thd);
@@ -2570,9 +2570,9 @@ mysql_execute_command(THD *thd)
#else
/* Fix names if symlinked tables */
if (append_file_to_dir(thd, &lex->create_info.data_file_name,
- create_table->real_name) ||
+ create_table->table_name) ||
append_file_to_dir(thd, &lex->create_info.index_file_name,
- create_table->real_name))
+ create_table->table_name))
goto create_error;
#endif
/*
@@ -2604,7 +2604,7 @@ mysql_execute_command(THD *thd)
if (!(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) &&
unique_table(create_table, select_tables))
{
- my_error(ER_UPDATE_TABLE_USED, MYF(0), create_table->real_name);
+ my_error(ER_UPDATE_TABLE_USED, MYF(0), create_table->table_name);
goto create_error;
}
/* If we create merge table, we have to test tables in merge, too */
@@ -2617,7 +2617,7 @@ mysql_execute_command(THD *thd)
{
if (unique_table(tab, select_tables))
{
- my_error(ER_UPDATE_TABLE_USED, MYF(0), tab->real_name);
+ my_error(ER_UPDATE_TABLE_USED, MYF(0), tab->table_name);
goto create_error;
}
}
@@ -2654,7 +2654,7 @@ mysql_execute_command(THD *thd)
else
{
res= mysql_create_table(thd, create_table->db,
- create_table->real_name, &lex->create_info,
+ create_table->table_name, &lex->create_info,
lex->create_list,
lex->key_list, 0, 0);
}
@@ -2747,7 +2747,7 @@ create_error:
{ // Rename of table
TABLE_LIST tmp_table;
bzero((char*) &tmp_table,sizeof(tmp_table));
- tmp_table.real_name=lex->name;
+ tmp_table.table_name=lex->name;
tmp_table.db=select_lex->db;
tmp_table.grant.privilege=priv;
if (check_grant(thd, INSERT_ACL | CREATE_ACL, &tmp_table, 0,
@@ -4331,7 +4331,7 @@ check_table_access(THD *thd, ulong want_access,TABLE_LIST *tables,
for (; tables; tables= tables->next_global)
{
if (tables->derived || tables->schema_table ||
- (tables->table && (int)tables->table->tmp_table) ||
+ (tables->table && (int)tables->table->s->tmp_table) ||
my_tz_check_n_skip_implicit_tables(&tables,
thd->lex->time_zone_tables_used))
continue;
@@ -4370,7 +4370,7 @@ check_procedure_access(THD *thd, ulong want_access,char *db, char *name,
bzero((char *)tables, sizeof(TABLE_LIST));
tables->db= db;
- tables->real_name= tables->alias= name;
+ tables->table_name= tables->alias= name;
if ((thd->master_access & want_access) == want_access && !thd->db)
tables->grant.privilege= want_access;
@@ -5319,8 +5319,8 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd,
ptr->alias= alias_str;
if (lower_case_table_names && table->table.length)
my_casedn_str(files_charset_info, table->table.str);
- ptr->real_name=table->table.str;
- ptr->real_name_length=table->table.length;
+ ptr->table_name=table->table.str;
+ ptr->table_name_length=table->table.length;
ptr->lock_type= lock_type;
ptr->updating= test(table_options & TL_OPTION_UPDATING);
ptr->force_index= test(table_options & TL_OPTION_FORCE_INDEX);
@@ -5329,13 +5329,13 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd,
if (!my_strcasecmp(system_charset_info, ptr->db,
information_schema_name.str))
{
- ST_SCHEMA_TABLE *schema_table= find_schema_table(thd, ptr->real_name);
+ ST_SCHEMA_TABLE *schema_table= find_schema_table(thd, ptr->table_name);
if (!schema_table ||
(schema_table->hidden &&
lex->orig_sql_command == SQLCOM_END)) // not a 'show' command
{
my_error(ER_UNKNOWN_TABLE, MYF(0),
- ptr->real_name, information_schema_name.str);
+ ptr->table_name, information_schema_name.str);
DBUG_RETURN(0);
}
ptr->schema_table= schema_table;
@@ -6039,7 +6039,7 @@ bool mysql_create_index(THD *thd, TABLE_LIST *table_list, List<Key> &keys)
bzero((char*) &create_info,sizeof(create_info));
create_info.db_type=DB_TYPE_DEFAULT;
create_info.default_table_charset= thd->variables.collation_database;
- DBUG_RETURN(mysql_alter_table(thd,table_list->db,table_list->real_name,
+ DBUG_RETURN(mysql_alter_table(thd,table_list->db,table_list->table_name,
&create_info, table_list,
fields, keys, 0, (ORDER*)0,
DUP_ERROR, 0, &alter_info));
@@ -6057,7 +6057,7 @@ bool mysql_drop_index(THD *thd, TABLE_LIST *table_list, ALTER_INFO *alter_info)
create_info.default_table_charset= thd->variables.collation_database;
alter_info->clear();
alter_info->flags= ALTER_DROP_INDEX;
- DBUG_RETURN(mysql_alter_table(thd,table_list->db,table_list->real_name,
+ DBUG_RETURN(mysql_alter_table(thd,table_list->db,table_list->table_name,
&create_info, table_list,
fields, keys, 0, (ORDER*)0,
DUP_ERROR, 0, alter_info));
@@ -6193,7 +6193,7 @@ bool multi_delete_precheck(THD *thd, TABLE_LIST *tables, uint *table_count)
if (!walk)
{
my_error(ER_UNKNOWN_TABLE, MYF(0),
- target_tbl->real_name, "MULTI DELETE");
+ target_tbl->table_name, "MULTI DELETE");
DBUG_RETURN(TRUE);
}
walk->lock_type= target_tbl->lock_type;
@@ -6343,7 +6343,7 @@ bool create_table_precheck(THD *thd, TABLE_LIST *tables,
*/
if (!(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) &&
find_table_in_global_list(tables, create_table->db,
- create_table->real_name))
+ create_table->table_name))
{
error= FALSE;
goto err;
diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc
index 1640fc1a634..8bc1891ef1b 100644
--- a/sql/sql_rename.cc
+++ b/sql/sql_rename.cc
@@ -149,8 +149,8 @@ rename_tables(THD *thd, TABLE_LIST *table_list, bool skip_error)
}
else
{
- old_alias= ren_table->real_name;
- new_alias= new_table->real_name;
+ old_alias= ren_table->table_name;
+ new_alias= new_table->table_name;
}
sprintf(name,"%s/%s/%s%s",mysql_data_home,
new_table->db, new_alias, reg_ext);
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index dce7c754f03..a44628d66a9 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -2152,7 +2152,7 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables, COND *conds,
table->quick_keys.clear_all();
table->reginfo.join_tab=s;
table->reginfo.not_exists_optimize=0;
- bzero((char*) table->const_key_parts, sizeof(key_part_map)*table->keys);
+ bzero((char*) table->const_key_parts, sizeof(key_part_map)*table->s->keys);
all_table_map|= table->map;
s->join=join;
s->info=0; // For describe
@@ -2189,7 +2189,7 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables, COND *conds,
continue;
}
- if ((table->system || table->file->records <= 1) && ! s->dependent &&
+ if ((table->s->system || table->file->records <= 1) && ! s->dependent &&
!(table->file->table_flags() & HA_NOT_EXACT_COUNT) &&
!table->fulltext_searched)
{
@@ -2915,7 +2915,7 @@ add_key_part(DYNAMIC_ARRAY *keyuse_array,KEY_FIELD *key_field)
if (key_field->eq_func && !(key_field->optimize & KEY_OPTIMIZE_EXISTS))
{
- for (uint key=0 ; key < form->keys ; key++)
+ for (uint key=0 ; key < form->s->keys ; key++)
{
if (!(form->keys_in_use_for_query.is_set(key)))
continue;
@@ -3427,8 +3427,8 @@ best_access_path(JOIN *join,
records=
((double) s->records / (double) rec *
(1.0 +
- ((double) (table->max_key_length-keyinfo->key_length) /
- (double) table->max_key_length)));
+ ((double) (table->s->max_key_length-keyinfo->key_length) /
+ (double) table->s->max_key_length)));
if (records < 2.0)
records=2.0; /* Can't be as good as a unique */
}
@@ -4412,8 +4412,8 @@ find_best(JOIN *join,table_map rest_tables,uint idx,double record_count,
records=
((double) s->records / (double) rec *
(1.0 +
- ((double) (table->max_key_length-keyinfo->key_length) /
- (double) table->max_key_length)));
+ ((double) (table->s->max_key_length-keyinfo->key_length) /
+ (double) table->s->max_key_length)));
if (records < 2.0)
records=2.0; // Can't be as good as a unique
}
@@ -4689,13 +4689,13 @@ static void calc_used_field_length(THD *thd, JOIN_TAB *join_tab)
}
}
if (null_fields)
- rec_length+=(join_tab->table->null_fields+7)/8;
+ rec_length+=(join_tab->table->s->null_fields+7)/8;
if (join_tab->table->maybe_null)
rec_length+=sizeof(my_bool);
if (blobs)
{
uint blob_length=(uint) (join_tab->table->file->mean_rec_length-
- (join_tab->table->reclength- rec_length));
+ (join_tab->table->s->reclength- rec_length));
rec_length+=(uint) max(4,blob_length);
}
join_tab->used_fields=fields;
@@ -5281,7 +5281,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
}
if (tmp || !cond)
{
- DBUG_EXECUTE("where",print_where(tmp,tab->table->table_name););
+ DBUG_EXECUTE("where",print_where(tmp,tab->table->alias););
SQL_SELECT *sel=tab->select=(SQL_SELECT*)
join->thd->memdup((gptr) select, sizeof(SQL_SELECT));
if (!sel)
@@ -7586,7 +7586,7 @@ static Field* create_tmp_field_from_field(THD *thd, Field* org_field,
new_field->flags&= ~NOT_NULL_FLAG; // Because of outer join
if (org_field->type() == MYSQL_TYPE_VAR_STRING ||
org_field->type() == MYSQL_TYPE_VARCHAR)
- table->db_create_options|= HA_OPTION_PACK_RECORD;
+ table->s->db_create_options|= HA_OPTION_PACK_RECORD;
}
return new_field;
}
@@ -7802,7 +7802,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
char *tmpname,path[FN_REFLEN], filename[FN_REFLEN];
byte *pos,*group_buff;
uchar *null_flags;
- Field **reg_field, **from_field, **blob_field;
+ Field **reg_field, **from_field;
+ uint *blob_field;
Copy_field *copy=0;
KEY *keyinfo;
KEY_PART_INFO *key_part_info;
@@ -7851,7 +7852,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
if (!my_multi_malloc(MYF(MY_WME),
&table,sizeof(*table),
&reg_field, sizeof(Field*)*(field_count+1),
- &blob_field, sizeof(Field*)*(field_count+1),
+ &blob_field, sizeof(uint)*(field_count+1),
&from_field, sizeof(Field*)*field_count,
&copy_func,sizeof(*copy_func)*(param->func_count+1),
&param->keyinfo,sizeof(*param->keyinfo),
@@ -7881,26 +7882,31 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
bzero((char*) reg_field,sizeof(Field*)*(field_count+1));
bzero((char*) from_field,sizeof(Field*)*field_count);
table->field=reg_field;
- table->blob_field= (Field_blob**) blob_field;
- table->real_name=table->path=tmpname;
- table->table_name= table_alias;
+ table->alias= table_alias;
table->reginfo.lock_type=TL_WRITE; /* Will be updated */
table->db_stat=HA_OPEN_KEYFILE+HA_OPEN_RNDFILE;
- table->blob_ptr_size=mi_portable_sizeof_char_ptr;
table->map=1;
- table->tmp_table= TMP_TABLE;
- table->db_low_byte_first=1; // True for HEAP and MyISAM
table->temp_pool_slot = temp_pool_slot;
table->copy_blobs= 1;
table->in_use= thd;
- table->table_charset= param->table_charset;
- table->keys_for_keyread.init();
- table->keys_in_use.init();
- table->read_only_keys.init();
table->quick_keys.init();
table->used_keys.init();
table->keys_in_use_for_query.init();
+ table->s= &table->share_not_to_be_used;
+ table->s->blob_field= blob_field;
+ table->s->table_name= table->s->path= tmpname;
+ table->s->db= "";
+ table->s->blob_ptr_size= mi_portable_sizeof_char_ptr;
+ table->s->tmp_table= TMP_TABLE;
+ table->s->db_low_byte_first=1; // True for HEAP and MyISAM
+ table->s->table_charset= param->table_charset;
+ table->s->keys_for_keyread.init();
+ table->s->keys_in_use.init();
+ /* For easier error reporting */
+ table->s->table_cache_key= (char*) table->s->db= "";
+
+
/* Calculate which type of fields we will store in the temporary table */
reclength= string_total_length= 0;
@@ -7944,13 +7950,13 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
if (!new_field)
goto err; // Should be OOM
tmp_from_field++;
- *(reg_field++)= new_field;
reclength+=new_field->pack_length();
if (new_field->flags & BLOB_FLAG)
{
- *blob_field++= new_field;
+ *blob_field++= (uint) (reg_field - table->field);
blob_count++;
}
+ *(reg_field++)= new_field;
if (new_field->real_type() == MYSQL_TYPE_STRING ||
new_field->real_type() == MYSQL_TYPE_VARCHAR)
{
@@ -8002,7 +8008,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
total_uneven_bit_length+= new_field->field_length & 7;
if (new_field->flags & BLOB_FLAG)
{
- *blob_field++= new_field;
+ *blob_field++= (uint) (reg_field - table->field);
blob_count++;
}
if (item->marker == 4 && item->maybe_null)
@@ -8024,7 +8030,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
(select_options & (OPTION_BIG_TABLES | SELECT_SMALL_RESULT)) ==
OPTION_BIG_TABLES)
{
- table->file=get_new_handler(table,table->db_type=DB_TYPE_MYISAM);
+ table->file=get_new_handler(table,table->s->db_type= DB_TYPE_MYISAM);
if (group &&
(param->group_parts > table->file->max_key_parts() ||
param->group_length > table->file->max_key_length()))
@@ -8032,13 +8038,13 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
}
else
{
- table->file=get_new_handler(table,table->db_type=DB_TYPE_HEAP);
+ table->file=get_new_handler(table,table->s->db_type= DB_TYPE_HEAP);
}
if (!using_unique_constraint)
reclength+= group_null_items; // null flag is stored separately
- table->blob_fields=blob_count;
+ table->s->blob_fields= blob_count;
if (blob_count == 0)
{
/* We need to ensure that first byte is not 0 for the delete link */
@@ -8060,15 +8066,15 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
string_total_length / string_count >= AVG_STRING_LENGTH_TO_PACK_ROWS))
use_packed_rows= 1;
- table->fields=field_count;
- table->reclength=reclength;
+ table->s->fields= field_count;
+ table->s->reclength= reclength;
{
uint alloc_length=ALIGN_SIZE(reclength+MI_UNIQUE_HASH_LENGTH+1);
- table->rec_buff_length=alloc_length;
+ table->s->rec_buff_length= alloc_length;
if (!(table->record[0]= (byte *) my_malloc(alloc_length*3, MYF(MY_WME))))
goto err;
table->record[1]= table->record[0]+alloc_length;
- table->default_values= table->record[1]+alloc_length;
+ table->s->default_values= table->record[1]+alloc_length;
}
copy_func[0]=0; // End marker
@@ -8084,8 +8090,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
bfill(null_flags,null_pack_length,255); // Set null fields
table->null_flags= (uchar*) table->record[0];
- table->null_fields= null_count+ hidden_null_count;
- table->null_bytes= null_pack_length;
+ table->s->null_fields= null_count+ hidden_null_count;
+ table->s->null_bytes= null_pack_length;
}
null_count= (blob_count == 0) ? 1 : 0;
hidden_field_count=param->hidden_field_count;
@@ -8143,30 +8149,30 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
null_count=(null_count+7) & ~7; // move to next byte
// fix table name in field entry
- field->table_name= table->table_name;
+ field->table_name= &table->alias;
}
param->copy_field_end=copy;
param->recinfo=recinfo;
- store_record(table,default_values); // Make empty default record
+ store_record(table,s->default_values); // Make empty default record
if (thd->variables.tmp_table_size == ~(ulong) 0) // No limit
- table->max_rows= ~(ha_rows) 0;
+ table->s->max_rows= ~(ha_rows) 0;
else
- table->max_rows=(((table->db_type == DB_TYPE_HEAP) ?
- min(thd->variables.tmp_table_size,
- thd->variables.max_heap_table_size) :
- thd->variables.tmp_table_size)/ table->reclength);
- set_if_bigger(table->max_rows,1); // For dummy start options
- keyinfo=param->keyinfo;
+ table->s->max_rows= (((table->s->db_type == DB_TYPE_HEAP) ?
+ min(thd->variables.tmp_table_size,
+ thd->variables.max_heap_table_size) :
+ thd->variables.tmp_table_size)/ table->s->reclength);
+ set_if_bigger(table->s->max_rows,1); // For dummy start options
+ keyinfo= param->keyinfo;
if (group)
{
DBUG_PRINT("info",("Creating group key in temporary table"));
table->group=group; /* Table is grouped by key */
param->group_buff=group_buff;
- table->keys=1;
- table->uniques= test(using_unique_constraint);
+ table->s->keys=1;
+ table->s->uniques= test(using_unique_constraint);
table->key_info=keyinfo;
keyinfo->key_part=key_part_info;
keyinfo->flags=HA_NOSAME;
@@ -8234,14 +8240,14 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
null_pack_length-=hidden_null_pack_length;
keyinfo->key_parts= ((field_count-param->hidden_field_count)+
test(null_pack_length));
- set_if_smaller(table->max_rows, rows_limit);
+ set_if_smaller(table->s->max_rows, rows_limit);
param->end_write_records= rows_limit;
- table->distinct=1;
- table->keys=1;
+ table->distinct= 1;
+ table->s->keys= 1;
if (blob_count)
{
using_unique_constraint=1;
- table->uniques=1;
+ table->s->uniques= 1;
}
if (!(key_part_info= (KEY_PART_INFO*)
sql_calloc((keyinfo->key_parts)*sizeof(KEY_PART_INFO))))
@@ -8286,23 +8292,16 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
}
if (thd->is_fatal_error) // If end of memory
goto err; /* purecov: inspected */
- table->db_record_offset=1;
- if (table->db_type == DB_TYPE_MYISAM)
+ table->s->db_record_offset= 1;
+ if (table->s->db_type == DB_TYPE_MYISAM)
{
if (create_myisam_tmp_table(table,param,select_options))
goto err;
}
- /* Set table_name for easier debugging */
- table->table_name= base_name(tmpname);
if (!open_tmp_table(table))
DBUG_RETURN(table);
err:
- /*
- Hack to ensure that free_blobs() doesn't fail if blob_field is not yet
- complete
- */
- *table->blob_field= 0;
free_tmp_table(thd,table); /* purecov: inspected */
bitmap_clear_bit(&temp_pool, temp_pool_slot);
DBUG_RETURN(NULL); /* purecov: inspected */
@@ -8312,7 +8311,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
static bool open_tmp_table(TABLE *table)
{
int error;
- if ((error=table->file->ha_open(table->real_name,O_RDWR,HA_OPEN_TMP_TABLE)))
+ if ((error=table->file->ha_open(table->s->table_name,O_RDWR,
+ HA_OPEN_TMP_TABLE)))
{
table->file->print_error(error,MYF(0)); /* purecov: inspected */
table->db_stat=0;
@@ -8332,7 +8332,7 @@ static bool create_myisam_tmp_table(TABLE *table,TMP_TABLE_PARAM *param,
KEY *keyinfo=param->keyinfo;
DBUG_ENTER("create_myisam_tmp_table");
- if (table->keys)
+ if (table->s->keys)
{ // Get keys for ni_create
bool using_unique_constraint=0;
HA_KEYSEG *seg= (HA_KEYSEG*) sql_calloc(sizeof(*seg) *
@@ -8342,11 +8342,11 @@ static bool create_myisam_tmp_table(TABLE *table,TMP_TABLE_PARAM *param,
if (keyinfo->key_length >= table->file->max_key_length() ||
keyinfo->key_parts > table->file->max_key_parts() ||
- table->uniques)
+ table->s->uniques)
{
/* Can't create a key; Make a unique constraint instead of a key */
- table->keys=0;
- table->uniques=1;
+ table->s->keys= 0;
+ table->s->uniques= 1;
using_unique_constraint=1;
bzero((char*) &uniquedef,sizeof(uniquedef));
uniquedef.keysegs=keyinfo->key_parts;
@@ -8358,7 +8358,7 @@ static bool create_myisam_tmp_table(TABLE *table,TMP_TABLE_PARAM *param,
param->recinfo->type= FIELD_CHECK;
param->recinfo->length=MI_UNIQUE_HASH_LENGTH;
param->recinfo++;
- table->reclength+=MI_UNIQUE_HASH_LENGTH;
+ table->s->reclength+=MI_UNIQUE_HASH_LENGTH;
}
else
{
@@ -8380,7 +8380,7 @@ static bool create_myisam_tmp_table(TABLE *table,TMP_TABLE_PARAM *param,
seg->type=
((keyinfo->key_part[i].key_type & FIELDFLAG_BINARY) ?
HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2);
- seg->bit_start= field->pack_length() - table->blob_ptr_size;
+ seg->bit_start= field->pack_length() - table->s->blob_ptr_size;
seg->flag= HA_BLOB_PART;
seg->length=0; // Whole blob in unique constraint
}
@@ -8413,10 +8413,10 @@ static bool create_myisam_tmp_table(TABLE *table,TMP_TABLE_PARAM *param,
OPTION_BIG_TABLES)
create_info.data_file_length= ~(ulonglong) 0;
- if ((error=mi_create(table->real_name,table->keys,&keydef,
+ if ((error=mi_create(table->s->table_name,table->s->keys,&keydef,
(uint) (param->recinfo-param->start_recinfo),
param->start_recinfo,
- table->uniques, &uniquedef,
+ table->s->uniques, &uniquedef,
&create_info,
HA_CREATE_TMP_TABLE)))
{
@@ -8426,7 +8426,7 @@ static bool create_myisam_tmp_table(TABLE *table,TMP_TABLE_PARAM *param,
}
statistic_increment(table->in_use->status_var.created_tmp_disk_tables,
&LOCK_status);
- table->db_record_offset=1;
+ table->s->db_record_offset= 1;
DBUG_RETURN(0);
err:
DBUG_RETURN(1);
@@ -8438,7 +8438,7 @@ free_tmp_table(THD *thd, TABLE *entry)
{
const char *save_proc_info;
DBUG_ENTER("free_tmp_table");
- DBUG_PRINT("enter",("table: %s",entry->table_name));
+ DBUG_PRINT("enter",("table: %s",entry->alias));
save_proc_info=thd->proc_info;
thd->proc_info="removing tmp table";
@@ -8454,8 +8454,9 @@ free_tmp_table(THD *thd, TABLE *entry)
here and we have to ensure that delete_table gets the table name in
the original case.
*/
- if (!(test_flags & TEST_KEEP_TMP_TABLES) || entry->db_type == DB_TYPE_HEAP)
- entry->file->delete_table(entry->real_name);
+ if (!(test_flags & TEST_KEEP_TMP_TABLES) ||
+ entry->s->db_type == DB_TYPE_HEAP)
+ entry->file->delete_table(entry->s->table_name);
delete entry->file;
}
@@ -8485,14 +8486,15 @@ bool create_myisam_from_heap(THD *thd, TABLE *table, TMP_TABLE_PARAM *param,
int write_err;
DBUG_ENTER("create_myisam_from_heap");
- if (table->db_type != DB_TYPE_HEAP || error != HA_ERR_RECORD_FILE_FULL)
+ if (table->s->db_type != DB_TYPE_HEAP || error != HA_ERR_RECORD_FILE_FULL)
{
table->file->print_error(error,MYF(0));
DBUG_RETURN(1);
}
new_table= *table;
- new_table.db_type=DB_TYPE_MYISAM;
- if (!(new_table.file=get_new_handler(&new_table,DB_TYPE_MYISAM)))
+ new_table.s= &new_table.share_not_to_be_used;
+ new_table.s->db_type= DB_TYPE_MYISAM;
+ if (!(new_table.file= get_new_handler(&new_table,DB_TYPE_MYISAM)))
DBUG_RETURN(1); // End of memory
save_proc_info=thd->proc_info;
@@ -8542,10 +8544,11 @@ bool create_myisam_from_heap(THD *thd, TABLE *table, TMP_TABLE_PARAM *param,
/* remove heap table and change to use myisam table */
(void) table->file->ha_rnd_end();
(void) table->file->close();
- (void) table->file->delete_table(table->real_name);
+ (void) table->file->delete_table(table->s->table_name);
delete table->file;
table->file=0;
- *table =new_table;
+ *table= new_table;
+ table->s= &table->share_not_to_be_used;
table->file->change_table_ptr(table);
thd->proc_info= (!strcmp(save_proc_info,"Copying to tmp table") ?
"Copying to tmp table on disk" : save_proc_info);
@@ -8557,7 +8560,7 @@ bool create_myisam_from_heap(THD *thd, TABLE *table, TMP_TABLE_PARAM *param,
(void) table->file->ha_rnd_end();
(void) new_table.file->close();
err1:
- new_table.file->delete_table(new_table.real_name);
+ new_table.file->delete_table(new_table.s->table_name);
delete new_table.file;
err2:
thd->proc_info=save_proc_info;
@@ -8600,7 +8603,7 @@ do_select(JOIN *join,List<Item> *fields,TABLE *table,Procedure *procedure)
{
if (table->group && join->tmp_table_param.sum_func_count)
{
- if (table->keys)
+ if (table->s->keys)
{
DBUG_PRINT("info",("Using end_update"));
end_select=end_update;
@@ -9003,7 +9006,7 @@ sub_select(JOIN *join,JOIN_TAB *join_tab,bool end_of_records)
join_tab->found= 1;
join_tab->not_null_compl= 0;
/* The outer row is complemented by nulls for each inner tables */
- restore_record(join_tab->table,default_values); // Make empty record
+ restore_record(join_tab->table,s->default_values); // Make empty record
mark_as_null_row(join_tab->table); // For group by without error
select_cond= join_tab->select_cond;
/* Check all attached conditions for inner table rows. */
@@ -9138,7 +9141,7 @@ int report_error(TABLE *table, int error)
*/
if (error != HA_ERR_LOCK_DEADLOCK && error != HA_ERR_LOCK_WAIT_TIMEOUT)
sql_print_error("Got error %d when reading table '%s'",
- error, table->path);
+ error, table->s->path);
table->file->print_error(error,MYF(0));
return 1;
}
@@ -9220,7 +9223,7 @@ join_read_system(JOIN_TAB *tab)
if (table->status & STATUS_GARBAGE) // If first read
{
if ((error=table->file->read_first_row(table->record[0],
- table->primary_key)))
+ table->s->primary_key)))
{
if (error != HA_ERR_END_OF_FILE)
return report_error(table, error);
@@ -9804,7 +9807,7 @@ end_write(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)),
if (create_myisam_from_heap(join->thd, table, &join->tmp_table_param,
error,1))
DBUG_RETURN(-1); // Not a table_is_full error
- table->uniques=0; // To ensure rows are the same
+ table->s->uniques=0; // To ensure rows are the same
}
if (++join->send_records >= join->tmp_table_param.end_write_records &&
join->do_send_rows)
@@ -10243,7 +10246,7 @@ uint find_shortest_key(TABLE *table, const key_map *usable_keys)
uint best= MAX_KEY;
if (!usable_keys->is_clear_all())
{
- for (uint nr=0; nr < table->keys ; nr++)
+ for (uint nr=0; nr < table->s->keys ; nr++)
{
if (usable_keys->is_set(nr))
{
@@ -10309,7 +10312,7 @@ test_if_subkey(ORDER *order, TABLE *table, uint ref, uint ref_key_parts,
KEY_PART_INFO *ref_key_part= table->key_info[ref].key_part;
KEY_PART_INFO *ref_key_part_end= ref_key_part + ref_key_parts;
- for (nr= 0 ; nr < table->keys ; nr++)
+ for (nr= 0 ; nr < table->s->keys ; nr++)
{
if (usable_keys->is_set(nr) &&
table->key_info[nr].key_length < min_length &&
@@ -10510,7 +10513,7 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
else
keys= usable_keys;
- for (nr=0; nr < table->keys ; nr++)
+ for (nr=0; nr < table->s->keys ; nr++)
{
uint not_used;
if (keys.is_set(nr))
@@ -10624,7 +10627,7 @@ create_sort_index(THD *thd, JOIN *join, ORDER *order,
goto err;
}
}
- if (table->tmp_table)
+ if (table->s->tmp_table)
table->file->info(HA_STATUS_VARIABLE); // Get record count
table->sort.found_records=filesort(thd, table,sortorder, length,
select, filesort_limit, &examined_rows);
@@ -10700,7 +10703,7 @@ static bool compare_record(TABLE *table, Field **ptr)
{
for (; *ptr ; ptr++)
{
- if ((*ptr)->cmp_offset(table->rec_buff_length))
+ if ((*ptr)->cmp_offset(table->s->rec_buff_length))
return 1;
}
return 0;
@@ -10753,14 +10756,14 @@ remove_duplicates(JOIN *join, TABLE *entry,List<Item> &fields, Item *having)
join->unit->select_limit_cnt= 1; // Only send first row
DBUG_RETURN(0);
}
- Field **first_field=entry->field+entry->fields - field_count;
- offset=entry->field[entry->fields - field_count]->offset();
- reclength=entry->reclength-offset;
+ Field **first_field=entry->field+entry->s->fields - field_count;
+ offset=entry->field[entry->s->fields - field_count]->offset();
+ reclength=entry->s->reclength-offset;
free_io_cache(entry); // Safety
entry->file->info(HA_STATUS_VARIABLE);
- if (entry->db_type == DB_TYPE_HEAP ||
- (!entry->blob_fields &&
+ if (entry->s->db_type == DB_TYPE_HEAP ||
+ (!entry->s->blob_fields &&
((ALIGN_SIZE(reclength) + HASH_OVERHEAD) * entry->file->records <
thd->variables.sortbuff_size)))
error=remove_dup_with_hash_index(join->thd, entry,
@@ -10782,7 +10785,7 @@ static int remove_dup_with_compare(THD *thd, TABLE *table, Field **first_field,
char *org_record,*new_record;
byte *record;
int error;
- ulong reclength=table->reclength-offset;
+ ulong reclength= table->s->reclength-offset;
DBUG_ENTER("remove_dup_with_compare");
org_record=(char*) (record=table->record[0])+offset;
@@ -11058,10 +11061,10 @@ join_init_cache(THD *thd,JOIN_TAB *tables,uint table_count)
}
}
/* Copy null bits from table */
- if (null_fields && tables[i].table->null_fields)
+ if (null_fields && tables[i].table->s->null_fields)
{ /* must copy null bits */
copy->str=(char*) tables[i].table->null_flags;
- copy->length=tables[i].table->null_bytes;
+ copy->length= tables[i].table->s->null_bytes;
copy->strip=0;
copy->blob_field=0;
length+=copy->length;
@@ -12690,8 +12693,8 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
item_list.push_back(new Item_string(table_name_buffer, len, cs));
}
else
- item_list.push_back(new Item_string(table->table_name,
- strlen(table->table_name),
+ item_list.push_back(new Item_string(table->alias,
+ strlen(table->alias),
cs));
/* type */
item_list.push_back(new Item_string(join_type_str[tab->type],
@@ -12701,7 +12704,7 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
if (!tab->keys.is_clear_all())
{
uint j;
- for (j=0 ; j < table->keys ; j++)
+ for (j=0 ; j < table->s->keys ; j++)
{
if (tab->keys.is_set(j))
{
@@ -12999,8 +13002,8 @@ void st_table_list::print(THD *thd, String *str)
}
else
{
- append_identifier(thd, str, real_name, real_name_length);
- cmp_name= real_name;
+ append_identifier(thd, str, table_name, table_name_length);
+ cmp_name= table_name;
}
}
if (my_strcasecmp(table_alias_charset, cmp_name, alias))
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 6ffad1e2bff..1e284891b90 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -311,7 +311,7 @@ mysql_find_files(THD *thd,List<char> *files, const char *db,const char *path,
if (db && !(col_access & TABLE_ACLS))
{
table_list.db= (char*) db;
- table_list.real_name=file->name;
+ table_list.table_name= file->name;
table_list.grant.privilege=col_access;
if (check_grant(thd, TABLE_ACLS, &table_list, 1, UINT_MAX, 1))
continue;
@@ -342,7 +342,7 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list)
int res;
DBUG_ENTER("mysqld_show_create");
DBUG_PRINT("enter",("db: %s table: %s",table_list->db,
- table_list->real_name));
+ table_list->table_name));
/* Only one table for now, but VIEW can involve several tables */
if (open_and_lock_tables(thd, table_list))
@@ -353,7 +353,7 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list)
if (thd->lex->only_view && !table_list->view)
{
my_error(ER_WRONG_OBJECT, MYF(0),
- table_list->db, table_list->real_name, "VIEW");
+ table_list->db, table_list->table_name, "VIEW");
DBUG_RETURN(TRUE);
}
@@ -395,7 +395,7 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list)
if (table_list->schema_table)
protocol->store(table_list->schema_table_name, system_charset_info);
else
- protocol->store(table->table_name, system_charset_info);
+ protocol->store(table->alias, system_charset_info);
if (store_create_info(thd, table_list, &buffer))
DBUG_RETURN(TRUE);
}
@@ -535,7 +535,7 @@ mysqld_list_fields(THD *thd, TABLE_LIST *table_list, const char *wild)
TABLE *table;
int res;
DBUG_ENTER("mysqld_list_fields");
- DBUG_PRINT("enter",("table: %s",table_list->real_name));
+ DBUG_PRINT("enter",("table: %s",table_list->table_name));
table_list->lock_type= TL_UNLOCK;
if (open_and_lock_tables(thd, table_list))
@@ -551,7 +551,7 @@ mysqld_list_fields(THD *thd, TABLE_LIST *table_list, const char *wild)
!wild_case_compare(system_charset_info, field->field_name,wild))
field_list.push_back(new Item_field(field));
}
- restore_record(table,default_values); // Get empty record
+ restore_record(table, s->default_values); // Get empty record
if (thd->protocol->send_fields(&field_list, Protocol::SEND_DEFAULTS |
Protocol::SEND_EOF))
DBUG_VOID_RETURN;
@@ -566,7 +566,7 @@ mysqld_dump_create_info(THD *thd, TABLE_LIST *table_list, int fd)
Protocol *protocol= thd->protocol;
String *packet= protocol->storage_packet();
DBUG_ENTER("mysqld_dump_create_info");
- DBUG_PRINT("enter",("table: %s",table_list->table->real_name));
+ DBUG_PRINT("enter",("table: %s",table_list->table->s->table_name));
protocol->prepare_for_resend();
if (store_create_info(thd, table_list, packet))
@@ -715,13 +715,15 @@ static int
store_create_info(THD *thd, TABLE_LIST *table_list, String *packet)
{
List<Item> field_list;
- char tmp[MAX_FIELD_WIDTH], *for_str, buff[128], *end, *alias;
+ char tmp[MAX_FIELD_WIDTH], *for_str, buff[128], *end;
+ const char *alias;
String type(tmp, sizeof(tmp), system_charset_info);
Field **ptr,*field;
uint primary_key;
KEY *key_info;
TABLE *table= table_list->table;
handler *file= table->file;
+ TABLE_SHARE *share= table->s;
HA_CREATE_INFO create_info;
my_bool foreign_db_mode= (thd->variables.sql_mode & (MODE_POSTGRESQL |
MODE_ORACLE |
@@ -732,21 +734,20 @@ store_create_info(THD *thd, TABLE_LIST *table_list, String *packet)
my_bool limited_mysql_mode= (thd->variables.sql_mode &
(MODE_NO_FIELD_OPTIONS | MODE_MYSQL323 |
MODE_MYSQL40)) != 0;
-
DBUG_ENTER("store_create_info");
- DBUG_PRINT("enter",("table: %s",table->real_name));
+ DBUG_PRINT("enter",("table: %s", table->s->table_name));
- restore_record(table,default_values); // Get empty record
+ restore_record(table, s->default_values); // Get empty record
- if (table->tmp_table)
+ if (share->tmp_table)
packet->append("CREATE TEMPORARY TABLE ", 23);
else
packet->append("CREATE TABLE ", 13);
if (table_list->schema_table)
alias= table_list->schema_table_name;
else
- alias= (lower_case_table_names == 2 ? table->table_name :
- table->real_name);
+ alias= (lower_case_table_names == 2 ? table->alias :
+ share->table_name);
append_identifier(thd, packet, alias, strlen(alias));
packet->append(" (\n", 3);
@@ -773,7 +774,7 @@ store_create_info(THD *thd, TABLE_LIST *table_list, String *packet)
if (field->has_charset() && !limited_mysql_mode && !foreign_db_mode)
{
- if (field->charset() != table->table_charset)
+ if (field->charset() != share->table_charset)
{
packet->append(" character set ", 15);
packet->append(field->charset()->csname);
@@ -859,9 +860,9 @@ store_create_info(THD *thd, TABLE_LIST *table_list, String *packet)
file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK | HA_STATUS_TIME);
bzero((char*) &create_info, sizeof(create_info));
file->update_create_info(&create_info);
- primary_key= table->primary_key;
+ primary_key= share->primary_key;
- for (uint i=0 ; i < table->keys ; i++,key_info++)
+ for (uint i=0 ; i < share->keys ; i++,key_info++)
{
KEY_PART_INFO *key_part= key_info->key_part;
bool found_primary=0;
@@ -886,7 +887,7 @@ store_create_info(THD *thd, TABLE_LIST *table_list, String *packet)
if (!(thd->variables.sql_mode & MODE_NO_KEY_OPTIONS) &&
!limited_mysql_mode && !foreign_db_mode)
{
- if (table->db_type == DB_TYPE_HEAP &&
+ if (share->db_type == DB_TYPE_HEAP &&
key_info->algorithm == HA_KEY_ALG_BTREE)
packet->append(" TYPE BTREE", 11);
@@ -941,58 +942,58 @@ store_create_info(THD *thd, TABLE_LIST *table_list, String *packet)
packet->append(" ENGINE=", 8);
packet->append(file->table_type());
- if (table->table_charset &&
+ if (share->table_charset &&
!(thd->variables.sql_mode & MODE_MYSQL323) &&
!(thd->variables.sql_mode & MODE_MYSQL40))
{
packet->append(" DEFAULT CHARSET=", 17);
- packet->append(table->table_charset->csname);
- if (!(table->table_charset->state & MY_CS_PRIMARY))
+ packet->append(share->table_charset->csname);
+ if (!(share->table_charset->state & MY_CS_PRIMARY))
{
packet->append(" COLLATE=", 9);
- packet->append(table->table_charset->name);
+ packet->append(table->s->table_charset->name);
}
}
- if (table->min_rows)
+ if (share->min_rows)
{
packet->append(" MIN_ROWS=", 10);
- end= longlong10_to_str(table->min_rows, buff, 10);
+ end= longlong10_to_str(share->min_rows, buff, 10);
packet->append(buff, (uint) (end- buff));
}
- if (table->max_rows)
+ if (share->max_rows)
{
packet->append(" MAX_ROWS=", 10);
- end= longlong10_to_str(table->max_rows, buff, 10);
+ end= longlong10_to_str(share->max_rows, buff, 10);
packet->append(buff, (uint) (end - buff));
}
- if (table->avg_row_length)
+ if (share->avg_row_length)
{
packet->append(" AVG_ROW_LENGTH=", 16);
- end= longlong10_to_str(table->avg_row_length, buff,10);
+ end= longlong10_to_str(share->avg_row_length, buff,10);
packet->append(buff, (uint) (end - buff));
}
- if (table->db_create_options & HA_OPTION_PACK_KEYS)
+ if (share->db_create_options & HA_OPTION_PACK_KEYS)
packet->append(" PACK_KEYS=1", 12);
- if (table->db_create_options & HA_OPTION_NO_PACK_KEYS)
+ if (share->db_create_options & HA_OPTION_NO_PACK_KEYS)
packet->append(" PACK_KEYS=0", 12);
- if (table->db_create_options & HA_OPTION_CHECKSUM)
+ if (share->db_create_options & HA_OPTION_CHECKSUM)
packet->append(" CHECKSUM=1", 11);
- if (table->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
+ if (share->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
packet->append(" DELAY_KEY_WRITE=1",18);
- if (table->row_type != ROW_TYPE_DEFAULT)
+ if (share->row_type != ROW_TYPE_DEFAULT)
{
packet->append(" ROW_FORMAT=",12);
- packet->append(ha_row_type[(uint) table->row_type]);
+ packet->append(ha_row_type[(uint) share->row_type]);
}
table->file->append_create_info(packet);
- if (table->comment && table->comment[0])
+ if (share->comment && share->comment[0])
{
packet->append(" COMMENT=", 9);
- append_unescaped(packet, table->comment, strlen(table->comment));
+ append_unescaped(packet, share->comment, strlen(share->comment));
}
if (file->raid_type)
{
@@ -1516,7 +1517,7 @@ static bool show_status_array(THD *thd, const char *wild,
default:
break;
}
- restore_record(table, default_values);
+ restore_record(table, s->default_values);
table->field[0]->store(name_buffer, strlen(name_buffer),
system_charset_info);
table->field[1]->store(pos, (uint32) (end - pos), system_charset_info);
@@ -1802,7 +1803,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
bool res= open_and_lock_tables(thd, show_table_list);
if (schema_table->process_table(thd, show_table_list,
table, res, show_table_list->db,
- show_table_list->real_name))
+ show_table_list->table_name))
{
DBUG_RETURN(1);
}
@@ -1870,7 +1871,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
List_iterator_fast<char> it(files);
while ((file_name=it++))
{
- restore_record(table, default_values);
+ restore_record(table, s->default_values);
table->field[schema_table->idx_field1]->
store(base_name, strlen(base_name), system_charset_info);
table->field[schema_table->idx_field2]->
@@ -1939,7 +1940,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
void store_schema_shemata(TABLE *table, const char *db_name,
const char* cs_name)
{
- restore_record(table, default_values);
+ restore_record(table, s->default_values);
table->field[1]->store(db_name, strlen(db_name), system_charset_info);
table->field[2]->store(cs_name, strlen(cs_name), system_charset_info);
table->file->write_row(table->record[0]);
@@ -2009,9 +2010,9 @@ static int get_schema_tables_record(THD *thd, struct st_table_list *tables,
const char *tmp_buff;
TIME time;
CHARSET_INFO *cs= system_charset_info;
-
DBUG_ENTER("get_schema_tables_record");
- restore_record(table, default_values);
+
+ restore_record(table, s->default_values);
table->field[1]->store(base_name, strlen(base_name), cs);
table->field[2]->store(file_name, strlen(file_name), cs);
if (res)
@@ -2031,9 +2032,11 @@ static int get_schema_tables_record(THD *thd, struct st_table_list *tables,
else
{
TABLE *show_table= tables->table;
+ TABLE_SHARE *share= show_table->s;
handler *file= show_table->file;
+
file->info(HA_STATUS_VARIABLE | HA_STATUS_TIME | HA_STATUS_NO_LOCK);
- if (show_table->tmp_table == TMP_TABLE)
+ if (share->tmp_table == TMP_TABLE)
table->field[3]->store("TEMPORARY", 9, cs);
else
table->field[3]->store("BASE TABLE", 10, cs);
@@ -2046,10 +2049,10 @@ static int get_schema_tables_record(THD *thd, struct st_table_list *tables,
}
tmp_buff= file->table_type();
table->field[4]->store(tmp_buff, strlen(tmp_buff), cs);
- table->field[5]->store((longlong) show_table->frm_version);
- tmp_buff= ((show_table->db_options_in_use &
+ table->field[5]->store((longlong) share->frm_version);
+ tmp_buff= ((share->db_options_in_use &
HA_OPTION_COMPRESS_RECORD) ? "Compressed" :
- (show_table->db_options_in_use & HA_OPTION_PACK_RECORD) ?
+ (share->db_options_in_use & HA_OPTION_PACK_RECORD) ?
"Dynamic" : "Fixed");
table->field[6]->store(tmp_buff, strlen(tmp_buff), cs);
if (!tables->schema_table)
@@ -2095,8 +2098,8 @@ static int get_schema_tables_record(THD *thd, struct st_table_list *tables,
table->field[16]->store_time(&time, MYSQL_TIMESTAMP_DATETIME);
table->field[16]->set_notnull();
}
- tmp_buff= (show_table->table_charset ? show_table->
- table_charset->name : "default");
+ tmp_buff= (share->table_charset ?
+ share->table_charset->name : "default");
table->field[17]->store(tmp_buff, strlen(tmp_buff), cs);
if (file->table_flags() & (ulong) HA_HAS_CHECKSUM)
{
@@ -2106,32 +2109,32 @@ static int get_schema_tables_record(THD *thd, struct st_table_list *tables,
char option_buff[350],*ptr;
ptr=option_buff;
- if (show_table->min_rows)
+ if (share->min_rows)
{
ptr=strmov(ptr," min_rows=");
- ptr=longlong10_to_str(show_table->min_rows,ptr,10);
+ ptr=longlong10_to_str(share->min_rows,ptr,10);
}
- if (show_table->max_rows)
+ if (share->max_rows)
{
ptr=strmov(ptr," max_rows=");
- ptr=longlong10_to_str(show_table->max_rows,ptr,10);
+ ptr=longlong10_to_str(share->max_rows,ptr,10);
}
- if (show_table->avg_row_length)
+ if (share->avg_row_length)
{
ptr=strmov(ptr," avg_row_length=");
- ptr=longlong10_to_str(show_table->avg_row_length,ptr,10);
+ ptr=longlong10_to_str(share->avg_row_length,ptr,10);
}
- if (show_table->db_create_options & HA_OPTION_PACK_KEYS)
+ if (share->db_create_options & HA_OPTION_PACK_KEYS)
ptr=strmov(ptr," pack_keys=1");
- if (show_table->db_create_options & HA_OPTION_NO_PACK_KEYS)
+ if (share->db_create_options & HA_OPTION_NO_PACK_KEYS)
ptr=strmov(ptr," pack_keys=0");
- if (show_table->db_create_options & HA_OPTION_CHECKSUM)
+ if (share->db_create_options & HA_OPTION_CHECKSUM)
ptr=strmov(ptr," checksum=1");
- if (show_table->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
+ if (share->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
ptr=strmov(ptr," delay_key_write=1");
- if (show_table->row_type != ROW_TYPE_DEFAULT)
+ if (share->row_type != ROW_TYPE_DEFAULT)
ptr=strxmov(ptr, " row_format=",
- ha_row_type[(uint) show_table->row_type],
+ ha_row_type[(uint) share->row_type],
NullS);
if (file->raid_type)
{
@@ -2146,13 +2149,13 @@ static int get_schema_tables_record(THD *thd, struct st_table_list *tables,
(ptr == option_buff ? 0 :
(uint) (ptr-option_buff)-1), cs);
{
- char *comment= show_table->file->
- update_table_comment(show_table->comment);
+ char *comment;
+ comment= show_table->file->update_table_comment(share->comment);
if (comment)
{
table->field[20]->store(comment, strlen(comment), cs);
- if (comment != show_table->comment)
- my_free(comment,MYF(0));
+ if (comment != share->comment)
+ my_free(comment, MYF(0));
}
}
}
@@ -2190,7 +2193,7 @@ static int get_schema_column_record(THD *thd, struct st_table_list *tables,
TABLE *show_table= tables->table;
handler *file= show_table->file;
file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
- restore_record(show_table, default_values);
+ restore_record(show_table, s->default_values);
Field **ptr,*field;
int count= 0;
for (ptr=show_table->field; (field= *ptr) ; ptr++)
@@ -2207,7 +2210,7 @@ static int get_schema_column_record(THD *thd, struct st_table_list *tables,
String type(tmp,sizeof(tmp), system_charset_info);
char tmp_buffer[128];
count++;
- restore_record(table, default_values);
+ restore_record(table, s->default_values);
table->field[1]->store(base_name, strlen(base_name), cs);
table->field[2]->store(file_name, strlen(file_name), cs);
table->field[3]->store(field->field_name, strlen(field->field_name),
@@ -2317,7 +2320,7 @@ static int get_schema_column_record(THD *thd, struct st_table_list *tables,
check_access(thd,SELECT_ACL | EXTRA_ACL, base_name,
&tables->grant.privilege, 0, 0);
col_access= get_column_grant(thd, &tables->grant, tables->db,
- tables->real_name,
+ tables->table_name,
field->field_name) & COL_ACLS;
for (uint bitnr=0; col_access ; col_access>>=1,bitnr++)
{
@@ -2354,7 +2357,7 @@ int fill_schema_charsets(THD *thd, TABLE_LIST *tables, COND *cond)
!(wild && wild[0] &&
wild_case_compare(scs, tmp_cs->csname,wild)))
{
- restore_record(table, default_values);
+ restore_record(table, s->default_values);
table->field[0]->store(tmp_cs->csname, strlen(tmp_cs->csname), scs);
table->field[1]->store(tmp_cs->name, strlen(tmp_cs->name), scs);
table->field[2]->store(tmp_cs->comment ? tmp_cs->comment : "",
@@ -2391,7 +2394,7 @@ int fill_schema_collation(THD *thd, TABLE_LIST *tables, COND *cond)
wild_case_compare(scs, tmp_cl->name,wild)))
{
const char *tmp_buff;
- restore_record(table, default_values);
+ restore_record(table, s->default_values);
table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
table->field[2]->store((longlong) tmp_cl->number);
@@ -2427,7 +2430,7 @@ int fill_schema_coll_charset_app(THD *thd, TABLE_LIST *tables, COND *cond)
if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) ||
!my_charset_same(tmp_cs,tmp_cl))
continue;
- restore_record(table, default_values);
+ restore_record(table, s->default_values);
table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
table->file->write_row(table->record[0]);
@@ -2445,7 +2448,7 @@ void store_schema_proc(THD *thd, TABLE *table,
TIME time;
LEX *lex= thd->lex;
CHARSET_INFO *cs= system_charset_info;
- restore_record(table, default_values);
+ restore_record(table, s->default_values);
if (lex->orig_sql_command == SQLCOM_SHOW_STATUS_PROC &&
proc_table->field[2]->val_int() == TYPE_ENUM_PROCEDURE ||
lex->orig_sql_command == SQLCOM_SHOW_STATUS_FUNC &&
@@ -2520,7 +2523,7 @@ int fill_schema_proc(THD *thd, TABLE_LIST *tables, COND *cond)
bzero((char*) &proc_tables,sizeof(proc_tables));
proc_tables.db= (char*) "mysql";
- proc_tables.real_name= proc_tables.alias= (char*) "proc";
+ proc_tables.table_name= proc_tables.alias= (char*) "proc";
proc_tables.lock_type= TL_READ;
if (!(proc_table= open_ltable(thd, &proc_tables, TL_READ)))
{
@@ -2573,13 +2576,13 @@ static int get_schema_stat_record(THD *thd, struct st_table_list *tables,
show_table->file->info(HA_STATUS_VARIABLE |
HA_STATUS_NO_LOCK |
HA_STATUS_TIME);
- for (uint i=0 ; i < show_table->keys ; i++,key_info++)
+ for (uint i=0 ; i < show_table->s->keys ; i++,key_info++)
{
KEY_PART_INFO *key_part= key_info->key_part;
const char *str;
for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
{
- restore_record(table, default_values);
+ restore_record(table, s->default_values);
table->field[1]->store(base_name, strlen(base_name), cs);
table->field[2]->store(file_name, strlen(file_name), cs);
table->field[3]->store((longlong) ((key_info->flags &
@@ -2618,7 +2621,7 @@ static int get_schema_stat_record(THD *thd, struct st_table_list *tables,
table->field[12]->store(pos, strlen(pos), cs);
pos= show_table->file->index_type(i);
table->field[13]->store(pos, strlen(pos), cs);
- if (!show_table->keys_in_use.is_set(i))
+ if (!show_table->s->keys_in_use.is_set(i))
table->field[14]->store("disabled", 8, cs);
else
table->field[14]->store("", 0, cs);
@@ -2642,9 +2645,10 @@ static int get_schema_views_record(THD *thd, struct st_table_list *tables,
{
if (tables->view)
{
- restore_record(table, default_values);
+ restore_record(table, s->default_values);
table->field[1]->store(tables->view_db.str, tables->view_db.length, cs);
- table->field[2]->store(tables->view_name.str,tables->view_name.length,cs);
+ table->field[2]->store(tables->view_name.str, tables->view_name.length,
+ cs);
table->field[3]->store(tables->query.str, tables->query.length, cs);
if (tables->with_check != VIEW_CHECK_NONE)
@@ -2680,7 +2684,7 @@ void store_constraints(TABLE *table, const char*db, const char *tname,
const char *con_type, uint con_len)
{
CHARSET_INFO *cs= system_charset_info;
- restore_record(table, default_values);
+ restore_record(table, s->default_values);
table->field[1]->store(db, strlen(db), cs);
table->field[2]->store(key_name, key_len, cs);
table->field[3]->store(db, strlen(db), cs);
@@ -2709,11 +2713,11 @@ static int get_schema_constraints_record(THD *thd, struct st_table_list *tables,
List<FOREIGN_KEY_INFO> f_key_list;
TABLE *show_table= tables->table;
KEY *key_info=show_table->key_info;
- uint primary_key= show_table->primary_key;
+ uint primary_key= show_table->s->primary_key;
show_table->file->info(HA_STATUS_VARIABLE |
HA_STATUS_NO_LOCK |
HA_STATUS_TIME);
- for (uint i=0 ; i < show_table->keys ; i++, key_info++)
+ for (uint i=0 ; i < show_table->s->keys ; i++, key_info++)
{
if (i != primary_key && !(key_info->flags & HA_NOSAME))
continue;
@@ -2774,11 +2778,11 @@ static int get_schema_key_column_usage_record(THD *thd,
List<FOREIGN_KEY_INFO> f_key_list;
TABLE *show_table= tables->table;
KEY *key_info=show_table->key_info;
- uint primary_key= show_table->primary_key;
+ uint primary_key= show_table->s->primary_key;
show_table->file->info(HA_STATUS_VARIABLE |
HA_STATUS_NO_LOCK |
HA_STATUS_TIME);
- for (uint i=0 ; i < show_table->keys ; i++, key_info++)
+ for (uint i=0 ; i < show_table->s->keys ; i++, key_info++)
{
if (i != primary_key && !(key_info->flags & HA_NOSAME))
continue;
@@ -2790,7 +2794,7 @@ static int get_schema_key_column_usage_record(THD *thd,
if (key_part->field)
{
f_idx++;
- restore_record(table, default_values);
+ restore_record(table, s->default_values);
store_key_column_usage(table, base_name, file_name,
key_info->name,
strlen(key_info->name),
@@ -2815,7 +2819,7 @@ static int get_schema_key_column_usage_record(THD *thd,
{
r_info= it1++;
f_idx++;
- restore_record(table, default_values);
+ restore_record(table, s->default_values);
store_key_column_usage(table, base_name, file_name,
f_key_info->forein_id->str,
f_key_info->forein_id->length,
@@ -2843,7 +2847,7 @@ int fill_open_tables(THD *thd, TABLE_LIST *tables, COND *cond)
for (; open_list ; open_list=open_list->next)
{
- restore_record(table, default_values);
+ restore_record(table, s->default_values);
table->field[0]->store(open_list->db, strlen(open_list->db), cs);
table->field[1]->store(open_list->table, strlen(open_list->table), cs);
table->field[2]->store((longlong) open_list->in_use);
@@ -3182,13 +3186,13 @@ int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list)
{
DBUG_RETURN(1);
}
- table->tmp_table= TMP_TABLE;
+ table->s->tmp_table= TMP_TABLE;
table->grant.privilege= SELECT_ACL;
table->alias_name_used= my_strcasecmp(table_alias_charset,
- table_list->real_name,
+ table_list->table_name,
table_list->alias);
- table_list->schema_table_name= table_list->real_name;
- table_list->real_name= table->real_name;
+ table_list->schema_table_name= table_list->table_name;
+ table_list->table_name= (char*) table->s->table_name;
table_list->table= table;
table->next= thd->derived_tables;
thd->derived_tables= table;
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 757e968a582..d7a272f804c 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -79,7 +79,7 @@ bool mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists,
{
if (thd->global_read_lock)
{
- my_error(ER_TABLE_NOT_LOCKED_FOR_WRITE, MYF(0), tables->real_name);
+ my_error(ER_TABLE_NOT_LOCKED_FOR_WRITE, MYF(0), tables->table_name);
error= TRUE;
goto err;
}
@@ -194,7 +194,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
{
char *db=table->db;
mysql_ha_flush(thd, table, MYSQL_HA_CLOSE_FINAL);
- if (!close_temporary_table(thd, db, table->real_name))
+ if (!close_temporary_table(thd, db, table->table_name))
{
tmp_table_deleted=1;
continue; // removed temporary table
@@ -203,17 +203,17 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
error=0;
if (!drop_temporary)
{
- abort_locked_tables(thd,db,table->real_name);
- while (remove_table_from_cache(thd,db,table->real_name) && !thd->killed)
+ abort_locked_tables(thd,db,table->table_name);
+ while (remove_table_from_cache(thd,db,table->table_name) && !thd->killed)
{
dropping_tables++;
(void) pthread_cond_wait(&COND_refresh,&LOCK_open);
dropping_tables--;
}
- drop_locked_tables(thd,db,table->real_name);
+ drop_locked_tables(thd,db,table->table_name);
if (thd->killed)
DBUG_RETURN(-1);
- alias= (lower_case_table_names == 2) ? table->alias : table->real_name;
+ alias= (lower_case_table_names == 2) ? table->alias : table->table_name;
/* remove form file and isam files */
strxmov(path, mysql_data_home, "/", db, "/", alias, reg_ext, NullS);
(void) unpack_filename(path,path);
@@ -225,7 +225,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
if (if_exists)
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR),
- table->real_name);
+ table->table_name);
else
error= 1;
}
@@ -254,7 +254,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
{
if (wrong_tables.length())
wrong_tables.append(',');
- wrong_tables.append(String(table->real_name,system_charset_info));
+ wrong_tables.append(String(table->table_name,system_charset_info));
}
}
thd->tmp_table_used= tmp_table_deleted;
@@ -1548,19 +1548,20 @@ TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info,
{
TABLE tmp_table; // Used during 'create_field()'
TABLE *table= 0;
- tmp_table.table_name=0;
uint select_field_count= items->elements;
- DBUG_ENTER("create_table_from_items");
-
/* Add selected items to field list */
List_iterator_fast<Item> it(*items);
Item *item;
Field *tmp_field;
- tmp_table.db_create_options=0;
+ DBUG_ENTER("create_table_from_items");
+
+ tmp_table.alias= 0;
+ tmp_table.s= &tmp_table.share_not_to_be_used;
+ tmp_table.s->db_create_options=0;
+ tmp_table.s->blob_ptr_size= portable_sizeof_char_ptr;
+ tmp_table.s->db_low_byte_first= test(create_info->db_type == DB_TYPE_MYISAM ||
+ create_info->db_type == DB_TYPE_HEAP);
tmp_table.null_row=tmp_table.maybe_null=0;
- tmp_table.blob_ptr_size=portable_sizeof_char_ptr;
- tmp_table.db_low_byte_first= test(create_info->db_type == DB_TYPE_MYISAM ||
- create_info->db_type == DB_TYPE_HEAP);
while ((item=it++))
{
@@ -1593,13 +1594,13 @@ TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info,
*/
{
tmp_disable_binlog(thd);
- if (!mysql_create_table(thd, create_table->db, create_table->real_name,
+ if (!mysql_create_table(thd, create_table->db, create_table->table_name,
create_info, *extra_fields, *keys, 0,
select_field_count))
{
if (!(table= open_table(thd, create_table, thd->mem_root, (bool*) 0)))
quick_rm_table(create_info->db_type, create_table->db,
- table_case_name(create_info, create_table->real_name));
+ table_case_name(create_info, create_table->table_name));
}
reenable_binlog(thd);
if (!table) // open failed
@@ -1613,7 +1614,7 @@ TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info,
hash_delete(&open_cache,(byte*) table);
VOID(pthread_mutex_unlock(&LOCK_open));
quick_rm_table(create_info->db_type, create_table->db,
- table_case_name(create_info, create_table->real_name));
+ table_case_name(create_info, create_table->table_name));
DBUG_RETURN(0);
}
table->file->extra(HA_EXTRA_WRITE_CACHE);
@@ -1696,7 +1697,7 @@ mysql_rename_table(enum db_type base,
static void wait_while_table_is_used(THD *thd,TABLE *table,
enum ha_extra_function function)
{
- DBUG_PRINT("enter",("table: %s", table->real_name));
+ DBUG_PRINT("enter",("table: %s", table->s->table_name));
DBUG_ENTER("wait_while_table_is_used");
safe_mutex_assert_owner(&LOCK_open);
@@ -1705,8 +1706,7 @@ static void wait_while_table_is_used(THD *thd,TABLE *table,
mysql_lock_abort(thd, table); // end threads waiting on lock
/* Wait until all there are no other threads that has this table open */
- while (remove_table_from_cache(thd,table->table_cache_key,
- table->real_name))
+ while (remove_table_from_cache(thd, table->s->db, table->s->table_name))
{
dropping_tables++;
(void) pthread_cond_wait(&COND_refresh,&LOCK_open);
@@ -1783,7 +1783,7 @@ static int prepare_for_restore(THD* thd, TABLE_LIST* table,
{
char* backup_dir= thd->lex->backup_dir;
char src_path[FN_REFLEN], dst_path[FN_REFLEN];
- char* table_name = table->real_name;
+ char* table_name = table->table_name;
char* db = thd->db ? thd->db : table->db;
if (fn_format_relative_to_data_home(src_path, table_name, backup_dir,
@@ -1844,7 +1844,7 @@ static int prepare_for_repair(THD* thd, TABLE_LIST *table_list,
{
char name[FN_REFLEN];
strxmov(name, mysql_data_home, "/", table_list->db, "/",
- table_list->real_name, NullS);
+ table_list->table_name, NullS);
if (openfrm(thd, name, "", 0, 0, 0, &tmp_table))
DBUG_RETURN(0); // Can't open frm file
table= &tmp_table;
@@ -1871,7 +1871,7 @@ static int prepare_for_repair(THD* thd, TABLE_LIST *table_list,
if (!ext[0] || !ext[1])
goto end; // No data file
- strxmov(from, table->path, ext[1], NullS); // Name of data file
+ strxmov(from, table->s->path, ext[1], NullS); // Name of data file
if (!my_stat(from, &stat_info, MYF(0)))
goto end; // Can't use USE_FRM flag
@@ -1979,7 +1979,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
char table_name[NAME_LEN*2+2];
char* db = (table->db) ? table->db : thd->db;
bool fatal_error=0;
- strxmov(table_name,db ? db : "",".",table->real_name,NullS);
+ strxmov(table_name,db ? db : "",".",table->table_name,NullS);
thd->open_options|= extra_open_options;
table->lock_type= lock_type;
@@ -2065,14 +2065,14 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
}
/* Close all instances of the table to allow repair to rename files */
- if (lock_type == TL_WRITE && table->table->version)
+ if (lock_type == TL_WRITE && table->table->s->version)
{
pthread_mutex_lock(&LOCK_open);
const char *old_message=thd->enter_cond(&COND_refresh, &LOCK_open,
"Waiting to get writelock");
mysql_lock_abort(thd,table->table);
- while (remove_table_from_cache(thd, table->table->table_cache_key,
- table->table->real_name) &&
+ while (remove_table_from_cache(thd, table->table->s->db,
+ table->table->s->table_name) &&
! thd->killed)
{
dropping_tables++;
@@ -2180,12 +2180,12 @@ send_result_message:
break;
}
if (fatal_error)
- table->table->version=0; // Force close of table
+ table->table->s->version=0; // Force close of table
else if (open_for_modify)
{
pthread_mutex_lock(&LOCK_open);
- remove_table_from_cache(thd, table->table->table_cache_key,
- table->table->real_name);
+ remove_table_from_cache(thd, table->table->s->db,
+ table->table->s->table_name);
pthread_mutex_unlock(&LOCK_open);
/* May be something modified consequently we have to invalidate cache */
query_cache_invalidate3(thd, table->table, 0);
@@ -2363,7 +2363,7 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table,
TABLE **tmp_table;
char src_path[FN_REFLEN], dst_path[FN_REFLEN];
char *db= table->db;
- char *table_name= table->real_name;
+ char *table_name= table->table_name;
char *src_db= thd->db;
char *src_table= table_ident->table.str;
int err;
@@ -2385,13 +2385,13 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table,
bzero((gptr)&src_tables_list, sizeof(src_tables_list));
src_tables_list.db= table_ident->db.str ? table_ident->db.str : thd->db;
- src_tables_list.real_name= table_ident->table.str;
+ src_tables_list.table_name= table_ident->table.str;
if (lock_and_wait_for_table_name(thd, &src_tables_list))
goto err;
if ((tmp_table= find_temporary_table(thd, src_db, src_table)))
- strxmov(src_path, (*tmp_table)->path, reg_ext, NullS);
+ strxmov(src_path, (*tmp_table)->s->path, reg_ext, NullS);
else
{
strxmov(src_path, mysql_data_home, "/", src_db, "/", src_table,
@@ -2669,7 +2669,7 @@ int mysql_create_indexes(THD *thd, TABLE_LIST *table_list, List<Key> &keys)
create_info.default_table_charset= thd->variables.collation_database;
/* Cleanup the fields list. We do not want to create existing fields. */
fields.delete_elements();
- if (real_alter_table(thd, table_list->db, table_list->real_name,
+ if (real_alter_table(thd, table_list->db, table_list->table_name,
&create_info, table_list, table,
fields, keys, drop, alter, 0, (ORDER*)0,
ALTER_ADD_INDEX, DUP_ERROR))
@@ -2681,7 +2681,7 @@ int mysql_create_indexes(THD *thd, TABLE_LIST *table_list, List<Key> &keys)
if (table->file->add_index(table, key_info_buffer, key_count)||
(my_snprintf(path, sizeof(path), "%s/%s/%s%s", mysql_data_home,
table_list->db, (lower_case_table_names == 2) ?
- table_list->alias: table_list->real_name, reg_ext) >=
+ table_list->alias: table_list->table_name, reg_ext) >=
(int) sizeof(path)) ||
! unpack_filename(path, path) ||
mysql_create_frm(thd, path, &create_info,
@@ -2766,7 +2766,7 @@ int mysql_drop_indexes(THD *thd, TABLE_LIST *table_list,
if ((drop_key)|| (drop.elements<= 0))
{
- if (real_alter_table(thd, table_list->db, table_list->real_name,
+ if (real_alter_table(thd, table_list->db, table_list->table_name,
&create_info, table_list, table,
fields, keys, drop, alter, 0, (ORDER*)0,
ALTER_DROP_INDEX, DUP_ERROR))
@@ -2783,7 +2783,7 @@ int mysql_drop_indexes(THD *thd, TABLE_LIST *table_list,
/*select_field_count*/ 0)||
(snprintf(path, sizeof(path), "%s/%s/%s%s", mysql_data_home,
table_list->db, (lower_case_table_names == 2)?
- table_list->alias: table_list->real_name, reg_ext)>=
+ table_list->alias: table_list->table_name, reg_ext)>=
(int)sizeof(path))||
! unpack_filename(path, path)||
mysql_create_frm(thd, path, &create_info,
@@ -2823,7 +2823,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
DBUG_ENTER("mysql_alter_table");
thd->proc_info="init";
- table_name=table_list->real_name;
+ table_name=table_list->table_name;
alias= (lower_case_table_names == 2) ? table_list->alias : table_name;
db=table_list->db;
@@ -2864,7 +2864,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
}
else
{
- if (table->tmp_table)
+ if (table->s->tmp_table)
{
if (find_temporary_table(thd,new_db,new_name_buff))
{
@@ -2892,9 +2892,9 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
new_name= table_name;
}
- old_db_type=table->db_type;
+ old_db_type= table->s->db_type;
if (create_info->db_type == DB_TYPE_DEFAULT)
- create_info->db_type=old_db_type;
+ create_info->db_type= old_db_type;
if ((new_db_type= ha_checktype(create_info->db_type)) !=
create_info->db_type)
{
@@ -2906,11 +2906,11 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
new_name);
}
if (create_info->row_type == ROW_TYPE_NOT_USED)
- create_info->row_type=table->row_type;
+ create_info->row_type= table->s->row_type;
thd->proc_info="setup";
if (!(alter_info->flags & ~(ALTER_RENAME | ALTER_KEYS_ONOFF)) &&
- !table->tmp_table) // no need to touch frm
+ !table->s->tmp_table) // no need to touch frm
{
error=0;
if (new_name != table_name || new_db != db)
@@ -2960,7 +2960,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
{
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA),
- table->table_name);
+ table->alias);
error=0;
}
if (!error)
@@ -2988,15 +2988,15 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
/* Let new create options override the old ones */
if (!(used_fields & HA_CREATE_USED_MIN_ROWS))
- create_info->min_rows=table->min_rows;
+ create_info->min_rows= table->s->min_rows;
if (!(used_fields & HA_CREATE_USED_MAX_ROWS))
- create_info->max_rows=table->max_rows;
+ create_info->max_rows= table->s->max_rows;
if (!(used_fields & HA_CREATE_USED_AVG_ROW_LENGTH))
- create_info->avg_row_length=table->avg_row_length;
+ create_info->avg_row_length= table->s->avg_row_length;
if (!(used_fields & HA_CREATE_USED_DEFAULT_CHARSET))
- create_info->default_table_charset= table->table_charset;
+ create_info->default_table_charset= table->s->table_charset;
- restore_record(table,default_values); // Empty record for DEFAULT
+ restore_record(table, s->default_values); // Empty record for DEFAULT
List_iterator<Alter_drop> drop_it(alter_info->drop_list);
List_iterator<create_field> def_it(fields);
List_iterator<Alter_column> alter_it(alter_info->alter_list);
@@ -3126,7 +3126,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
List<key_part_spec> key_parts;
KEY *key_info=table->key_info;
- for (uint i=0 ; i < table->keys ; i++,key_info++)
+ for (uint i=0 ; i < table->s->keys ; i++,key_info++)
{
char *key_name= key_info->name;
Alter_drop *drop;
@@ -3220,7 +3220,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
goto err;
}
- db_create_options=table->db_create_options & ~(HA_OPTION_PACK_RECORD);
+ db_create_options= table->s->db_create_options & ~(HA_OPTION_PACK_RECORD);
my_snprintf(tmp_name, sizeof(tmp_name), "%s-%lx_%lx", tmp_file_prefix,
current_pid, thd->thread_id);
/* Safety fix for innodb */
@@ -3228,7 +3228,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
my_casedn_str(files_charset_info, tmp_name);
create_info->db_type=new_db_type;
if (!create_info->comment)
- create_info->comment=table->comment;
+ create_info->comment= table->s->comment;
table->file->update_create_info(create_info);
if ((create_info->table_options &
@@ -3244,7 +3244,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
HA_OPTION_NO_DELAY_KEY_WRITE);
create_info->table_options|= db_create_options;
- if (table->tmp_table)
+ if (table->s->tmp_table)
create_info->options|=HA_LEX_CREATE_TMP_TABLE;
/*
@@ -3254,7 +3254,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
*/
need_copy_table=(alter_info->flags & ~(ALTER_CHANGE_COLUMN_DEFAULT|ALTER_OPTIONS) ||
create_info->used_fields & ~(HA_CREATE_USED_COMMENT|HA_CREATE_USED_PASSWORD) ||
- table->tmp_table);
+ table->s->tmp_table);
create_info->frm_only= !need_copy_table;
/*
@@ -3315,12 +3315,12 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
}
if (need_copy_table)
{
- if (table->tmp_table)
+ if (table->s->tmp_table)
{
TABLE_LIST tbl;
bzero((void*) &tbl, sizeof(tbl));
tbl.db= new_db;
- tbl.real_name= tbl.alias= tmp_name;
+ tbl.table_name= tbl.alias= tmp_name;
new_table= open_table(thd, &tbl, thd->mem_root, 0);
}
else
@@ -3344,7 +3344,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
thd->proc_info="copy to tmp table";
next_insert_id=thd->next_insert_id; // Remember for logging
copied=deleted=0;
- if (new_table && !new_table->is_view)
+ if (new_table && !new_table->s->is_view)
{
new_table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
new_table->next_number_field=new_table->found_next_number_field;
@@ -3355,7 +3355,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
thd->last_insert_id=next_insert_id; // Needed for correct log
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
- if (table->tmp_table)
+ if (table->s->tmp_table)
{
/* We changed a temporary table */
if (error)
@@ -3374,7 +3374,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
thd->lock=0;
}
/* Remove link to old table and rename the new one */
- close_temporary_table(thd,table->table_cache_key,table_name);
+ close_temporary_table(thd, table->s->db, table_name);
if (rename_temporary_table(thd, new_table, new_db, new_alias))
{ // Fatal error
close_temporary_table(thd,new_db,tmp_name);
@@ -3588,7 +3588,7 @@ copy_data_between_tables(TABLE *from,TABLE *to,
ulong save_sql_mode;
DBUG_ENTER("copy_data_between_tables");
- if (!(copy= new Copy_field[to->fields]))
+ if (!(copy= new Copy_field[to->s->fields]))
DBUG_RETURN(-1); /* purecov: inspected */
if (to->file->external_lock(thd, F_WRLCK))
@@ -3630,9 +3630,9 @@ copy_data_between_tables(TABLE *from,TABLE *to,
from->sort.io_cache=(IO_CACHE*) my_malloc(sizeof(IO_CACHE),
MYF(MY_FAE | MY_ZEROFILL));
bzero((char*) &tables,sizeof(tables));
- tables.table = from;
- tables.alias = tables.real_name= from->real_name;
- tables.db = from->table_cache_key;
+ tables.table= from;
+ tables.alias= tables.table_name= (char*) from->s->table_name;
+ tables.db= (char*) from->s->db;
error=1;
if (thd->lex->select_lex.setup_ref_array(thd, order_num) ||
@@ -3666,6 +3666,7 @@ copy_data_between_tables(TABLE *from,TABLE *to,
handle_duplicates == DUP_REPLACE)
to->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
thd->row_count= 0;
+ restore_record(to, s->default_values); // Create empty record
while (!(error=info.read_record(&info)))
{
if (thd->killed)
@@ -3791,7 +3792,7 @@ bool mysql_checksum_table(THD *thd, TABLE_LIST *tables, HA_CHECK_OPT *check_opt)
char table_name[NAME_LEN*2+2];
TABLE *t;
- strxmov(table_name, table->db ,".", table->real_name, NullS);
+ strxmov(table_name, table->db ,".", table->table_name, NullS);
t= table->table= open_ltable(thd, table, TL_READ_NO_INSERT);
thd->clear_error(); // these errors shouldn't get client
@@ -3836,7 +3837,7 @@ bool mysql_checksum_table(THD *thd, TABLE_LIST *tables, HA_CHECK_OPT *check_opt)
row_crc= my_checksum(row_crc, t->record[0],
((byte*) t->field[0]->ptr) - t->record[0]);
- for (uint i= 0; i < t->fields; i++ )
+ for (uint i= 0; i < t->s->fields; i++ )
{
Field *f= t->field[i];
if (f->type() == FIELD_TYPE_BLOB)
diff --git a/sql/sql_test.cc b/sql/sql_test.cc
index 6cffa9df2c6..2739fe865f7 100644
--- a/sql/sql_test.cc
+++ b/sql/sql_test.cc
@@ -79,7 +79,7 @@ void print_cached_tables(void)
{
TABLE *entry=(TABLE*) hash_element(&open_cache,idx);
printf("%-14.14s %-32s%6ld%8ld%10ld%6d %s\n",
- entry->table_cache_key,entry->real_name,entry->version,
+ entry->s->db, entry->s->table_name, entry->s->version,
entry->in_use ? entry->in_use->thread_id : 0L,
entry->in_use ? entry->in_use->dbug_thread_id : 0L,
entry->db_stat ? 1 : 0, entry->in_use ? lock_descriptions[(int)entry->reginfo.lock_type] : "Not in use");
@@ -131,7 +131,7 @@ void TEST_filesort(SORT_FIELD *sortorder,uint s_length)
{
if (sortorder->field->table_name)
{
- out.append(sortorder->field->table_name);
+ out.append(*sortorder->field->table_name);
out.append('.');
}
out.append(sortorder->field->field_name ? sortorder->field->field_name:
@@ -167,7 +167,7 @@ TEST_join(JOIN *join)
TABLE *form=tab->table;
char key_map_buff[128];
fprintf(DBUG_FILE,"%-16.16s type: %-7s q_keys: %s refs: %d key: %d len: %d\n",
- form->table_name,
+ form->alias,
join_type_str[tab->type],
tab->keys.print(key_map_buff),
tab->ref.key_parts,
@@ -261,7 +261,7 @@ print_plan(JOIN* join, double read_time, double record_count,
pos = join->positions[i];
table= pos.table->table;
if (table)
- fputs(table->real_name, DBUG_FILE);
+ fputs(table->s->table_name, DBUG_FILE);
fputc(' ', DBUG_FILE);
}
fputc('\n', DBUG_FILE);
@@ -278,7 +278,7 @@ print_plan(JOIN* join, double read_time, double record_count,
pos= join->best_positions[i];
table= pos.table->table;
if (table)
- fputs(table->real_name, DBUG_FILE);
+ fputs(table->s->table_name, DBUG_FILE);
fputc(' ', DBUG_FILE);
}
}
@@ -289,7 +289,7 @@ print_plan(JOIN* join, double read_time, double record_count,
for (plan_nodes= join->best_ref ; *plan_nodes ; plan_nodes++)
{
join_table= (*plan_nodes);
- fputs(join_table->table->real_name, DBUG_FILE);
+ fputs(join_table->table->s->table_name, DBUG_FILE);
fprintf(DBUG_FILE, "(%lu,%lu,%lu)",
(ulong) join_table->found_records,
(ulong) join_table->records,
@@ -332,12 +332,12 @@ static void push_locks_into_array(DYNAMIC_ARRAY *ar, THR_LOCK_DATA *data,
if (data)
{
TABLE *table=(TABLE *)data->debug_print_param;
- if (table && table->tmp_table == NO_TMP_TABLE)
+ if (table && table->s->tmp_table == NO_TMP_TABLE)
{
TABLE_LOCK_INFO table_lock_info;
- table_lock_info.thread_id=table->in_use->thread_id;
- memcpy(table_lock_info.table_name, table->table_cache_key,
- table->key_length);
+ table_lock_info.thread_id= table->in_use->thread_id;
+ memcpy(table_lock_info.table_name, table->s->table_cache_key,
+ table->s->key_length);
table_lock_info.table_name[strlen(table_lock_info.table_name)]='.';
table_lock_info.waiting=wait;
table_lock_info.lock_text=text;
diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc
index 96ede3fbe6b..5968d13efde 100644
--- a/sql/sql_trigger.cc
+++ b/sql/sql_trigger.cc
@@ -70,7 +70,7 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
Table_triggers_list::create_trigger() because we want to avoid messing
with table cash for views and temporary tables.
*/
- if (tables->view || table->tmp_table != NO_TMP_TABLE)
+ if (tables->view || table->s->tmp_table != NO_TMP_TABLE)
{
my_error(ER_TRG_ON_VIEW_OR_TEMP_TABLE, MYF(0), tables->alias);
DBUG_RETURN(TRUE);
@@ -188,7 +188,7 @@ bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables)
strxnmov(dir_buff, FN_REFLEN, mysql_data_home, "/", tables->db, "/", NullS);
dir.length= unpack_filename(dir_buff, dir_buff);
dir.str= dir_buff;
- file.length= strxnmov(file_buff, FN_REFLEN, tables->real_name,
+ file.length= strxnmov(file_buff, FN_REFLEN, tables->table_name,
triggers_file_ext, NullS) - file_buff;
file.str= file_buff;
@@ -257,7 +257,7 @@ bool Table_triggers_list::drop_trigger(THD *thd, TABLE_LIST *tables)
elsewhere).
*/
strxnmov(path, FN_REFLEN, mysql_data_home, "/", tables->db, "/",
- tables->real_name, triggers_file_ext, NullS);
+ tables->table_name, triggers_file_ext, NullS);
unpack_filename(path, path);
return my_delete(path, MYF(MY_WME));
}
@@ -270,7 +270,7 @@ bool Table_triggers_list::drop_trigger(THD *thd, TABLE_LIST *tables)
"/", NullS);
dir.length= unpack_filename(dir_buff, dir_buff);
dir.str= dir_buff;
- file.length= strxnmov(file_buff, FN_REFLEN, tables->real_name,
+ file.length= strxnmov(file_buff, FN_REFLEN, tables->table_name,
triggers_file_ext, NullS) - file_buff;
file.str= file_buff;
@@ -315,7 +315,7 @@ bool Table_triggers_list::prepare_old_row_accessors(TABLE *table)
Field **fld, **old_fld;
if (!(old_field= (Field **)alloc_root(&table->mem_root,
- (table->fields + 1) *
+ (table->s->fields + 1) *
sizeof(Field*))))
return 1;
diff --git a/sql/sql_udf.cc b/sql/sql_udf.cc
index 7fd81f22e66..ec47fb055e2 100644
--- a/sql/sql_udf.cc
+++ b/sql/sql_udf.cc
@@ -146,7 +146,7 @@ void udf_init()
new_thd->db_length=5;
bzero((gptr) &tables,sizeof(tables));
- tables.alias= tables.real_name= (char*) "func";
+ tables.alias= tables.table_name= (char*) "func";
tables.lock_type = TL_READ;
tables.db=new_thd->db;
@@ -168,7 +168,7 @@ void udf_init()
char *dl_name= get_field(&mem, table->field[2]);
bool new_dl=0;
Item_udftype udftype=UDFTYPE_FUNCTION;
- if (table->fields >= 4) // New func table
+ if (table->s->fields >= 4) // New func table
udftype=(Item_udftype) table->field[3]->val_int();
if (!(tmp = add_udf(&name,(Item_result) table->field[1]->val_int(),
@@ -429,16 +429,16 @@ int mysql_create_function(THD *thd,udf_func *udf)
bzero((char*) &tables,sizeof(tables));
tables.db= (char*) "mysql";
- tables.real_name= tables.alias= (char*) "func";
+ tables.table_name= tables.alias= (char*) "func";
/* Allow creation of functions even if we can't open func table */
if (!(table = open_ltable(thd,&tables,TL_WRITE)))
goto err;
- restore_record(table,default_values); // Default values for fields
+ restore_record(table, s->default_values); // Default values for fields
table->field[0]->store(u_d->name.str, u_d->name.length, system_charset_info);
table->field[1]->store((longlong) u_d->returns);
table->field[2]->store(u_d->dl,(uint) strlen(u_d->dl), system_charset_info);
- if (table->fields >= 4) // If not old func format
+ if (table->s->fields >= 4) // If not old func format
table->field[3]->store((longlong) u_d->type);
error = table->file->write_row(table->record[0]);
@@ -488,7 +488,7 @@ int mysql_drop_function(THD *thd,const LEX_STRING *udf_name)
bzero((char*) &tables,sizeof(tables));
tables.db=(char*) "mysql";
- tables.real_name= tables.alias= (char*) "func";
+ tables.table_name= tables.alias= (char*) "func";
if (!(table = open_ltable(thd,&tables,TL_WRITE)))
goto err;
if (!table->file->index_read_idx(table->record[0],0,(byte*) udf_name->str,
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index 901cb0ba496..ce84be47243 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -313,7 +313,7 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
bzero((char*) &result_table_list, sizeof(result_table_list));
result_table_list.db= (char*) "";
- result_table_list.real_name= result_table_list.alias= (char*) "union";
+ result_table_list.table_name= result_table_list.alias= (char*) "union";
result_table_list.table= table;
union_result->set_table(table);
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index 5ca25bbac3e..3908c4a7456 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -31,18 +31,18 @@ static bool safe_update_on_fly(JOIN_TAB *join_tab, List<Item> *fields);
static bool compare_record(TABLE *table, ulong query_id)
{
- if (!table->blob_fields)
+ if (!table->s->blob_fields)
return cmp_record(table,record[1]);
/* Compare null bits */
if (memcmp(table->null_flags,
- table->null_flags+table->rec_buff_length,
- table->null_bytes))
+ table->null_flags+table->s->rec_buff_length,
+ table->s->null_bytes))
return TRUE; // Diff in NULL value
/* Compare updated fields */
for (Field **ptr=table->field ; *ptr ; ptr++)
{
if ((*ptr)->query_id == query_id &&
- (*ptr)->cmp_binary_offset(table->rec_buff_length))
+ (*ptr)->cmp_binary_offset(table->s->rec_buff_length))
return TRUE;
}
return FALSE;
@@ -166,7 +166,7 @@ int mysql_update(THD *thd,
table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
/* Calculate "table->used_keys" based on the WHERE */
- table->used_keys=table->keys_in_use;
+ table->used_keys= table->s->keys_in_use;
table->quick_keys.clear_all();
#ifndef NO_EMBEDDED_ACCESS_CHECKS
@@ -471,7 +471,7 @@ int mysql_update(THD *thd,
query_cache_invalidate3(thd, table_list, 1);
}
- log_delayed= (transactional_table || table->tmp_table);
+ log_delayed= (transactional_table || table->s->tmp_table);
if ((updated || (error < 0)) && (error <= 0 || !transactional_table))
{
if (mysql_bin_log.is_open())
@@ -572,7 +572,7 @@ bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list,
/* Check that we are not using table that we are updating in a sub select */
if (unique_table(table_list, table_list->next_global))
{
- my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->real_name);
+ my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->table_name);
DBUG_RETURN(TRUE);
}
select_lex->fix_prepare_information(thd, conds);
@@ -698,9 +698,9 @@ bool mysql_multi_update_prepare(THD *thd)
single SELECT on top and have to check underlying SELECTs of it
*/
if (lex->select_lex.check_updateable_in_subqueries(tl->db,
- tl->real_name))
+ tl->table_name))
{
- my_error(ER_UPDATE_TABLE_USED, MYF(0), tl->real_name);
+ my_error(ER_UPDATE_TABLE_USED, MYF(0), tl->table_name);
DBUG_RETURN(TRUE);
}
DBUG_PRINT("info",("setting table `%s` for update", tl->alias));
@@ -924,7 +924,7 @@ int multi_update::prepare(List<Item> &not_used_values,
table_count= update.elements;
update_tables= (TABLE_LIST*) update.first;
- tmp_tables = (TABLE **) thd->calloc(sizeof(TABLE *) * table_count);
+ tmp_tables = (TABLE**) thd->calloc(sizeof(TABLE *) * table_count);
tmp_table_param = (TMP_TABLE_PARAM*) thd->calloc(sizeof(TMP_TABLE_PARAM) *
table_count);
fields_for_table= (List_item **) thd->alloc(sizeof(List_item *) *
@@ -976,7 +976,7 @@ int multi_update::prepare(List<Item> &not_used_values,
TABLE *table=table_ref->table;
if (!(tables_to_update & table->map) &&
find_table_in_local_list(update_tables, table_ref->db,
- table_ref->real_name))
+ table_ref->table_name))
table->no_cache= 1; // Disable row cache
}
DBUG_RETURN(thd->is_fatal_error != 0);
@@ -1002,7 +1002,7 @@ multi_update::initialize_tables(JOIN *join)
DBUG_RETURN(1);
main_table=join->join_tab->table;
trans_safe= transactional_tables= main_table->file->has_transactions();
- log_delayed= trans_safe || main_table->tmp_table != NO_TMP_TABLE;
+ log_delayed= trans_safe || main_table->s->tmp_table != NO_TMP_TABLE;
table_to_update= 0;
/* Create a temporary table for keys to all tables, except main table */
@@ -1105,8 +1105,8 @@ static bool safe_update_on_fly(JOIN_TAB *join_tab, List<Item> *fields)
return !join_tab->quick->check_if_keys_used(fields);
/* If scanning in clustered key */
if ((table->file->table_flags() & HA_PRIMARY_KEY_IN_READ_INDEX) &&
- table->primary_key < MAX_KEY)
- return !check_if_key_used(table, table->primary_key, *fields);
+ table->s->primary_key < MAX_KEY)
+ return !check_if_key_used(table, table->s->primary_key, *fields);
return TRUE;
default:
break; // Avoid compler warning
@@ -1337,14 +1337,14 @@ int multi_update::do_updates(bool from_send_error)
goto err;
}
updated++;
- if (table->tmp_table != NO_TMP_TABLE)
+ if (table->s->tmp_table != NO_TMP_TABLE)
log_delayed= 1;
}
}
if (updated != org_updated)
{
- if (table->tmp_table != NO_TMP_TABLE)
+ if (table->s->tmp_table != NO_TMP_TABLE)
log_delayed= 1; // Tmp tables forces delay log
if (table->file->has_transactions())
log_delayed= transactional_tables= 1;
@@ -1368,7 +1368,7 @@ err:
if (updated != org_updated)
{
- if (table->tmp_table != NO_TMP_TABLE)
+ if (table->s->tmp_table != NO_TMP_TABLE)
log_delayed= 1;
if (table->file->has_transactions())
log_delayed= transactional_tables= 1;
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index bafb57c44b0..6680ea95561 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -118,7 +118,7 @@ bool mysql_create_view(THD *thd,
if (check_some_access(thd, VIEW_ANY_ACL, tbl))
{
my_error(ER_TABLEACCESS_DENIED_ERROR, MYF(0),
- "ANY", thd->priv_user, thd->host_or_ip, tbl->real_name);
+ "ANY", thd->priv_user, thd->host_or_ip, tbl->table_name);
DBUG_RETURN(TRUE);
}
/*
@@ -136,11 +136,11 @@ bool mysql_create_view(THD *thd,
/*
Make sure that all rights are loaded to the TABLE::grant field.
- tbl->real_name will be correct name of table because VIEWs are
+ tbl->table_name will be correct name of table because VIEWs are
not opened yet.
*/
fill_effective_table_privileges(thd, &tbl->grant, tbl->db,
- tbl->real_name);
+ tbl->table_name);
}
}
@@ -187,7 +187,7 @@ bool mysql_create_view(THD *thd,
for (tbl= tables; tbl; tbl= tbl->next_global)
{
/* is this table temporary and is not view? */
- if (tbl->table->tmp_table != NO_TMP_TABLE && !tbl->view &&
+ if (tbl->table->s->tmp_table != NO_TMP_TABLE && !tbl->view &&
!tbl->schema_table)
{
my_error(ER_VIEW_SELECT_TMPTABLE, MYF(0), tbl->alias);
@@ -198,7 +198,7 @@ bool mysql_create_view(THD *thd,
/* is this table view and the same view which we creates now? */
if (tbl->view &&
strcmp(tbl->view_db.str, view->db) == 0 &&
- strcmp(tbl->view_name.str, view->real_name) == 0)
+ strcmp(tbl->view_name.str, view->table_name) == 0)
{
my_error(ER_NO_SUCH_TABLE, MYF(0), tbl->view_db.str, tbl->view_name.str);
res= TRUE;
@@ -272,24 +272,24 @@ bool mysql_create_view(THD *thd,
List_iterator_fast<Item> it(sl->item_list);
Item *item;
fill_effective_table_privileges(thd, &view->grant, db,
- view->real_name);
+ view->table_name);
while ((item= it++))
{
Item_field *fld;
uint priv= (get_column_grant(thd, &view->grant, db,
- view->real_name, item->name) &
+ view->table_name, item->name) &
VIEW_ANY_ACL);
if ((fld= item->filed_for_view_update()))
{
/*
Do we have more privileges on view field then underlying table field?
*/
- if (!fld->field->table->tmp_table && (~fld->have_privileges & priv))
+ if (!fld->field->table->s->tmp_table && (~fld->have_privileges & priv))
{
/* VIEW column has more privileges */
my_error(ER_COLUMNACCESS_DENIED_ERROR, MYF(0),
"create view", thd->priv_user, thd->host_or_ip, item->name,
- view->real_name);
+ view->table_name);
DBUG_RETURN(TRUE);
}
}
@@ -404,7 +404,7 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view,
dir.length= strlen(dir_buff);
file.str= file_buff;
- file.length= (strxnmov(file_buff, FN_REFLEN, view->real_name, reg_ext,
+ file.length= (strxnmov(file_buff, FN_REFLEN, view->table_name, reg_ext,
NullS) - file_buff);
/* init timestamp */
if (!view->timestamp.str)
@@ -435,7 +435,7 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view,
strncmp("VIEW", parser->type()->str, parser->type()->length))
{
my_error(ER_WRONG_OBJECT, MYF(0),
- (view->db ? view->db : thd->db), view->real_name, "VIEW");
+ (view->db ? view->db : thd->db), view->table_name, "VIEW");
DBUG_RETURN(-1);
}
@@ -518,7 +518,7 @@ loop_out:
!((TABLE_LIST*)lex->select_lex.table_list.first)->next_local &&
find_table_in_global_list(lex->query_tables->next_global,
lex->query_tables->db,
- lex->query_tables->real_name))
+ lex->query_tables->table_name))
{
view->updatable_view= 0;
}
@@ -526,7 +526,7 @@ loop_out:
if (view->with_check != VIEW_CHECK_NONE &&
!view->updatable_view)
{
- my_error(ER_VIEW_NONUPD_CHECK, MYF(0), view->db, view->real_name);
+ my_error(ER_VIEW_NONUPD_CHECK, MYF(0), view->db, view->table_name);
DBUG_RETURN(-1);
}
@@ -598,8 +598,8 @@ mysql_make_view(File_parser *parser, TABLE_LIST *table)
*/
table->view_db.str= table->db;
table->view_db.length= table->db_length;
- table->view_name.str= table->real_name;
- table->view_name.length= table->real_name_length;
+ table->view_name.str= table->table_name;
+ table->view_name.length= table->table_name_length;
/*TODO: md5 test here and warning if it is differ */
@@ -669,8 +669,8 @@ mysql_make_view(File_parser *parser, TABLE_LIST *table)
TABLE_LIST *table= old_lex->proc_table;
table->db= (char*)"mysql";
table->db_length= 5;
- table->real_name= table->alias= (char*)"proc";
- table->real_name_length= 4;
+ table->table_name= table->alias= (char*)"proc";
+ table->table_name_length= 4;
table->cacheable_table= 1;
old_lex->add_to_query_tables(table);
}
@@ -889,13 +889,13 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
for (view= views; view; view= view->next_local)
{
strxnmov(path, FN_REFLEN, mysql_data_home, "/", view->db, "/",
- view->real_name, reg_ext, NullS);
+ view->table_name, reg_ext, NullS);
(void) unpack_filename(path, path);
VOID(pthread_mutex_lock(&LOCK_open));
if (access(path, F_OK) || (type= (mysql_frm_type(path) != FRMTYPE_VIEW)))
{
char name[FN_REFLEN];
- my_snprintf(name, sizeof(name), "%s.%s", view->db, view->real_name);
+ my_snprintf(name, sizeof(name), "%s.%s", view->db, view->table_name);
if (thd->lex->drop_if_exists)
{
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
@@ -905,7 +905,7 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
continue;
}
if (type)
- my_error(ER_WRONG_OBJECT, MYF(0), view->db, view->real_name, "VIEW");
+ my_error(ER_WRONG_OBJECT, MYF(0), view->db, view->table_name, "VIEW");
else
my_error(ER_BAD_TABLE_ERROR, MYF(0), name);
goto err;
@@ -998,7 +998,7 @@ bool check_key_in_view(THD *thd, TABLE_LIST *view)
if (view->belong_to_view)
view= view->belong_to_view;
trans= view->field_translation;
- key_info_end= (key_info= table->key_info)+ table->keys;
+ key_info_end= (key_info= table->key_info)+ table->s->keys;
elements_in_view= view->view->select_lex.item_list.elements;
DBUG_ASSERT(table != 0 && view->field_translation != 0);
diff --git a/sql/table.cc b/sql/table.cc
index e9b89d6b124..b8d4d3fea94 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -85,27 +85,29 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat,
uint null_bit_pos, new_frm_ver, field_pack_length;
SQL_CRYPT *crypted=0;
MEM_ROOT **root_ptr, *old_root;
+ TABLE_SHARE *share;
DBUG_ENTER("openfrm");
DBUG_PRINT("enter",("name: '%s' form: 0x%lx",name,outparam));
- error=1;
- disk_buff=NULL;
+ error= 1;
+ disk_buff= NULL;
root_ptr= my_pthread_getspecific_ptr(MEM_ROOT**, THR_MALLOC);
old_root= *root_ptr;
+ bzero((char*) outparam,sizeof(*outparam));
+ outparam->in_use= thd;
+ outparam->s= share= &outparam->share_not_to_be_used;
+
if ((file=my_open(fn_format(index_file, name, "", reg_ext,
MY_UNPACK_FILENAME),
O_RDONLY | O_SHARE,
MYF(0)))
< 0)
- {
goto err_w_init;
- }
+ error= 4;
if (my_read(file,(byte*) head,64,MYF(MY_NABP)))
- {
goto err_w_init;
- }
if (memcmp(head, "TYPE=", 5) == 0)
{
@@ -116,28 +118,22 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat,
DBUG_RETURN(5);
// caller can't process new .frm
- error= 4;
goto err_w_init;
}
- bzero((char*) outparam,sizeof(*outparam));
- outparam->in_use= thd;
- outparam->blob_ptr_size=sizeof(char*);
- outparam->db_stat = db_stat;
+ share->blob_ptr_size= sizeof(char*);
+ outparam->db_stat= db_stat;
init_sql_alloc(&outparam->mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
*root_ptr= &outparam->mem_root;
- outparam->real_name=strdup_root(&outparam->mem_root,
- name+dirname_length(name));
- *fn_ext(outparam->real_name)='\0'; // Remove extension
- outparam->table_name=my_strdup(alias,MYF(MY_WME));
- if (!outparam->real_name || !outparam->table_name)
- goto err_end;
-
- error=4;
- if (!(outparam->path= strdup_root(&outparam->mem_root,name)))
+ share->table_name= strdup_root(&outparam->mem_root,
+ name+dirname_length(name));
+ share->path= strdup_root(&outparam->mem_root, name);
+ outparam->alias= my_strdup(alias, MYF(MY_WME));
+ if (!share->table_name || !share->path || !outparam->alias)
goto err_not_open;
- *fn_ext(outparam->path)='\0'; // Remove extension
+ *fn_ext(share->table_name)='\0'; // Remove extension
+ *fn_ext(share->path)='\0'; // Remove extension
if (head[0] != (uchar) 254 || head[1] != 1 ||
(head[2] != FRM_VER && head[2] != FRM_VER+1 &&
@@ -152,31 +148,34 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat,
goto err_not_open; /* purecov: inspected */
*fn_ext(index_file)='\0'; // Remove .frm extension
- outparam->frm_version= head[2];
- outparam->db_type=ha_checktype((enum db_type) (uint) *(head+3));
- outparam->db_create_options=db_create_options=uint2korr(head+30);
- outparam->db_options_in_use=outparam->db_create_options;
- null_field_first=0;
+ share->frm_version= head[2];
+ share->db_type= ha_checktype((enum db_type) (uint) *(head+3));
+ share->db_create_options= db_create_options=uint2korr(head+30);
+ share->db_options_in_use= share->db_create_options;
+ null_field_first= 0;
if (!head[32]) // New frm file in 3.23
{
- outparam->avg_row_length=uint4korr(head+34);
- outparam->row_type=(row_type) head[40];
- outparam->raid_type= head[41];
- outparam->raid_chunks= head[42];
- outparam->raid_chunksize= uint4korr(head+43);
- outparam->table_charset=get_charset((uint) head[38],MYF(0));
- null_field_first=1;
+ share->avg_row_length= uint4korr(head+34);
+ share-> row_type= (row_type) head[40];
+ share->raid_type= head[41];
+ share->raid_chunks= head[42];
+ share->raid_chunksize= uint4korr(head+43);
+ share->table_charset= get_charset((uint) head[38],MYF(0));
+ null_field_first= 1;
+ }
+ if (!share->table_charset)
+ {
+ /* unknown charset in head[38] or pre-3.23 frm */
+ share->table_charset= default_charset_info;
}
- if (!outparam->table_charset) /* unknown charset in head[38] or pre-3.23 frm */
- outparam->table_charset=default_charset_info;
- outparam->db_record_offset=1;
+ share->db_record_offset= 1;
if (db_create_options & HA_OPTION_LONG_BLOB_PTR)
- outparam->blob_ptr_size=portable_sizeof_char_ptr;
+ share->blob_ptr_size= portable_sizeof_char_ptr;
/* Set temporarily a good value for db_low_byte_first */
- outparam->db_low_byte_first=test(outparam->db_type != DB_TYPE_ISAM);
+ share->db_low_byte_first= test(share->db_type != DB_TYPE_ISAM);
error=4;
- outparam->max_rows=uint4korr(head+18);
- outparam->min_rows=uint4korr(head+22);
+ share->max_rows= uint4korr(head+18);
+ share->min_rows= uint4korr(head+22);
/* Read keyinformation */
key_info_length= (uint) uint2korr(head+28);
@@ -185,17 +184,16 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat,
goto err_not_open; /* purecov: inspected */
if (disk_buff[0] & 0x80)
{
- outparam->keys= keys= (disk_buff[1] << 7) | (disk_buff[0] & 0x7f);
- outparam->key_parts= key_parts= uint2korr(disk_buff+2);
+ share->keys= keys= (disk_buff[1] << 7) | (disk_buff[0] & 0x7f);
+ share->key_parts= key_parts= uint2korr(disk_buff+2);
}
else
{
- outparam->keys= keys= disk_buff[0];
- outparam->key_parts= key_parts= disk_buff[1];
+ share->keys= keys= disk_buff[0];
+ share->key_parts= key_parts= disk_buff[1];
}
- outparam->keys_for_keyread.init(0);
- outparam->keys_in_use.init(keys);
- outparam->read_only_keys.init(keys);
+ share->keys_for_keyread.init(0);
+ share->keys_in_use.init(keys);
outparam->quick_keys.init();
outparam->used_keys.init();
outparam->keys_in_use_for_query.init();
@@ -206,7 +204,6 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat,
goto err_not_open; /* purecov: inspected */
bzero((char*) keyinfo,n_length);
outparam->key_info=keyinfo;
- outparam->max_key_length= outparam->total_key_length= 0;
key_part= my_reinterpret_cast(KEY_PART_INFO*) (keyinfo+keys);
strpos=disk_buff+6;
@@ -267,9 +264,9 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat,
keynames=(char*) key_part;
strpos+= (strmov(keynames, (char *) strpos) - keynames)+1;
- outparam->reclength = uint2korr((head+16));
+ share->reclength = uint2korr((head+16));
if (*(head+26) == 1)
- outparam->system=1; /* one-record-database */
+ share->system= 1; /* one-record-database */
#ifdef HAVE_CRYPTED_FRM
else if (*(head+26) == 2)
{
@@ -281,45 +278,37 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat,
#endif
/* Allocate handler */
- if (!(outparam->file= get_new_handler(outparam,outparam->db_type)))
+ if (!(outparam->file= get_new_handler(outparam, share->db_type)))
goto err_not_open;
error=4;
outparam->reginfo.lock_type= TL_UNLOCK;
outparam->current_lock=F_UNLCK;
- if ((db_stat & HA_OPEN_KEYFILE) || (prgflag & DELAYED_OPEN)) records=2;
- else records=1;
+ if ((db_stat & HA_OPEN_KEYFILE) || (prgflag & DELAYED_OPEN))
+ records=2;
+ else
+ records=1;
if (prgflag & (READ_ALL+EXTRA_RECORD)) records++;
/* QQ: TODO, remove the +1 from below */
- rec_buff_length=ALIGN_SIZE(outparam->reclength+1+
- outparam->file->extra_rec_buf_length());
- if (!(outparam->record[0]= (byte*)
- (record = (char *) alloc_root(&outparam->mem_root,
- rec_buff_length * records))))
+ rec_buff_length= ALIGN_SIZE(share->reclength + 1 +
+ outparam->file->extra_rec_buf_length());
+ share->rec_buff_length= rec_buff_length;
+ if (!(record= (char *) alloc_root(&outparam->mem_root,
+ rec_buff_length * records)))
goto err_not_open; /* purecov: inspected */
- record[outparam->reclength]=0; // For purify and ->c_ptr()
- outparam->rec_buff_length=rec_buff_length;
- if (my_pread(file,(byte*) record,(uint) outparam->reclength,
+ share->default_values= record;
+ if (my_pread(file,(byte*) record, (uint) share->reclength,
(ulong) (uint2korr(head+6)+
((uint2korr(head+14) == 0xffff ?
uint4korr(head+47) : uint2korr(head+14)))),
MYF(MY_NABP)))
goto err_not_open; /* purecov: inspected */
- /* HACK: table->record[2] is used instead of table->default_values here */
- for (i=0 ; i < records ; i++, record+=rec_buff_length)
- {
- outparam->record[i]=(byte*) record;
- if (i)
- memcpy(record,record-rec_buff_length,(uint) outparam->reclength);
- }
- if (records == 2)
- { /* fix for select */
- outparam->default_values=outparam->record[1];
- if (db_stat & HA_READ_ONLY)
- outparam->record[1]=outparam->record[0]; /* purecov: inspected */
- }
- outparam->insert_values=0; /* for INSERT ... UPDATE */
+ outparam->record[0]= record+ rec_buff_length;
+ if (records > 2)
+ outparam->record[1]= record+ rec_buff_length*2;
+ else
+ outparam->record[1]= outparam->record[0]; // Safety
VOID(my_seek(file,pos,MY_SEEK_SET,MYF(0)));
if (my_read(file,(byte*) head,288,MYF(MY_NABP))) goto err_not_open;
@@ -330,30 +319,29 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat,
goto err_not_open; // Wrong password
}
- outparam->fields= uint2korr(head+258);
- pos=uint2korr(head+260); /* Length of all screens */
- n_length=uint2korr(head+268);
- interval_count=uint2korr(head+270);
- interval_parts=uint2korr(head+272);
- int_length=uint2korr(head+274);
- outparam->null_fields=uint2korr(head+282);
- com_length=uint2korr(head+284);
- outparam->comment=strdup_root(&outparam->mem_root,
- (char*) head+47);
+ share->fields= uint2korr(head+258);
+ pos= uint2korr(head+260); /* Length of all screens */
+ n_length= uint2korr(head+268);
+ interval_count= uint2korr(head+270);
+ interval_parts= uint2korr(head+272);
+ int_length= uint2korr(head+274);
+ share->null_fields= uint2korr(head+282);
+ com_length= uint2korr(head+284);
+ share->comment= strdup_root(&outparam->mem_root, (char*) head+47);
- DBUG_PRINT("info",("i_count: %d i_parts: %d index: %d n_length: %d int_length: %d com_length: %d", interval_count,interval_parts, outparam->keys,n_length,int_length, com_length));
+ DBUG_PRINT("info",("i_count: %d i_parts: %d index: %d n_length: %d int_length: %d com_length: %d", interval_count,interval_parts, share->keys,n_length,int_length, com_length));
if (!(field_ptr = (Field **)
alloc_root(&outparam->mem_root,
- (uint) ((outparam->fields+1)*sizeof(Field*)+
+ (uint) ((share->fields+1)*sizeof(Field*)+
interval_count*sizeof(TYPELIB)+
- (outparam->fields+interval_parts+
+ (share->fields+interval_parts+
keys+3)*sizeof(my_string)+
(n_length+int_length+com_length)))))
goto err_not_open; /* purecov: inspected */
outparam->field=field_ptr;
- read_length=(uint) (outparam->fields * field_pack_length +
+ read_length=(uint) (share->fields * field_pack_length +
pos+ (uint) (n_length+int_length+com_length));
if (read_string(file,(gptr*) &disk_buff,read_length))
goto err_not_open; /* purecov: inspected */
@@ -365,25 +353,25 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat,
}
strpos= disk_buff+pos;
- outparam->intervals= (TYPELIB*) (field_ptr+outparam->fields+1);
- int_array= (const char **) (outparam->intervals+interval_count);
- names= (char*) (int_array+outparam->fields+interval_parts+keys+3);
+ share->intervals= (TYPELIB*) (field_ptr+share->fields+1);
+ int_array= (const char **) (share->intervals+interval_count);
+ names= (char*) (int_array+share->fields+interval_parts+keys+3);
if (!interval_count)
- outparam->intervals=0; // For better debugging
- memcpy((char*) names, strpos+(outparam->fields*field_pack_length),
+ share->intervals= 0; // For better debugging
+ memcpy((char*) names, strpos+(share->fields*field_pack_length),
(uint) (n_length+int_length));
- comment_pos=names+(n_length+int_length);
+ comment_pos= names+(n_length+int_length);
memcpy(comment_pos, disk_buff+read_length-com_length, com_length);
- fix_type_pointers(&int_array,&outparam->fieldnames,1,&names);
- fix_type_pointers(&int_array,outparam->intervals,interval_count,
+ fix_type_pointers(&int_array, &share->fieldnames, 1, &names);
+ fix_type_pointers(&int_array, share->intervals, interval_count,
&names);
{
/* Set ENUM and SET lengths */
TYPELIB *interval;
- for (interval= outparam->intervals;
- interval < outparam->intervals + interval_count;
+ for (interval= share->intervals;
+ interval < share->intervals + interval_count;
interval++)
{
uint count= (uint) (interval->count + 1) * sizeof(uint);
@@ -397,33 +385,33 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat,
}
if (keynames)
- fix_type_pointers(&int_array,&outparam->keynames,1,&keynames);
+ fix_type_pointers(&int_array, &share->keynames, 1, &keynames);
VOID(my_close(file,MYF(MY_WME)));
file= -1;
- record=(char*) outparam->record[0]-1; /* Fieldstart = 1 */
+ record= (char*) outparam->record[0]-1; /* Fieldstart = 1 */
if (null_field_first)
{
outparam->null_flags=null_pos=(uchar*) record+1;
null_bit_pos= (db_create_options & HA_OPTION_PACK_RECORD) ? 0 : 1;
- outparam->null_bytes= (outparam->null_fields + null_bit_pos + 7) / 8;
+ share->null_bytes= (share->null_fields + null_bit_pos + 7) / 8;
}
else
{
- outparam->null_bytes=(outparam->null_fields+7)/8;
- outparam->null_flags=null_pos=
- (uchar*) (record+1+outparam->reclength-outparam->null_bytes);
+ share->null_bytes= (share->null_fields+7)/8;
+ outparam->null_flags= null_pos=
+ (uchar*) (record+1+share->reclength-share->null_bytes);
null_bit_pos= 0;
}
- use_hash= outparam->fields >= MAX_FIELDS_BEFORE_HASH;
+ use_hash= share->fields >= MAX_FIELDS_BEFORE_HASH;
if (use_hash)
- use_hash= !hash_init(&outparam->name_hash,
+ use_hash= !hash_init(&share->name_hash,
system_charset_info,
- outparam->fields,0,0,
+ share->fields,0,0,
(hash_get_key) get_field_name,0,0);
- for (i=0 ; i < outparam->fields; i++, strpos+=field_pack_length, field_ptr++)
+ for (i=0 ; i < share->fields; i++, strpos+=field_pack_length, field_ptr++)
{
uint pack_flag, interval_nr, unireg_type, recpos, field_length;
enum_field_types field_type;
@@ -498,7 +486,7 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat,
if (!f_is_blob(pack_flag))
{
// 3.23 or 4.0 string
- if (!(charset= get_charset_by_csname(outparam->table_charset->csname,
+ if (!(charset= get_charset_by_csname(share->table_charset->csname,
MY_CS_BINSORT, MYF(0))))
charset= &my_charset_bin;
}
@@ -506,14 +494,14 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat,
charset= &my_charset_bin;
}
else
- charset= outparam->table_charset;
+ charset= share->table_charset;
bzero((char*) &comment, sizeof(comment));
}
if (interval_nr && charset->mbminlen > 1)
{
/* Unescape UCS2 intervals from HEX notation */
- TYPELIB *interval= outparam->intervals + interval_nr - 1;
+ TYPELIB *interval= share->intervals + interval_nr - 1;
unhex_type2(interval);
}
@@ -527,9 +515,9 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat,
geom_type,
(Field::utype) MTYP_TYPENR(unireg_type),
(interval_nr ?
- outparam->intervals+interval_nr-1 :
+ share->intervals+interval_nr-1 :
(TYPELIB*) 0),
- outparam->fieldnames.type_names[i],
+ share->fieldnames.type_names[i],
outparam);
if (!reg_field) // Not supported field type
{
@@ -555,9 +543,9 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat,
if (reg_field->unireg_check == Field::NEXT_NUMBER)
outparam->found_next_number_field= reg_field;
if (outparam->timestamp_field == reg_field)
- outparam->timestamp_field_offset=i;
+ share->timestamp_field_offset= i;
if (use_hash)
- (void) my_hash_insert(&outparam->name_hash,(byte*) field_ptr); // Will never fail
+ (void) my_hash_insert(&share->name_hash,(byte*) field_ptr); // never fail
}
*field_ptr=0; // End marker
@@ -565,15 +553,15 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat,
if (key_parts)
{
uint primary_key=(uint) (find_type((char*) primary_key_name,
- &outparam->keynames, 3) - 1);
+ &share->keynames, 3) - 1);
uint ha_option=outparam->file->table_flags();
keyinfo=outparam->key_info;
key_part=keyinfo->key_part;
- for (uint key=0 ; key < outparam->keys ; key++,keyinfo++)
+ for (uint key=0 ; key < share->keys ; key++,keyinfo++)
{
uint usable_parts=0;
- keyinfo->name=(char*) outparam->keynames.type_names[key];
+ keyinfo->name=(char*) share->keynames.type_names[key];
/* Fix fulltext keys for old .frm files */
if (outparam->key_info[key].flags & HA_FULLTEXT)
outparam->key_info[key].algorithm= HA_KEY_ALG_FULLTEXT;
@@ -606,7 +594,7 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat,
(uint) key_part->offset,
(uint) key_part->length);
#ifdef EXTRA_DEBUG
- if (key_part->fieldnr > outparam->fields)
+ if (key_part->fieldnr > share->fields)
goto err_not_open; // sanity check
#endif
if (key_part->fieldnr)
@@ -654,8 +642,7 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat,
{
if (outparam->file->index_flags(key, i, 0) & HA_KEYREAD_ONLY)
{
- outparam->read_only_keys.clear_bit(key);
- outparam->keys_for_keyread.set_bit(key);
+ share->keys_for_keyread.set_bit(key);
field->part_of_key.set_bit(key);
}
if (outparam->file->index_flags(key, i, 1) & HA_READ_ORDER)
@@ -673,7 +660,7 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat,
the primary key, then we can use any key to find this column
*/
if (ha_option & HA_PRIMARY_KEY_IN_READ_INDEX)
- field->part_of_key= outparam->keys_in_use;
+ field->part_of_key= share->keys_in_use;
}
if (field->key_length() != key_part->length)
{
@@ -701,16 +688,16 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat,
}
keyinfo->usable_key_parts=usable_parts; // Filesort
- set_if_bigger(outparam->max_key_length,keyinfo->key_length+
+ set_if_bigger(share->max_key_length,keyinfo->key_length+
keyinfo->key_parts);
- outparam->total_key_length+= keyinfo->key_length;
+ share->total_key_length+= keyinfo->key_length;
if (keyinfo->flags & HA_NOSAME)
- set_if_bigger(outparam->max_unique_length,keyinfo->key_length);
+ set_if_bigger(share->max_unique_length, keyinfo->key_length);
}
if (primary_key < MAX_KEY &&
- (outparam->keys_in_use.is_set(primary_key)))
+ (share->keys_in_use.is_set(primary_key)))
{
- outparam->primary_key=primary_key;
+ share->primary_key= primary_key;
/*
If we are using an integer as the primary key then allow the user to
refer to it as '_rowid'
@@ -723,27 +710,25 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat,
}
}
else
- outparam->primary_key = MAX_KEY; // we do not have a primary key
+ share->primary_key = MAX_KEY; // we do not have a primary key
}
else
- outparam->primary_key= MAX_KEY;
+ share->primary_key= MAX_KEY;
x_free((gptr) disk_buff);
disk_buff=0;
if (new_field_pack_flag <= 1)
- { /* Old file format with default null */
- uint null_length=(outparam->null_fields+7)/8;
- bfill(outparam->null_flags,null_length,255);
- bfill(outparam->null_flags+outparam->rec_buff_length,null_length,255);
- if (records > 2)
- bfill(outparam->null_flags+outparam->rec_buff_length*2,null_length,255);
+ {
+ /* Old file format with default as not null */
+ uint null_length= (share->null_fields+7)/8;
+ bfill(share->default_values + (outparam->null_flags - (uchar*) record),
+ null_length, 255);
}
-
if ((reg_field=outparam->found_next_number_field))
{
- if ((int) (outparam->next_number_index= (uint)
+ if ((int) (share->next_number_index= (uint)
find_ref_key(outparam,reg_field,
- &outparam->next_number_key_offset)) < 0)
+ &share->next_number_key_offset)) < 0)
{
reg_field->unireg_check=Field::NONE; /* purecov: inspected */
outparam->found_next_number_field=0;
@@ -752,26 +737,22 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat,
reg_field->flags|=AUTO_INCREMENT_FLAG;
}
- if (outparam->blob_fields)
+ if (share->blob_fields)
{
Field **ptr;
- Field_blob **save;
+ uint i, *save;
- if (!(outparam->blob_field=save=
- (Field_blob**) alloc_root(&outparam->mem_root,
- (uint) (outparam->blob_fields+1)*
- sizeof(Field_blob*))))
+ /* Store offsets to blob fields to find them fast */
+ if (!(share->blob_field= save=
+ (uint*) alloc_root(&outparam->mem_root,
+ (uint) (share->blob_fields* sizeof(uint)))))
goto err_not_open;
- for (ptr=outparam->field ; *ptr ; ptr++)
+ for (i=0, ptr= outparam->field ; *ptr ; ptr++, i++)
{
if ((*ptr)->flags & BLOB_FLAG)
- (*save++)= (Field_blob*) *ptr;
+ (*save++)= i;
}
- *save=0; // End marker
}
- else
- outparam->blob_field=
- (Field_blob**) (outparam->field+outparam->fields); // Point at null ptr
/* The table struct is now initialized; Open the table */
error=2;
@@ -791,11 +772,11 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat,
HA_OPEN_IGNORE_IF_LOCKED) | ha_open_flags))))
{
/* Set a flag if the table is crashed and it can be auto. repaired */
- outparam->crashed=((err == HA_ERR_CRASHED_ON_USAGE) &&
- outparam->file->auto_repair() &&
- !(ha_open_flags & HA_OPEN_FOR_REPAIR));
+ share->crashed= ((err == HA_ERR_CRASHED_ON_USAGE) &&
+ outparam->file->auto_repair() &&
+ !(ha_open_flags & HA_OPEN_FOR_REPAIR));
- if (err==HA_ERR_NO_SUCH_TABLE)
+ if (err == HA_ERR_NO_SUCH_TABLE)
{
/* The table did not exists in storage engine, use same error message
as if the .frm file didn't exist */
@@ -810,27 +791,29 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat,
goto err_not_open; /* purecov: inspected */
}
}
- outparam->db_low_byte_first=outparam->file->low_byte_first();
+ share->db_low_byte_first= outparam->file->low_byte_first();
*root_ptr= old_root;
thd->status_var.opened_tables++;
#ifndef DBUG_OFF
if (use_hash)
- (void) hash_check(&outparam->name_hash);
+ (void) hash_check(&share->name_hash);
#endif
DBUG_RETURN (0);
err_w_init:
- /* Avoid problem with uninitialized data */
+ /*
+ Avoid problem with uninitialized data
+ Note that we don't have to initialize outparam->s here becasue
+ the caller will check if the pointer exists in case of errors
+ */
bzero((char*) outparam,sizeof(*outparam));
- outparam->real_name= (char*)name+dirname_length(name);
err_not_open:
x_free((gptr) disk_buff);
if (file > 0)
VOID(my_close(file,MYF(MY_WME)));
- err_end: /* Here when no file */
delete crypted;
*root_ptr= old_root;
if (! error_reported)
@@ -838,9 +821,9 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat,
delete outparam->file;
outparam->file=0; // For easier errorchecking
outparam->db_stat=0;
- hash_free(&outparam->name_hash);
- free_root(&outparam->mem_root,MYF(0));
- my_free(outparam->table_name,MYF(MY_ALLOW_ZERO_PTR));
+ hash_free(&share->name_hash);
+ free_root(&share->mem_root, MYF(0));
+ my_free((char*) outparam->alias, MYF(MY_ALLOW_ZERO_PTR));
DBUG_RETURN (error);
} /* openfrm */
@@ -853,21 +836,18 @@ int closefrm(register TABLE *table)
DBUG_ENTER("closefrm");
if (table->db_stat)
error=table->file->close();
- if (table->table_name)
- {
- my_free(table->table_name,MYF(0));
- table->table_name=0;
- }
- if (table->fields)
+ my_free((char*) table->alias, MYF(MY_ALLOW_ZERO_PTR));
+ table->alias= 0;
+ if (table->field)
{
for (Field **ptr=table->field ; *ptr ; ptr++)
delete *ptr;
- table->fields=0;
+ table->field= 0;
}
delete table->file;
- table->file=0; /* For easier errorchecking */
- hash_free(&table->name_hash);
- free_root(&table->mem_root,MYF(0));
+ table->file= 0; /* For easier errorchecking */
+ hash_free(&table->s->name_hash);
+ free_root(&table->mem_root, MYF(0));
DBUG_RETURN(error);
}
@@ -876,8 +856,11 @@ int closefrm(register TABLE *table)
void free_blobs(register TABLE *table)
{
- for (Field_blob **ptr=table->blob_field ; *ptr ; ptr++)
- (*ptr)->free();
+ uint *ptr, *end;
+ for (ptr= table->s->blob_field, end=ptr + table->s->blob_fields ;
+ ptr != end ;
+ ptr++)
+ ((Field_blob*) table->field[*ptr])->free();
}
@@ -1025,6 +1008,7 @@ static void frm_error(int error, TABLE *form, const char *name,
int err_no;
char buff[FN_REFLEN];
const char *form_dev="",*datext;
+ const char *real_name= (char*) name+dirname_length(name);
DBUG_ENTER("frm_error");
switch (error) {
@@ -1035,7 +1019,7 @@ static void frm_error(int error, TABLE *form, const char *name,
uint length=dirname_part(buff,name);
buff[length-1]=0;
db=buff+dirname_length(buff);
- my_error(ER_NO_SUCH_TABLE, MYF(0), db, form->real_name);
+ my_error(ER_NO_SUCH_TABLE, MYF(0), db, real_name);
}
else
my_error(ER_FILE_NOT_FOUND, errortype,
@@ -1048,7 +1032,7 @@ static void frm_error(int error, TABLE *form, const char *name,
err_no= (my_errno == ENOENT) ? ER_FILE_NOT_FOUND : (my_errno == EAGAIN) ?
ER_FILE_USED : ER_CANT_OPEN_FILE;
my_error(err_no,errortype,
- fn_format(buff,form->real_name,form_dev,datext,2),my_errno);
+ fn_format(buff,real_name,form_dev,datext,2),my_errno);
break;
}
case 5:
@@ -1062,7 +1046,7 @@ static void frm_error(int error, TABLE *form, const char *name,
}
my_printf_error(ER_UNKNOWN_COLLATION,
"Unknown collation '%s' in table '%-.64s' definition",
- MYF(0), csname, form->real_name);
+ MYF(0), csname, real_name);
break;
}
default: /* Better wrong error than none */
@@ -1139,22 +1123,27 @@ TYPELIB *typelib(List<String> &strings)
}
- /*
- ** Search after a field with given start & length
- ** If an exact field isn't found, return longest field with starts
- ** at right position.
- ** Return 0 on error, else field number+1
- ** This is needed because in some .frm fields 'fieldnr' was saved wrong
- */
+/*
+ Search after a field with given start & length
+ If an exact field isn't found, return longest field with starts
+ at right position.
+
+ NOTES
+ This is needed because in some .frm fields 'fieldnr' was saved wrong
+
+ RETURN
+ 0 error
+ # field number +1
+*/
static uint find_field(TABLE *form,uint start,uint length)
{
Field **field;
- uint i,pos;
+ uint i, pos, fields;
pos=0;
-
- for (field=form->field, i=1 ; i<= form->fields ; i++,field++)
+ fields= form->s->fields;
+ for (field=form->field, i=1 ; i<= fields ; i++,field++)
{
if ((*field)->offset() == start)
{
@@ -1322,17 +1311,20 @@ File create_frm(register my_string name, uint reclength, uchar *fileinfo,
void update_create_info_from_table(HA_CREATE_INFO *create_info, TABLE *table)
{
+ TABLE_SHARE *share= table->s;
DBUG_ENTER("update_create_info_from_table");
- create_info->max_rows=table->max_rows;
- create_info->min_rows=table->min_rows;
- create_info->table_options=table->db_create_options;
- create_info->avg_row_length=table->avg_row_length;
- create_info->row_type=table->row_type;
- create_info->raid_type=table->raid_type;
- create_info->raid_chunks=table->raid_chunks;
- create_info->raid_chunksize=table->raid_chunksize;
- create_info->default_table_charset=table->table_charset;
+
+ create_info->max_rows= share->max_rows;
+ create_info->min_rows= share->min_rows;
+ create_info->table_options= share->db_create_options;
+ create_info->avg_row_length= share->avg_row_length;
+ create_info->row_type= share->row_type;
+ create_info->raid_type= share->raid_type;
+ create_info->raid_chunks= share->raid_chunks;
+ create_info->raid_chunksize= share->raid_chunksize;
+ create_info->default_table_charset= share->table_charset;
create_info->table_charset= 0;
+
DBUG_VOID_RETURN;
}
@@ -2012,7 +2004,7 @@ bool st_table_list::set_insert_values(MEM_ROOT *mem_root)
{
if (!table->insert_values &&
!(table->insert_values= (byte *)alloc_root(mem_root,
- table->rec_buff_length)))
+ table->s->rec_buff_length)))
return TRUE;
}
else
diff --git a/sql/table.h b/sql/table.h
index 391b4908f96..2eca4e49a10 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -38,7 +38,7 @@ typedef struct st_order {
bool counter_used; /* parameter was counter of columns */
Field *field; /* If tmp-table group */
char *buff; /* If tmp-table group */
- table_map used,depend_map;
+ table_map used, depend_map;
} ORDER;
typedef struct st_grant_info
@@ -80,48 +80,118 @@ enum timestamp_auto_set_type
TIMESTAMP_AUTO_SET_ON_UPDATE= 2, TIMESTAMP_AUTO_SET_ON_BOTH= 3
};
-/* Table cache entry struct */
-
class Field_timestamp;
class Field_blob;
class Table_triggers_list;
-struct st_table {
- handler *file;
- Field **field; /* Pointer to fields */
- Field_blob **blob_field; /* Pointer to blob fields */
+/* This structure is shared between different table objects */
+
+typedef struct st_table_share
+{
/* hash of field names (contains pointers to elements of field array) */
- HASH name_hash;
- byte *record[2]; /* Pointer to records */
- byte *default_values; /* Default values for INSERT */
- byte *insert_values; /* used by INSERT ... UPDATE */
- uint fields; /* field count */
- uint reclength; /* Recordlength */
- uint rec_buff_length;
- uint keys,key_parts,primary_key,max_key_length,max_unique_length;
- uint total_key_length;
- uint uniques;
- uint null_fields; /* number of null fields */
- uint blob_fields; /* number of blob fields */
- key_map keys_in_use, keys_for_keyread, read_only_keys;
- key_map quick_keys, used_keys, keys_in_use_for_query;
- KEY *key_info; /* data of keys in database */
+ HASH name_hash; /* hash of field names */
+ MEM_ROOT mem_root;
TYPELIB keynames; /* Pointers to keynames */
- ha_rows max_rows; /* create information */
- ha_rows min_rows; /* create information */
- ulong avg_row_length; /* create information */
- ulong raid_chunksize;
TYPELIB fieldnames; /* Pointer to fieldnames */
TYPELIB *intervals; /* pointer to interval info */
+#ifdef NOT_YET
+ pthread_mutex_t mutex; /* For locking the share */
+ pthread_cond_t cond; /* To signal that share is ready */
+ struct st_table *open_tables; /* link to open tables */
+ struct st_table *used_next, /* Link to used tables */
+ **used_prev;
+ /* The following is copied to each TABLE on OPEN */
+ Field **field;
+ KEY *key_info; /* data of keys in database */
+#endif
+ uint *blob_field; /* Index to blobs in Field arrray*/
+ byte *default_values; /* row with default values */
+ char *comment; /* Comment about table */
+ CHARSET_INFO *table_charset; /* Default charset of string fields */
+
+ /* A pair "database_name\0table_name\0", widely used as simply a db name */
+ char *table_cache_key;
+ const char *db; /* Pointer to db */
+ const char *table_name; /* Table name (for open) */
+ const char *path; /* Path to .frm file (from datadir) */
+ key_map keys_in_use; /* Keys in use for table */
+ key_map keys_for_keyread;
+ ulong avg_row_length; /* create information */
+ ulong raid_chunksize;
+ ulong version, flush_version;
+ ulong timestamp_offset; /* Set to offset+1 of record */
+ ulong reclength; /* Recordlength */
+
+ ha_rows min_rows, max_rows; /* create information */
enum db_type db_type; /* table_type for handler */
enum row_type row_type; /* How rows are stored */
+ enum tmp_table_type tmp_table;
+
+ uint blob_ptr_size; /* 4 or 8 */
+ uint null_bytes;
+ uint key_length; /* Length of table_cache_key */
+ uint fields; /* Number of fields */
+ uint rec_buff_length; /* Size of table->record[] buffer */
+ uint keys, key_parts;
+ uint max_key_length, max_unique_length, total_key_length;
+ uint uniques; /* Number of UNIQUE index */
+ uint null_fields; /* number of null fields */
+ uint blob_fields; /* number of blob fields */
uint db_create_options; /* Create options from database */
uint db_options_in_use; /* Options in use */
uint db_record_offset; /* if HA_REC_IN_SEQ */
- uint db_stat; /* mode of file as in handler.h */
- uint raid_type,raid_chunks;
- uint status; /* Used by postfix.. */
- uint system; /* Set if system record */
+ uint raid_type, raid_chunks;
+ uint open_count; /* Number of tables in open list */
+ /* Index of auto-updated TIMESTAMP field in field array */
+ uint primary_key;
+ uint timestamp_field_offset;
+ uint next_number_index;
+ uint next_number_key_offset;
+ uchar frm_version;
+ my_bool system; /* Set if system record */
+ my_bool crypted; /* If .frm file is crypted */
+ my_bool db_low_byte_first; /* Portable row format */
+ my_bool crashed;
+ my_bool is_view;
+ my_bool name_lock, replace_with_name_lock;
+} TABLE_SHARE;
+
+
+/* Information for one open table */
+
+struct st_table {
+ TABLE_SHARE *s;
+ handler *file;
+#ifdef NOT_YET
+ struct st_table *used_next, **used_prev; /* Link to used tables */
+ struct st_table *open_next, **open_prev; /* Link to open tables */
+#endif
+ struct st_table *next, *prev;
+
+ THD *in_use; /* Which thread uses this */
+ Field **field; /* Pointer to fields */
+
+ byte *record[2]; /* Pointer to records */
+ byte *insert_values; /* used by INSERT ... UPDATE */
+ key_map quick_keys, used_keys, keys_in_use_for_query;
+ KEY *key_info; /* data of keys in database */
+
+ Field *next_number_field, /* Set if next_number is activated */
+ *found_next_number_field, /* Set on open */
+ *rowid_field;
+ Field_timestamp *timestamp_field;
+
+ /* Table's triggers, 0 if there are no of them */
+ Table_triggers_list *triggers;
+ struct st_table_list *pos_in_table_list;/* Element referring to this table */
+ ORDER *group;
+ const char *alias; /* alias or table name */
+ uchar *null_flags;
+ ulong query_id;
+
+ ha_rows quick_rows[MAX_KEY];
+ key_part_map const_key_parts[MAX_KEY];
+ uint quick_key_parts[MAX_KEY];
/*
If this table has TIMESTAMP field with auto-set property (pointed by
@@ -136,14 +206,15 @@ struct st_table {
as example).
*/
timestamp_auto_set_type timestamp_field_type;
- /* Index of auto-updated TIMESTAMP field in field array */
- uint timestamp_field_offset;
+ table_map map; /* ID bit of table (1,2,4,8,16...) */
- uint next_number_index;
- uint blob_ptr_size; /* 4 or 8 */
- uint next_number_key_offset;
- int current_lock; /* Type of lock on table */
- enum tmp_table_type tmp_table;
+ uint tablenr,used_fields;
+ uint temp_pool_slot; /* Used by intern temp tables */
+ uint status; /* What's in record[0] */
+ uint db_stat; /* mode of file as in handler.h */
+ /* number of select if it is derived table */
+ uint derived_select_number;
+ int current_lock; /* Type of lock on table */
my_bool copy_blobs; /* copy_blobs when storing */
/*
Used in outer joins: if true, all columns are considered to have NULL
@@ -155,60 +226,22 @@ struct st_table {
my_bool maybe_null; /* true if (outer_join != 0) */
my_bool force_index;
my_bool distinct,const_table,no_rows;
- my_bool key_read;
- my_bool crypted;
- my_bool db_low_byte_first; /* Portable row format */
+ my_bool key_read, no_keyread;
my_bool locked_by_flush;
my_bool locked_by_name;
my_bool fulltext_searched;
- my_bool crashed;
- my_bool is_view;
- my_bool no_keyread, no_cache;
- my_bool clear_query_id; /* To reset query_id for tables and cols */
+ my_bool no_cache;
+ /* To signal that we should reset query_id for tables and cols */
+ my_bool clear_query_id;
my_bool auto_increment_field_not_null;
my_bool insert_or_update; /* Can be used by the handler */
my_bool alias_name_used; /* true if table_name is alias */
- Field *next_number_field, /* Set if next_number is activated */
- *found_next_number_field, /* Set on open */
- *rowid_field;
- Field_timestamp *timestamp_field;
-#if MYSQL_VERSION_ID < 40100
- /*
- Indicates whenever we have to set field_length members of all TIMESTAMP
- fields to 19 (to honour 'new_mode' variable) or to original
- field_length values.
- */
- my_bool timestamp_mode;
-#endif
- my_string comment; /* Comment about table */
- CHARSET_INFO *table_charset; /* Default charset of string fields */
+
REGINFO reginfo; /* field connections */
MEM_ROOT mem_root;
GRANT_INFO grant;
- /* Table's triggers, 0 if there are no of them */
- Table_triggers_list *triggers;
-
- /* A pair "database_name\0table_name\0", widely used as simply a db name */
- char *table_cache_key;
- char *table_name,*real_name,*path;
- uint key_length; /* Length of key */
- uint tablenr,used_fields,null_bytes;
- table_map map; /* ID bit of table (1,2,4,8,16...) */
- ulong version,flush_version;
- uchar *null_flags;
FILESORT_INFO sort;
- ORDER *group;
- ha_rows quick_rows[MAX_KEY];
- uint quick_key_parts[MAX_KEY];
- key_part_map const_key_parts[MAX_KEY];
- ulong query_id;
- uchar frm_version;
- uint temp_pool_slot; /* Used by intern temp tables */
- struct st_table_list *pos_in_table_list;/* Element referring to this table */
- /* number of select if it is derived table */
- uint derived_select_number;
- THD *in_use; /* Which thread uses this */
- struct st_table *next,*prev;
+ TABLE_SHARE share_not_to_be_used; /* To be deleted when true shares */
};
@@ -243,6 +276,7 @@ typedef struct st_field_info
const char* old_name;
} ST_FIELD_INFO;
+
struct st_table_list;
typedef class Item COND;
@@ -283,19 +317,21 @@ typedef struct st_schema_table
struct st_lex;
class select_union;
+
struct Field_translator
{
Item *item;
const char *name;
};
+
typedef struct st_table_list
{
/* link in a local table list (used by SQL_LIST) */
struct st_table_list *next_local;
/* link in a global list of all queries tables */
struct st_table_list *next_global, **prev_global;
- char *db, *alias, *real_name, *schema_table_name;
+ char *db, *alias, *table_name, *schema_table_name;
char *option; /* Used by cache index */
Item *on_expr; /* Used with outer join */
COND_EQUAL *cond_equal; /* Used with outer join */
@@ -353,7 +389,7 @@ typedef struct st_table_list
thr_lock_type lock_type;
uint outer_join; /* Which join type */
uint shared; /* Used in multi-upd */
- uint32 db_length, real_name_length;
+ uint32 db_length, table_name_length;
bool updatable; /* VIEW/TABLE can be updated now */
bool straight; /* optimize with prev table */
bool updating; /* for replicate-do/ignore table */
@@ -431,6 +467,7 @@ public:
Field *field() { return 0; }
};
+
typedef struct st_nested_join
{
List<TABLE_LIST> join_list; /* list of elements in the nested join */
@@ -440,6 +477,7 @@ typedef struct st_nested_join
uint counter; /* to count tables in the nested join */
} NESTED_JOIN;
+
typedef struct st_changed_table_list
{
struct st_changed_table_list *next;
@@ -447,6 +485,7 @@ typedef struct st_changed_table_list
uint32 key_length;
} CHANGED_TABLE_LIST;
+
typedef struct st_open_table_list{
struct st_open_table_list *next;
char *db,*table;
diff --git a/sql/tztime.cc b/sql/tztime.cc
index dc38580f3b6..b9b9e4821c4 100644
--- a/sql/tztime.cc
+++ b/sql/tztime.cc
@@ -1416,10 +1416,10 @@ static void
tz_init_table_list(TABLE_LIST *tz_tabs, TABLE_LIST ***global_next_ptr)
{
bzero(tz_tabs, sizeof(TABLE_LIST) * 4);
- tz_tabs[0].alias= tz_tabs[0].real_name= (char*)"time_zone_name";
- tz_tabs[1].alias= tz_tabs[1].real_name= (char*)"time_zone";
- tz_tabs[2].alias= tz_tabs[2].real_name= (char*)"time_zone_transition_type";
- tz_tabs[3].alias= tz_tabs[3].real_name= (char*)"time_zone_transition";
+ tz_tabs[0].alias= tz_tabs[0].table_name= (char*)"time_zone_name";
+ tz_tabs[1].alias= tz_tabs[1].table_name= (char*)"time_zone";
+ tz_tabs[2].alias= tz_tabs[2].table_name= (char*)"time_zone_transition_type";
+ tz_tabs[3].alias= tz_tabs[3].table_name= (char*)"time_zone_transition";
tz_tabs[0].next_global= tz_tabs[0].next_local= tz_tabs+1;
tz_tabs[1].next_global= tz_tabs[1].next_local= tz_tabs+2;
tz_tabs[2].next_global= tz_tabs[2].next_local= tz_tabs+3;
@@ -1582,7 +1582,7 @@ my_tz_init(THD *org_thd, const char *default_tzname, my_bool bootstrap)
thd->db= my_strdup("mysql",MYF(0));
thd->db_length= 5; // Safety
bzero((char*) &tables_buff, sizeof(TABLE_LIST));
- tables_buff[0].alias= tables_buff[0].real_name=
+ tables_buff[0].alias= tables_buff[0].table_name=
(char*)"time_zone_leap_second";
tables_buff[0].lock_type= TL_READ;
tables_buff[0].db= thd->db;
diff --git a/sql/unireg.cc b/sql/unireg.cc
index ee036ed113d..dd94098fbf3 100644
--- a/sql/unireg.cc
+++ b/sql/unireg.cc
@@ -656,6 +656,7 @@ static bool make_empty_rec(File file,enum db_type table_type,
/* We need a table to generate columns for default values */
bzero((char*) &table,sizeof(table));
+ table.s= &table.share_not_to_be_used;
handler= get_new_handler((TABLE*) 0, table_type);
if (!handler ||
@@ -666,8 +667,8 @@ static bool make_empty_rec(File file,enum db_type table_type,
}
table.in_use= current_thd;
- table.db_low_byte_first= handler->low_byte_first();
- table.blob_ptr_size=portable_sizeof_char_ptr;
+ table.s->db_low_byte_first= handler->low_byte_first();
+ table.s->blob_ptr_size= portable_sizeof_char_ptr;
firstpos=reclength;
null_count=0;
diff --git a/sql/unireg.h b/sql/unireg.h
index 053ca393ad0..eca540b61b9 100644
--- a/sql/unireg.h
+++ b/sql/unireg.h
@@ -121,12 +121,12 @@
#define SPECIAL_LOG_QUERIES_NOT_USING_INDEXES 4096 /* Log q not using indexes */
/* Extern defines */
-#define store_record(A,B) bmove_align((A)->B,(A)->record[0],(size_t) (A)->reclength)
-#define restore_record(A,B) bmove_align((A)->record[0],(A)->B,(size_t) (A)->reclength)
-#define cmp_record(A,B) memcmp((A)->record[0],(A)->B,(size_t) (A)->reclength)
+#define store_record(A,B) bmove_align((A)->B,(A)->record[0],(size_t) (A)->s->reclength)
+#define restore_record(A,B) bmove_align((A)->record[0],(A)->B,(size_t) (A)->s->reclength)
+#define cmp_record(A,B) memcmp((A)->record[0],(A)->B,(size_t) (A)->s->reclength)
#define empty_record(A) { \
- restore_record((A),default_values); \
- bfill((A)->null_flags,(A)->null_bytes,255);\
+ restore_record((A),s->default_values); \
+ bfill((A)->null_flags,(A)->s->null_bytes,255);\
}
/* Defines for use with openfrm, openprt and openfrd */