29
29
static char *make_unique_key_name(const char *field_name,KEY *start,KEY *end);
30
30
static int copy_data_between_tables(Table *from,Table *to,
31
31
List<Create_field> &create, bool ignore,
32
uint32_t order_num, order_st *order,
32
uint order_num, order_st *order,
33
33
ha_rows *copied,ha_rows *deleted,
34
34
enum enum_enable_or_disable keys_onoff,
35
35
bool error_if_not_empty);
40
40
mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
41
41
Alter_info *alter_info,
44
44
handler *file, KEY **key_info_buffer,
45
uint32_t *key_count, int select_field_count);
45
uint *key_count, int select_field_count);
47
47
mysql_prepare_alter_table(THD *thd, Table *table,
48
48
HA_CREATE_INFO *create_info,
63
uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length)
63
uint filename_to_tablename(const char *from, char *to, uint to_length)
68
68
if (!memcmp(from, tmp_file_prefix, tmp_file_prefix_length))
70
70
/* Temporary table name. */
71
res= (my_stpncpy(to, from, to_length) - to);
71
res= (stpncpy(to, from, to_length) - to);
76
76
system_charset_info, to, to_length, &errors);
77
77
if (errors) // Old 5.0 name
79
res= (strxnmov(to, to_length, MYSQL50_TABLE_NAME_PREFIX, from, NULL) -
79
res= (strxnmov(to, to_length, MYSQL50_TABLE_NAME_PREFIX, from, NullS) -
81
81
sql_print_error(_("Invalid (old?) table or database name '%s'"), from);
102
uint32_t tablename_to_filename(const char *from, char *to, uint32_t to_length)
102
uint tablename_to_filename(const char *from, char *to, uint to_length)
104
uint32_t errors, length;
106
106
if (from[0] == '#' && !strncmp(from, MYSQL50_TABLE_NAME_PREFIX,
107
107
MYSQL50_TABLE_NAME_PREFIX_LENGTH))
156
uint32_t build_table_filename(char *buff, size_t bufflen, const char *db,
157
const char *table_name, const char *ext, uint32_t flags)
156
uint build_table_filename(char *buff, size_t bufflen, const char *db,
157
const char *table_name, const char *ext, uint flags)
159
159
char dbbuff[FN_REFLEN];
160
160
char tbbuff[FN_REFLEN];
162
162
if (flags & FN_IS_TMP) // FN_FROM_IS_TMP | FN_TO_IS_TMP
163
my_stpncpy(tbbuff, table_name, sizeof(tbbuff));
163
stpncpy(tbbuff, table_name, sizeof(tbbuff));
165
tablename_to_filename(table_name, tbbuff, sizeof(tbbuff));
165
VOID(tablename_to_filename(table_name, tbbuff, sizeof(tbbuff)));
167
tablename_to_filename(db, dbbuff, sizeof(dbbuff));
167
VOID(tablename_to_filename(db, dbbuff, sizeof(dbbuff)));
169
169
char *end = buff + bufflen;
170
170
/* Don't add FN_ROOTDIR if mysql_data_home already includes it */
171
char *pos = my_stpncpy(buff, mysql_data_home, bufflen);
171
char *pos = stpncpy(buff, mysql_data_home, bufflen);
172
172
int rootdir_len= strlen(FN_ROOTDIR);
173
173
if (pos - rootdir_len >= buff &&
174
174
memcmp(pos - rootdir_len, FN_ROOTDIR, rootdir_len) != 0)
175
pos= my_stpncpy(pos, FN_ROOTDIR, end - pos);
176
pos= strxnmov(pos, end - pos, dbbuff, FN_ROOTDIR, NULL);
175
pos= stpncpy(pos, FN_ROOTDIR, end - pos);
176
pos= strxnmov(pos, end - pos, dbbuff, FN_ROOTDIR, NullS);
177
177
#ifdef USE_SYMDIR
178
178
unpack_dirname(buff, buff);
179
179
pos= strend(buff);
181
pos= strxnmov(pos, end - pos, tbbuff, ext, NULL);
181
pos= strxnmov(pos, end - pos, tbbuff, ext, NullS);
183
183
return(pos - buff);
205
uint32_t build_tmptable_filename(THD* thd, char *buff, size_t bufflen)
205
uint build_tmptable_filename(THD* thd, char *buff, size_t bufflen)
208
char *p= my_stpncpy(buff, mysql_tmpdir, bufflen);
208
char *p= stpncpy(buff, mysql_tmpdir, bufflen);
209
209
snprintf(p, bufflen - (p - buff), "/%s%lx_%lx_%x%s",
210
210
tmp_file_prefix, current_pid,
211
211
thd->thread_id, thd->tmp_table++, reg_ext);
606
607
bool quick_rm_table(handlerton *base,const char *db,
607
const char *table_name, uint32_t flags)
608
const char *table_name, uint flags)
609
610
char path[FN_REFLEN];
612
uint32_t path_length= build_table_filename(path, sizeof(path),
613
uint path_length= build_table_filename(path, sizeof(path),
613
614
db, table_name, reg_ext, flags);
614
615
if (my_delete(path,MYF(0)))
615
616
error= 1; /* purecov: inspected */
730
731
uint32_t *max_length, uint32_t *tot_length)
732
733
const char **pos;
734
735
*max_length= *tot_length= 0;
735
736
for (pos= interval->type_names, len= interval->type_lengths;
736
737
*pos ; pos++, len++)
738
uint32_t length= cs->cset->numchars(cs, *pos, *pos + *len);
739
uint length= cs->cset->numchars(cs, *pos, *pos + *len);
739
740
*tot_length+= length;
740
741
set_if_bigger(*max_length, (uint32_t)length);
839
840
(sql_field->decimals << FIELDFLAG_DEC_SHIFT));
842
if (!(sql_field->flags & NOT_NULL_FLAG) ||
843
(sql_field->vcol_info)) /* Make virtual columns always allow NULL values */
843
if (!(sql_field->flags & NOT_NULL_FLAG))
844
844
sql_field->pack_flag|= FIELDFLAG_MAYBE_NULL;
845
845
if (sql_field->flags & NO_DEFAULT_VALUE_FLAG)
846
846
sql_field->pack_flag|= FIELDFLAG_NO_DEFAULT;
877
877
mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
878
878
Alter_info *alter_info,
880
uint32_t *db_options,
881
881
handler *file, KEY **key_info_buffer,
882
uint32_t *key_count, int select_field_count)
882
uint *key_count, int select_field_count)
884
884
const char *key_name;
885
885
Create_field *sql_field,*dup_field;
892
892
int select_field_pos,auto_increment=0;
893
893
List_iterator<Create_field> it(alter_info->create_list);
894
894
List_iterator<Create_field> it2(alter_info->create_list);
895
uint32_t total_uneven_bit_length= 0;
895
uint total_uneven_bit_length= 0;
897
897
select_field_pos= alter_info->create_list.elements - select_field_count;
898
898
null_fields=blob_columns=0;
983
983
List_iterator<String> int_it(sql_field->interval_list);
984
984
String conv, *tmp;
985
985
char comma_buf[4];
986
int comma_length= cs->cset->wc_mb(cs, ',', (unsigned char*) comma_buf,
987
(unsigned char*) comma_buf +
986
int comma_length= cs->cset->wc_mb(cs, ',', (uchar*) comma_buf,
988
988
sizeof(comma_buf));
989
989
assert(comma_length > 0);
990
for (uint32_t i= 0; (tmp= int_it++); i++)
990
for (uint i= 0; (tmp= int_it++); i++)
993
993
if (String::needs_conversion(tmp->length(), tmp->charset(),
997
997
conv.copy(tmp->ptr(), tmp->length(), tmp->charset(), cs, &cnv_errs);
998
998
interval->type_names[i]= strmake_root(thd->mem_root, conv.ptr(),
1004
1004
lengthsp= cs->cset->lengthsp(cs, interval->type_names[i],
1005
1005
interval->type_lengths[i]);
1006
1006
interval->type_lengths[i]= lengthsp;
1007
((unsigned char *)interval->type_names[i])[lengthsp]= '\0';
1007
((uchar *)interval->type_names[i])[lengthsp]= '\0';
1009
1009
sql_field->interval_list.empty(); // Don't need interval_list anymore
1127
1125
sql_field->offset= record_offset;
1128
1126
if (MTYP_TYPENR(sql_field->unireg_check) == Field::NEXT_NUMBER)
1129
1127
auto_increment++;
1131
For now skip fields that are not physically stored in the database
1132
(virtual fields) and update their offset later
1133
(see the next loop).
1135
if (sql_field->is_stored)
1136
record_offset+= sql_field->pack_length;
1138
/* Update virtual fields' offset */
1140
while ((sql_field=it++))
1142
if (not sql_field->is_stored)
1144
sql_field->offset= record_offset;
1145
record_offset+= sql_field->pack_length;
1128
record_offset+= sql_field->pack_length;
1148
1130
if (timestamps_with_niladic > 1)
1176
1158
List_iterator<Key> key_iterator(alter_info->key_list);
1177
1159
List_iterator<Key> key_iterator2(alter_info->key_list);
1178
uint32_t key_parts=0, fk_key_count=0;
1160
uint key_parts=0, fk_key_count=0;
1179
1161
bool primary_key=0,unique_key=0;
1180
1162
Key *key, *key2;
1181
uint32_t tmp, key_number;
1163
uint tmp, key_number;
1182
1164
/* special marker for keys to be ignored */
1183
1165
static char ignore_key[1];
1314
1294
if (key_info->block_size)
1315
1295
key_info->flags|= HA_USES_BLOCK_SIZE;
1317
uint32_t tmp_len= system_charset_info->cset->charpos(system_charset_info,
1297
uint tmp_len= system_charset_info->cset->charpos(system_charset_info,
1318
1298
key->key_create_info.comment.str,
1319
1299
key->key_create_info.comment.str +
1320
1300
key->key_create_info.comment.length,
1384
if (not sql_field->is_stored)
1386
/* Key fields must always be physically stored. */
1387
my_error(ER_KEY_BASED_ON_GENERATED_VIRTUAL_COLUMN, MYF(0));
1390
if (key->type == Key::PRIMARY && sql_field->vcol_info)
1392
my_error(ER_PRIMARY_KEY_BASED_ON_VIRTUAL_COLUMN, MYF(0));
1395
1364
if (!(sql_field->flags & NOT_NULL_FLAG))
1397
1366
if (key->type == Key::PRIMARY)
1430
1399
if ((length=column->length) > max_key_length ||
1431
1400
length > file->max_key_part_length())
1433
length=cmin(max_key_length, file->max_key_part_length());
1402
length=min(max_key_length, file->max_key_part_length());
1434
1403
if (key->type == Key::MULTIPLE)
1436
1405
/* not a critical problem */
1561
1530
/* Sort keys in optimized order */
1562
my_qsort((unsigned char*) *key_info_buffer, *key_count, sizeof(KEY),
1531
my_qsort((uchar*) *key_info_buffer, *key_count, sizeof(KEY),
1563
1532
(qsort_cmp) sort_keys);
1564
1533
create_info->null_bits= null_fields;
1937
1904
write_bin_log(thd, true, thd->query, thd->query_length);
1939
1906
unlock_and_end:
1941
pthread_mutex_unlock(&LOCK_open);
1907
VOID(pthread_mutex_unlock(&LOCK_open));
1944
thd->set_proc_info("After create");
1910
thd_proc_info(thd, "After create");
1971
1937
/* Wait for any database locks */
1972
1938
pthread_mutex_lock(&LOCK_lock_db);
1973
1939
while (!thd->killed &&
1974
hash_search(&lock_db_cache,(unsigned char*) db, strlen(db)))
1940
hash_search(&lock_db_cache,(uchar*) db, strlen(db)))
1976
1942
wait_for_condition(thd, &LOCK_lock_db, &COND_refresh);
1977
1943
pthread_mutex_lock(&LOCK_lock_db);
2059
2025
Only 3 chars + '\0' left, so need to limit to 2 digit
2060
2026
This is ok as we can't have more than 100 keys anyway
2062
for (uint32_t i=2 ; i< 100; i++)
2028
for (uint i=2 ; i< 100; i++)
2064
2030
*buff_end= '_';
2065
2031
int10_to_str(i, buff_end+1, 10);
2100
2066
mysql_rename_table(handlerton *base, const char *old_db,
2101
2067
const char *old_name, const char *new_db,
2102
const char *new_name, uint32_t flags)
2068
const char *new_name, uint flags)
2104
2070
THD *thd= current_thd;
2105
2071
char from[FN_REFLEN], to[FN_REFLEN], lc_from[FN_REFLEN], lc_to[FN_REFLEN];
2124
2090
if (lower_case_table_names == 2 && file &&
2125
2091
!(file->ha_table_flags() & HA_FILE_BASED))
2127
my_stpcpy(tmp_name, old_name);
2093
stpcpy(tmp_name, old_name);
2128
2094
my_casedn_str(files_charset_info, tmp_name);
2129
2095
build_table_filename(lc_from, sizeof(lc_from), old_db, tmp_name, "",
2130
2096
flags & FN_FROM_IS_TMP);
2131
2097
from_base= lc_from;
2133
my_stpcpy(tmp_name, new_name);
2099
stpcpy(tmp_name, new_name);
2134
2100
my_casedn_str(files_charset_info, tmp_name);
2135
2101
build_table_filename(lc_to, sizeof(lc_to), new_db, tmp_name, "",
2136
2102
flags & FN_TO_IS_TMP);
2311
2277
goto end; // No data file
2313
2279
// Name of data file
2314
strxmov(from, table->s->normalized_path.str, ext[1], NULL);
2280
strxmov(from, table->s->normalized_path.str, ext[1], NullS);
2315
2281
if (stat(from, &stat_info))
2316
2282
goto end; // Can't use USE_FRM flag
2436
2402
char* db = table->db;
2437
2403
bool fatal_error=0;
2439
strxmov(table_name, db, ".", table->table_name, NULL);
2405
strxmov(table_name, db, ".", table->table_name, NullS);
2440
2406
thd->open_options|= extra_open_options;
2441
2407
table->lock_type= lock_type;
2442
2408
/* open only one table from local list of command */
2609
2575
case HA_ADMIN_NOT_IMPLEMENTED:
2611
2577
char buf[ERRMSGSIZE+20];
2612
uint32_t length=snprintf(buf, ERRMSGSIZE,
2578
uint length=snprintf(buf, ERRMSGSIZE,
2613
2579
ER(ER_CHECK_NOT_IMPLEMENTED), operator_name);
2614
2580
protocol->store(STRING_WITH_LEN("note"), system_charset_info);
2615
2581
protocol->store(buf, length, system_charset_info);
2619
2585
case HA_ADMIN_NOT_BASE_TABLE:
2621
2587
char buf[ERRMSGSIZE+20];
2622
uint32_t length= snprintf(buf, ERRMSGSIZE,
2588
uint length= snprintf(buf, ERRMSGSIZE,
2623
2589
ER(ER_BAD_TABLE_ERROR), table_name);
2624
2590
protocol->store(STRING_WITH_LEN("note"), system_charset_info);
2625
2591
protocol->store(buf, length, system_charset_info);
2746
2712
default: // Probably HA_ADMIN_INTERNAL_ERROR
2748
2714
char buf[ERRMSGSIZE+20];
2749
uint32_t length=snprintf(buf, ERRMSGSIZE,
2715
uint length=snprintf(buf, ERRMSGSIZE,
2750
2716
_("Unknown - internal error %d during operation"),
2752
2718
protocol->store(STRING_WITH_LEN("error"), system_charset_info);
2902
2868
HA_CREATE_INFO local_create_info;
2903
2869
Alter_info alter_info;
2904
2870
bool tmp_table= (create_info->options & HA_LEX_CREATE_TMP_TABLE);
2905
uint32_t keys= schema_table->table->s->keys;
2906
uint32_t db_options= 0;
2871
uint keys= schema_table->table->s->keys;
2908
2874
memset(&local_create_info, 0, sizeof(local_create_info));
2909
2875
local_create_info.db_type= schema_table->table->s->db_type();
2920
2886
&schema_table->table->s->key_info, &keys, 0))
2922
2888
local_create_info.max_rows= 0;
2923
if (mysql_create_frm(thd, dst_path, NULL, NULL,
2889
if (mysql_create_frm(thd, dst_path, NullS, NullS,
2924
2890
&local_create_info, alter_info.create_list,
2925
2891
keys, schema_table->table->s->key_info,
2926
2892
schema_table->table->file))
2968
2934
if (open_tables(thd, &src_table, ¬_used, 0))
2971
strxmov(src_path, src_table->table->s->path.str, reg_ext, NULL);
2937
strxmov(src_path, src_table->table->s->path.str, reg_ext, NullS);
2974
2940
Check that destination tables does not exist. Note that its name
3006
2972
Also some engines (e.g. NDB cluster) require that LOCK_open should be held
3007
2973
during the call to ha_create_table(). See bug #28614 for more info.
3009
pthread_mutex_lock(&LOCK_open);
2975
VOID(pthread_mutex_lock(&LOCK_open));
3010
2976
if (src_table->schema_table)
3012
2978
if (mysql_create_like_schema_frm(thd, src_table, dst_path, create_info))
3014
pthread_mutex_unlock(&LOCK_open);
2980
VOID(pthread_mutex_unlock(&LOCK_open));
3021
2987
my_error(ER_BAD_DB_ERROR,MYF(0),db);
3023
2989
my_error(ER_CANT_CREATE_FILE,MYF(0),dst_path,my_errno);
3024
pthread_mutex_unlock(&LOCK_open);
2990
VOID(pthread_mutex_unlock(&LOCK_open));
3034
3000
if (thd->variables.keep_files_on_create)
3035
3001
create_info->options|= HA_CREATE_KEEP_FILES;
3036
3002
err= ha_create_table(thd, dst_path, db, table_name, create_info, 1);
3037
pthread_mutex_unlock(&LOCK_open);
3003
VOID(pthread_mutex_unlock(&LOCK_open));
3039
3005
if (create_info->options & HA_LEX_CREATE_TMP_TABLE)
3089
3055
of this function.
3091
3057
table->table= name_lock;
3092
pthread_mutex_lock(&LOCK_open);
3058
VOID(pthread_mutex_lock(&LOCK_open));
3093
3059
if (reopen_name_locked_table(thd, table, false))
3095
pthread_mutex_unlock(&LOCK_open);
3061
VOID(pthread_mutex_unlock(&LOCK_open));
3098
pthread_mutex_unlock(&LOCK_open);
3064
VOID(pthread_mutex_unlock(&LOCK_open));
3100
3066
int result= store_create_info(thd, table, &query,
3294
3260
Alter_info *alter_info,
3295
3261
HA_CREATE_INFO *create_info,
3297
3263
HA_ALTER_FLAGS *alter_flags,
3298
3264
HA_ALTER_INFO *ha_alter_info,
3299
uint32_t *table_changes)
3265
uint *table_changes)
3301
3267
Field **f_ptr, *field;
3302
uint32_t table_changes_local= 0;
3268
uint table_changes_local= 0;
3303
3269
List_iterator_fast<Create_field> new_field_it(alter_info->create_list);
3304
3270
Create_field *new_field;
3305
3271
KEY_PART_INFO *key_part;
3329
3295
Alter_info tmp_alter_info(*alter_info, thd->mem_root);
3330
3296
THD *thd= table->in_use;
3331
uint32_t db_options= 0; /* not used */
3297
uint db_options= 0; /* not used */
3332
3298
/* Create the prepared information. */
3333
3299
if (mysql_prepare_create_table(thd, create_info,
3334
3300
&tmp_alter_info,
3441
3407
if (!(table_changes_local= field->is_equal(new_field)))
3442
3408
*alter_flags|= HA_ALTER_COLUMN_TYPE;
3445
Check if the altered column is a stored virtual field.
3446
TODO: Mark such a column with an alter flag only if
3447
the expression functions are not equal.
3449
if (field->is_stored && field->vcol_info)
3450
*alter_flags|= HA_ALTER_STORED_VCOL;
3452
3410
/* Check if field was renamed */
3453
3411
field->flags&= ~FIELD_IS_RENAMED;
3454
3412
if (my_strcasecmp(system_charset_info,
3730
3688
if (create_info->index_file_name)
3732
3690
/* Fix index_file_name to have 'tmp_name' as basename */
3733
my_stpcpy(index_file, tmp_name);
3691
stpcpy(index_file, tmp_name);
3734
3692
create_info->index_file_name=fn_same(index_file,
3735
3693
create_info->index_file_name,
3738
3696
if (create_info->data_file_name)
3740
3698
/* Fix data_file_name to have 'tmp_name' as basename */
3741
my_stpcpy(data_file, tmp_name);
3699
stpcpy(data_file, tmp_name);
3742
3700
create_info->data_file_name=fn_same(data_file,
3743
3701
create_info->data_file_name,
3887
3845
The final .frm file is already created as a temporary file
3888
3846
and will be renamed to the original table name.
3890
pthread_mutex_lock(&LOCK_open);
3848
VOID(pthread_mutex_lock(&LOCK_open));
3891
3849
wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN);
3892
3850
alter_table_manage_keys(table, table->file->indexes_are_disabled(),
3901
3859
table->s->table_name.str, FN_FROM_IS_TMP))
3904
pthread_mutex_unlock(&LOCK_open);
3862
VOID(pthread_mutex_unlock(&LOCK_open));
3907
3865
broadcast_refresh();
3908
pthread_mutex_unlock(&LOCK_open);
3866
VOID(pthread_mutex_unlock(&LOCK_open));
3911
3869
The ALTER Table is always in its own transaction.
3947
3905
assert(t_table == table);
3948
3906
table->open_placeholder= 1;
3949
pthread_mutex_lock(&LOCK_open);
3907
VOID(pthread_mutex_lock(&LOCK_open));
3950
3908
close_handle_and_leave_table_as_lock(table);
3951
pthread_mutex_unlock(&LOCK_open);
3909
VOID(pthread_mutex_unlock(&LOCK_open));
4015
3973
List_iterator<Create_field> find_it(new_create_list);
4016
3974
List_iterator<Create_field> field_it(new_create_list);
4017
3975
List<Key_part_spec> key_parts;
4018
uint32_t db_create_options= (table->s->db_create_options
3976
uint db_create_options= (table->s->db_create_options
4019
3977
& ~(HA_OPTION_PACK_RECORD));
4020
uint32_t used_fields= create_info->used_fields;
3978
uint used_fields= create_info->used_fields;
4021
3979
KEY *key_info=table->key_info;
4414
4364
HA_CREATE_INFO *create_info,
4415
4365
TableList *table_list,
4416
4366
Alter_info *alter_info,
4417
uint32_t order_num, order_st *order, bool ignore)
4367
uint order_num, order_st *order, bool ignore)
4419
4369
Table *table, *new_table=0, *name_lock= 0;;
4436
4386
to simplify further comparisons: we want to see if it's a RENAME
4437
4387
later just by comparing the pointers, avoiding the need for strcmp.
4439
thd->set_proc_info("init");
4389
thd_proc_info(thd, "init");
4440
4390
table_name=table_list->table_name;
4441
4391
alias= (lower_case_table_names == 2) ? table_list->alias : table_name;
4442
4392
db=table_list->db;
4452
4402
return(mysql_discard_or_import_tablespace(thd,table_list,
4453
4403
alter_info->tablespace_op));
4454
4404
strxnmov(new_name_buff, sizeof (new_name_buff) - 1, mysql_data_home, "/", db,
4455
"/", table_name, reg_ext, NULL);
4405
"/", table_name, reg_ext, NullS);
4456
4406
(void) unpack_filename(new_name_buff, new_name_buff);
4458
4408
If this is just a rename of a view, short cut to the
4476
4426
/* Check that we are not trying to rename to an existing table */
4479
my_stpcpy(new_name_buff,new_name);
4480
my_stpcpy(new_alias= new_alias_buff, new_name);
4429
stpcpy(new_name_buff,new_name);
4430
stpcpy(new_alias= new_alias_buff, new_name);
4481
4431
if (lower_case_table_names)
4483
4433
if (lower_case_table_names != 2)
4578
4528
while the fact that the table is still open gives us protection
4579
4529
from concurrent DDL statements.
4581
pthread_mutex_lock(&LOCK_open);
4531
VOID(pthread_mutex_lock(&LOCK_open));
4582
4532
wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN);
4583
pthread_mutex_unlock(&LOCK_open);
4533
VOID(pthread_mutex_unlock(&LOCK_open));
4584
4534
error= table->file->ha_enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
4585
4535
/* COND_refresh will be signaled in close_thread_tables() */
4588
pthread_mutex_lock(&LOCK_open);
4538
VOID(pthread_mutex_lock(&LOCK_open));
4589
4539
wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN);
4590
pthread_mutex_unlock(&LOCK_open);
4540
VOID(pthread_mutex_unlock(&LOCK_open));
4591
4541
error=table->file->ha_disable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
4592
4542
/* COND_refresh will be signaled in close_thread_tables() */
4712
4662
Table *altered_table= 0;
4713
4663
HA_ALTER_INFO ha_alter_info;
4714
4664
HA_ALTER_FLAGS ha_alter_flags;
4715
uint32_t table_changes= IS_EQUAL_YES;
4665
uint table_changes= IS_EQUAL_YES;
4716
4666
bool need_copy_table= true;
4717
4667
/* Check how much the tables differ. */
4718
4668
if (compare_tables(thd, table, alter_info,
4887
pthread_mutex_lock(&LOCK_open);
4837
VOID(pthread_mutex_lock(&LOCK_open));
4888
4838
wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN);
4889
pthread_mutex_unlock(&LOCK_open);
4839
VOID(pthread_mutex_unlock(&LOCK_open));
4890
4840
alter_table_manage_keys(table, table->file->indexes_are_disabled(),
4891
4841
alter_info->keys_onoff);
4892
4842
error= ha_autocommit_or_rollback(thd, 0);
4924
4874
Note that MERGE tables do not have their children attached here.
4926
4876
intern_close_table(new_table);
4877
my_free(new_table,MYF(0));
4929
pthread_mutex_lock(&LOCK_open);
4879
VOID(pthread_mutex_lock(&LOCK_open));
4932
quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP);
4933
pthread_mutex_unlock(&LOCK_open);
4882
VOID(quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP));
4883
VOID(pthread_mutex_unlock(&LOCK_open));
4950
4900
call to remove name-locks from table cache and list of open table.
4953
thd->set_proc_info("rename result table");
4903
thd_proc_info(thd, "rename result table");
4954
4904
snprintf(old_name, sizeof(old_name), "%s2-%lx-%lx", tmp_file_prefix,
4955
4905
current_pid, thd->thread_id);
4956
4906
if (lower_case_table_names)
4982
quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP);
4932
VOID(quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP));
4984
4934
else if (mysql_rename_table(new_db_type, new_db, tmp_name, new_db,
4985
4935
new_alias, FN_FROM_IS_TMP) || ((new_name != table_name || new_db != db) && 0))
4987
4937
/* Try to get everything back. */
4989
quick_rm_table(new_db_type,new_db,new_alias, 0);
4990
quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP);
4991
mysql_rename_table(old_db_type, db, old_name, db, alias,
4939
VOID(quick_rm_table(new_db_type,new_db,new_alias, 0));
4940
VOID(quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP));
4941
VOID(mysql_rename_table(old_db_type, db, old_name, db, alias,
4998
4948
goto err_with_placeholders;
5001
quick_rm_table(old_db_type, db, old_name, FN_IS_TMP);
4951
VOID(quick_rm_table(old_db_type, db, old_name, FN_IS_TMP));
5004
4954
if (thd->locked_tables && new_name == table_name && new_db == db)
5010
4960
goto err_with_placeholders;
5012
pthread_mutex_unlock(&LOCK_open);
5014
thd->set_proc_info("end");
4962
VOID(pthread_mutex_unlock(&LOCK_open));
4964
thd_proc_info(thd, "end");
4966
ha_binlog_log_query(thd, create_info->db_type, LOGCOM_ALTER_TABLE,
4967
thd->query, thd->query_length,
5016
4970
assert(!(mysql_bin_log.is_open() &&
5017
4971
thd->current_stmt_binlog_row_based &&
5070
5024
close_temporary_table(thd, new_table, 1, 1);
5073
quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP);
5027
VOID(quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP));
5130
5084
copy_data_between_tables(Table *from,Table *to,
5131
5085
List<Create_field> &create,
5133
uint32_t order_num, order_st *order,
5087
uint order_num, order_st *order,
5134
5088
ha_rows *copied,
5135
5089
ha_rows *deleted,
5136
5090
enum enum_enable_or_disable keys_onoff,
5364
5317
create_info.default_table_charset=default_charset_info;
5365
5318
/* Force alter table to recreate table */
5366
5319
alter_info.flags= (ALTER_CHANGE_COLUMN | ALTER_RECREATE);
5367
return(mysql_alter_table(thd, NULL, NULL, &create_info,
5320
return(mysql_alter_table(thd, NullS, NullS, &create_info,
5368
5321
table_list, &alter_info, 0,
5369
5322
(order_st *) 0, 0));
5393
5346
char table_name[NAME_LEN*2+2];
5396
strxmov(table_name, table->db ,".", table->table_name, NULL);
5349
strxmov(table_name, table->db ,".", table->table_name, NullS);
5398
5351
t= table->table= open_n_lock_single_table(thd, table, TL_READ);
5399
5352
thd->clear_error(); // these errors shouldn't get client