diff options
author | unknown <monty@mysql.com> | 2005-01-06 13:00:13 +0200 |
---|---|---|
committer | unknown <monty@mysql.com> | 2005-01-06 13:00:13 +0200 |
commit | acf76e3b88b4ec294c8f63f0fb2a29f895228259 (patch) | |
tree | ed8b3e5bd637f4d9661ed2ba57849e7e56d5178a /sql/sql_insert.cc | |
parent | bd365f76222e6263095e079ab9e634e88f06b7e1 (diff) | |
download | mariadb-git-acf76e3b88b4ec294c8f63f0fb2a29f895228259.tar.gz |
First stage of table definition cache
Split TABLE to TABLE and TABLE_SHARE (TABLE_SHARE is still allocated as part of table, will be fixed soon)
Created Field::make_field() and made Field_num::make_field() to call this
Added 'TABLE_SHARE->db' that points to database name; Changed all usage of table_cache_key as database name to use this instead
Changed field->table_name to point to pointer to alias. This allows us to change alias for a table by just updating one pointer.
Renamed TABLE_SHARE->real_name to table_name
Renamed TABLE->table_name to alias
Renamed TABLE_LIST->real_name to table_name
include/myisam.h:
Added const before names
mysql-test/r/group_min_max.result:
Make results repeatable
mysql-test/t/group_min_max.test:
Make results repeatable
sql/field.cc:
Created Field::make_field() and made Field_num::make_field() to call this
Use TABLE_SHARE
Use sql_strmake() instead of sql_memdup() to simplify code
sql/field.h:
Changed table_name to be pointer to table_name. This allows us to change alias for all fields by just changing one pointer.
Use TABLE_SHARE
sql/field_conv.cc:
Use TABLE_SHARE
sql/filesort.cc:
Use TABLE_SHARE
sql/ha_berkeley.cc:
Use TABLE_SHARE
sql/ha_heap.cc:
Use TABLE_SHARE
sql/ha_innodb.cc:
Use TABLE_SHARE
sql/ha_myisam.cc:
Use TABLE_SHARE
sql/ha_myisammrg.cc:
Use TABLE_SHARE
Change some pointer handling to use const char*
sql/ha_ndbcluster.cc:
Use TABLE_SHARE
sql/handler.cc:
Use TABLE_SHARE
sql/item.cc:
Use TABLE_SHARE
sql/item_func.cc:
Use TABLE_SHARE
sql/item_subselect.cc:
Use TABLE_SHARE
sql/item_sum.cc:
Use TABLE_SHARE
sql/key.cc:
Use TABLE_SHARE
sql/lock.cc:
Use TABLE_SHARE
sql/log_event.cc:
real_name -> table_name
sql/mysql_priv.h:
Use TABLE_SHARE
sql/opt_range.cc:
Use TABLE_SHARE
sql/opt_sum.cc:
Use TABLE_SHARE
sql/records.cc:
Use TABLE_SHARE
sql/repl_failsafe.cc:
real_name -> table_name
sql/slave.cc:
Use TABLE_SHARE
sql/sp.cc:
Use TABLE_SHARE
sql/sp_head.cc:
real_name -> table_name
sql/sql_acl.cc:
Use TABLE_SHARE
removed unnecessary assert
fixed indentation
changed some char * -> const char*
sql/sql_acl.h:
changed some char* -> const char*
sql/sql_base.cc:
Use TABLE_SHARE
sql/sql_cache.cc:
Use TABLE_SHARE
sql/sql_class.cc:
Use TABLE_SHARE
sql/sql_db.cc:
real_name -> table_name
sql/sql_delete.cc:
Use TABLE_SHARE
sql/sql_derived.cc:
Use TABLE_SHARE
sql/sql_handler.cc:
Use TABLE_SHARE
sql/sql_help.cc:
Use TABLE_SHARE
sql/sql_insert.cc:
Use TABLE_SHARE
sql/sql_load.cc:
Use TABLE_SHARE
sql/sql_parse.cc:
Use TABLE_SHARE
sql/sql_rename.cc:
real_name -> table_name
sql/sql_select.cc:
Use TABLE_SHARE
table->blob_fields now points to field offsets, not fields
tmp_table->table_name now points to alias name
sql/sql_show.cc:
Use TABLE_SHARE
sql/sql_table.cc:
Use TABLE_SHARE
sql/sql_test.cc:
Use TABLE_SHARE
sql/sql_trigger.cc:
Use TABLE_SHARE
sql/sql_udf.cc:
Use TABLE_SHARE
sql/sql_union.cc:
real_name -> table_name
sql/sql_update.cc:
Use TABLE_SHARE
sql/sql_view.cc:
Use TABLE_SHARE
sql/table.cc:
Split TABLE to TABLE and TABLE_SHARE
Changed blob_field to be field offsets instead of pointer to fields
Only initialize table->s->default_values with default record (not all table->record[#])
Some indentation changes
sql/table.h:
Split TABLE to TABLE and TABLE_SHARE
sql/tztime.cc:
real_name -> table_name
sql/unireg.cc:
Use TABLE_SHARE
sql/unireg.h:
Use TABLE_SHARE
Diffstat (limited to 'sql/sql_insert.cc')
-rw-r--r-- | sql/sql_insert.cc | 92 |
1 files changed, 47 insertions, 45 deletions
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*) ©->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)); |