mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
First stage of table definition cache
Split TABLE to TABLE and TABLE_SHARE (TABLE_SHARE is still allocated as part of table, will be fixed soon) Created Field::make_field() and made Field_num::make_field() to call this Added 'TABLE_SHARE->db' that points to database name; Changed all usage of table_cache_key as database name to use this instead Changed field->table_name to point to pointer to alias. This allows us to change alias for a table by just updating one pointer. Renamed TABLE_SHARE->real_name to table_name Renamed TABLE->table_name to alias Renamed TABLE_LIST->real_name to table_name
This commit is contained in:
@ -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*) ©->name_hash,sizeof(copy->name_hash)); // No name hashing
|
||||
copy->s= ©->share_not_to_be_used;
|
||||
// No name hashing
|
||||
bzero((char*) ©->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));
|
||||
|
Reference in New Issue
Block a user