62
56
List<CreateField> &create,
64
58
uint32_t order_num,
68
62
enum enum_enable_or_disable keys_onoff,
69
63
bool error_if_not_empty);
71
static bool prepare_alter_table(Session *session,
65
static bool mysql_prepare_alter_table(Session *session,
73
67
HA_CREATE_INFO *create_info,
74
68
const message::Table &original_proto,
75
69
message::Table &table_message,
76
70
AlterInfo *alter_info);
78
static Table *open_alter_table(Session *session, Table *table, identifier::Table &identifier);
82
AlterTable::AlterTable(Session *in_session, Table_ident *ident, drizzled::ha_build_method build_arg) :
83
CreateTable(in_session)
85
in_session->lex->sql_command= SQLCOM_ALTER_TABLE;
87
alter_info.build_method= build_arg;
90
} // namespace statement
72
static int create_temporary_table(Session *session,
73
TableIdentifier &identifier,
74
HA_CREATE_INFO *create_info,
75
message::Table &create_message,
76
AlterInfo *alter_info);
78
static Table *open_alter_table(Session *session, Table *table, TableIdentifier &identifier);
92
80
bool statement::AlterTable::execute()
94
TableList *first_table= (TableList *) getSession()->lex->select_lex.table_list.first;
95
TableList *all_tables= getSession()->lex->query_tables;
82
TableList *first_table= (TableList *) session->lex->select_lex.table_list.first;
83
TableList *all_tables= session->lex->query_tables;
96
84
assert(first_table == all_tables && first_table != 0);
97
Select_Lex *select_lex= &getSession()->lex->select_lex;
85
Select_Lex *select_lex= &session->lex->select_lex;
98
86
bool need_start_waiting= false;
100
is_engine_set= not createTableMessage().engine().name().empty();
102
88
if (is_engine_set)
104
create_info().db_type=
105
plugin::StorageEngine::findByName(*getSession(), createTableMessage().engine().name());
91
plugin::StorageEngine::findByName(*session, create_table_message.engine().name());
107
if (create_info().db_type == NULL)
93
if (create_info.db_type == NULL)
109
my_error(createTableMessage().engine().name(), ER_UNKNOWN_STORAGE_ENGINE, MYF(0));
95
my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0),
96
create_table_message.engine().name().c_str());
116
103
assert(select_lex->db);
118
105
/* Chicken/Egg... we need to search for the table, to know if the table exists, so we can build a full identifier from it */
119
message::table::shared_ptr original_table_message;
106
message::Table original_table_message;
121
identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
122
if (plugin::StorageEngine::getTableDefinition(*getSession(), identifier, original_table_message) != EEXIST)
108
TableIdentifier identifier(first_table->db, first_table->table_name);
109
if (plugin::StorageEngine::getTableDefinition(*session, identifier, original_table_message) != EEXIST)
124
my_error(ER_BAD_TABLE_ERROR, identifier);
111
my_error(ER_BAD_TABLE_ERROR, MYF(0), identifier.getSQLPath().c_str());
128
if (not create_info().db_type)
115
if (not create_info.db_type)
130
create_info().db_type=
131
plugin::StorageEngine::findByName(*getSession(), original_table_message->engine().name());
118
plugin::StorageEngine::findByName(*session, original_table_message.engine().name());
133
if (not create_info().db_type)
120
if (not create_info.db_type)
135
my_error(ER_BAD_TABLE_ERROR, identifier);
122
my_error(ER_BAD_TABLE_ERROR, MYF(0), identifier.getSQLPath().c_str());
141
128
if (not validateCreateTableOption())
144
if (getSession()->inTransaction())
146
my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
150
if (not (need_start_waiting= not getSession()->wait_if_global_read_lock(0, 1)))
133
/* ALTER TABLE ends previous transaction */
134
if (not session->endActiveTransaction())
139
if (not (need_start_waiting= ! wait_if_global_read_lock(session, 0, 1)))
154
if (original_table_message->type() == message::Table::STANDARD )
145
if (original_table_message.type() == message::Table::STANDARD )
156
identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName());
157
identifier::Table new_identifier(select_lex->db ? select_lex->db : first_table->getSchemaName(),
158
getSession()->lex->name.str ? getSession()->lex->name.str : first_table->getTableName());
147
TableIdentifier identifier(first_table->db, first_table->table_name);
148
TableIdentifier new_identifier(select_lex->db ? select_lex->db : first_table->db,
149
session->lex->name.str ? session->lex->name.str : first_table->table_name);
160
res= alter_table(getSession(),
151
res= alter_table(session,
164
*original_table_message,
165
createTableMessage(),
155
original_table_message,
156
create_table_message,
168
159
select_lex->order_list.elements,
169
(Order *) select_lex->order_list.first,
170
getSession()->lex->ignore);
160
(order_st *) select_lex->order_list.first,
161
session->lex->ignore);
174
identifier::Table catch22(first_table->getSchemaName(), first_table->getTableName());
175
Table *table= getSession()->find_temporary_table(catch22);
165
Table *table= session->find_temporary_table(first_table);
178
identifier::Table identifier(first_table->getSchemaName(), first_table->getTableName(), table->getMutableShare()->getPath());
179
identifier::Table new_identifier(select_lex->db ? select_lex->db : first_table->getSchemaName(),
180
getSession()->lex->name.str ? getSession()->lex->name.str : first_table->getTableName(),
181
table->getMutableShare()->getPath());
168
TableIdentifier identifier(first_table->db, first_table->table_name, table->getMutableShare()->getPath());
169
TableIdentifier new_identifier(select_lex->db ? select_lex->db : first_table->db,
170
session->lex->name.str ? session->lex->name.str : first_table->table_name,
171
table->getMutableShare()->getPath());
183
res= alter_table(getSession(),
173
res= alter_table(session,
187
*original_table_message,
188
createTableMessage(),
177
original_table_message,
178
create_table_message,
191
181
select_lex->order_list.elements,
192
(Order *) select_lex->order_list.first,
193
getSession()->lex->ignore);
182
(order_st *) select_lex->order_list.first,
183
session->lex->ignore);
346
331
new_create_list.push_back(def);
347
332
alter_it.rewind(); /* Change default if ALTER */
348
333
AlterColumn *alter;
350
334
while ((alter= alter_it++))
352
336
if (! my_strcasecmp(system_charset_info,field->field_name, alter->name))
358
341
if (def->sql_type == DRIZZLE_TYPE_BLOB)
360
343
my_error(ER_BLOB_CANT_HAVE_DEFAULT, MYF(0), def->change);
364
346
if ((def->def= alter->def))
366
348
/* Use new default */
367
349
def->flags&= ~NO_DEFAULT_VALUE_FLAG;
371
352
def->flags|= NO_DEFAULT_VALUE_FLAG;
373
353
alter_it.remove();
379
358
while ((def= def_it++)) /* Add new columns */
381
360
if (def->change && ! def->field)
383
362
my_error(ER_BAD_FIELD_ERROR, MYF(0), def->change, table->getMutableShare()->getTableName());
387
If we have been given a field which has no default value, and is not null then we need to bail.
366
Check that the DATE/DATETIME not null field we are going to add is
367
either has a default value or the '0000-00-00' is allowed by the
369
If the '0000-00-00' value isn't allowed then raise the error_if_not_empty
370
flag to allow ALTER Table only if the table to be altered is empty.
389
if (not (~def->flags & (NO_DEFAULT_VALUE_FLAG | NOT_NULL_FLAG)) and not def->change)
372
if ((def->sql_type == DRIZZLE_TYPE_DATE ||
373
def->sql_type == DRIZZLE_TYPE_DATETIME) &&
374
! alter_info->datetime_field &&
375
! (~def->flags & (NO_DEFAULT_VALUE_FLAG | NOT_NULL_FLAG)))
377
alter_info->datetime_field= def;
391
378
alter_info->error_if_not_empty= true;
393
380
if (! def->after)
395
381
new_create_list.push_back(def);
397
382
else if (def->after == first_keyword)
399
383
new_create_list.push_front(def);
403
386
CreateField *find;
404
387
find_it.rewind();
406
388
while ((find= find_it++)) /* Add new columns */
408
if (not my_strcasecmp(system_charset_info,def->after, find->field_name))
390
if (! my_strcasecmp(system_charset_info,def->after, find->field_name))
414
395
my_error(ER_BAD_FIELD_ERROR, MYF(0), def->after, table->getMutableShare()->getTableName());
418
398
find_it.after(def); /* Put element after this */
421
400
XXX: hack for Bug#28427.
422
401
If column order has changed, force OFFLINE ALTER Table
563
533
new_key_list.push_back(key);
567
/* Copy over existing foreign keys */
568
for (int32_t j= 0; j < original_proto.fk_constraint_size(); j++)
572
while ((drop= drop_it++))
574
if (drop->type == AlterDrop::FOREIGN_KEY &&
575
! my_strcasecmp(system_charset_info, original_proto.fk_constraint(j).name().c_str(), drop->name))
586
message::Table::ForeignKeyConstraint *pfkey= table_message.add_fk_constraint();
587
*pfkey= original_proto.fk_constraint(j);
592
538
while ((key= key_it++)) /* Add new keys */
594
if (key->type == Key::FOREIGN_KEY)
596
if (((Foreign_key *)key)->validate(new_create_list))
601
Foreign_key *fkey= (Foreign_key*)key;
602
add_foreign_key_to_table_message(&table_message,
540
if (key->type == Key::FOREIGN_KEY &&
541
((Foreign_key *)key)->validate(new_create_list))
612
543
if (key->type != Key::FOREIGN_KEY)
613
544
new_key_list.push_back(key);
615
545
if (key->name.str && is_primary_key_name(key->name.str))
617
547
my_error(ER_WRONG_NAME_FOR_INDEX,
625
/* Fix names of foreign keys being added */
626
for (int j= 0; j < table_message.fk_constraint_size(); j++)
628
if (! table_message.fk_constraint(j).has_name())
630
std::string name(table->getMutableShare()->getTableName());
633
name.append("_ibfk_");
634
snprintf(number, sizeof(number), "%d", j+1);
637
message::Table::ForeignKeyConstraint *pfkey= table_message.mutable_fk_constraint(j);
638
pfkey->set_name(name);
642
555
if (alter_info->drop_list.elements)
644
557
my_error(ER_CANT_DROP_FIELD_OR_KEY,
646
559
alter_info->drop_list.head()->name);
650
562
if (alter_info->alter_list.elements)
652
564
my_error(ER_CANT_DROP_FIELD_OR_KEY,
654
566
alter_info->alter_list.head()->name);
658
570
if (not table_message.options().has_comment()
659
571
&& table->getMutableShare()->hasComment())
661
572
table_options->set_comment(table->getMutableShare()->getComment());
664
574
if (table->getShare()->getType())
666
576
table_message.set_type(message::Table::TEMPORARY);
669
table_message.set_creation_timestamp(table->getShare()->getTableMessage()->creation_timestamp());
670
table_message.set_version(table->getShare()->getTableMessage()->version());
671
table_message.set_uuid(table->getShare()->getTableMessage()->uuid());
579
table_message.set_creation_timestamp(table->getShare()->getTableProto()->creation_timestamp());
581
table_message.set_update_timestamp(time(NULL));
674
584
alter_info->create_list.swap(new_create_list);
675
585
alter_info->key_list.swap(new_key_list);
677
588
size_t num_engine_options= table_message.engine().options_size();
678
589
size_t original_num_engine_options= original_proto.engine().options_size();
723
634
We set this flag so that ha_innobase::open and ::external_lock() do
724
635
not complain when we lock the table
726
session->setDoingTablespaceOperation(true);
727
if (not (table= session->openTableLock(table_list, TL_WRITE)))
637
session->tablespace_op= true;
638
if (!(table= session->openTableLock(table_list, TL_WRITE)))
729
session->setDoingTablespaceOperation(false);
640
session->tablespace_op= false;
735
error= table->cursor->ha_discard_or_import_tablespace(discard);
737
session->set_proc_info("end");
742
/* The ALTER Table is always in its own transaction */
743
error= transaction_services.autocommitOrRollback(*session, false);
744
if (not session->endActiveTransaction())
750
write_bin_log(session, *session->getQueryString());
754
(void) transaction_services.autocommitOrRollback(*session, error);
755
session->setDoingTablespaceOperation(false);
644
error= table->cursor->ha_discard_or_import_tablespace(discard);
646
session->set_proc_info("end");
651
/* The ALTER Table is always in its own transaction */
652
error= transaction_services.autocommitOrRollback(session, false);
653
if (! session->endActiveTransaction())
657
write_bin_log(session, session->query.c_str());
660
(void) transaction_services.autocommitOrRollback(session, error);
661
session->tablespace_op=false;
996
903
while the fact that the table is still open gives us protection
997
904
from concurrent DDL statements.
1000
boost::mutex::scoped_lock scopedLock(table::Cache::singleton().mutex()); /* DDL wait for/blocker */
1001
wait_while_table_is_used(session, table, HA_EXTRA_FORCE_REOPEN);
906
pthread_mutex_lock(&LOCK_open); /* DDL wait for/blocker */
907
wait_while_table_is_used(session, table, HA_EXTRA_FORCE_REOPEN);
908
pthread_mutex_unlock(&LOCK_open);
1003
909
error= table->cursor->ha_enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
1005
910
/* COND_refresh will be signaled in close_thread_tables() */
1010
boost::mutex::scoped_lock scopedLock(table::Cache::singleton().mutex()); /* DDL wait for/blocker */
1011
wait_while_table_is_used(session, table, HA_EXTRA_FORCE_REOPEN);
1013
error= table->cursor->ha_disable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
913
pthread_mutex_lock(&LOCK_open); /* DDL wait for/blocker */
914
wait_while_table_is_used(session, table, HA_EXTRA_FORCE_REOPEN);
915
pthread_mutex_unlock(&LOCK_open);
916
error=table->cursor->ha_disable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
1015
917
/* COND_refresh will be signaled in close_thread_tables() */
1019
925
if (error == HA_ERR_WRONG_COMMAND)
1022
928
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
1023
929
ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA),
1027
boost::mutex::scoped_lock scopedLock(table::Cache::singleton().mutex()); /* Lock to remove all instances of table from table cache before ALTER */
933
pthread_mutex_lock(&LOCK_open); /* Lock to remove all instances of table from table cache before ALTER */
1029
935
Unlike to the above case close_cached_table() below will remove ALL
1030
936
instances of Table from table cache (it will also remove table lock
1031
937
held by this thread). So to make actual table renaming and writing
1032
938
to binlog atomic we have to put them into the same critical section
1033
protected by table::Cache::singleton().mutex() mutex. This also removes gap for races between
1034
access() and rename_table() calls.
939
protected by LOCK_open mutex. This also removes gap for races between
940
access() and mysql_rename_table() calls.
1037
if (not error && not (original_table_identifier == new_table_identifier))
943
if (error == 0 && not (original_table_identifier == new_table_identifier))
1039
945
session->set_proc_info("rename");
1256
1180
if (new_table->hasShare())
1258
delete new_table->getMutableShare();
1182
assert(new_table->getShare()->newed);
1183
delete new_table->s;
1265
boost::mutex::scoped_lock scopedLock(table::Cache::singleton().mutex()); /* ALTER TABLE */
1267
Data is copied. Now we:
1268
1) Wait until all other threads close old version of table.
1269
2) Close instances of table open by this thread and replace them
1270
with exclusive name-locks.
1271
3) Rename the old table to a temp name, rename the new one to the
1273
4) If we are under LOCK TABLES and don't do ALTER Table ... RENAME
1274
we reopen new version of table.
1275
5) Write statement to the binary log.
1276
6) If we are under LOCK TABLES and do ALTER Table ... RENAME we
1277
remove name-locks from list of open tables and table cache.
1278
7) If we are not not under LOCK TABLES we rely on close_thread_tables()
1279
call to remove name-locks from table cache and list of open table.
1282
session->set_proc_info("rename result table");
1284
snprintf(old_name, sizeof(old_name), "%s2-%lx-%"PRIx64, TMP_FILE_PREFIX, (unsigned long) current_pid, session->thread_id);
1286
my_casedn_str(files_charset_info, old_name);
1288
wait_while_table_is_used(session, table, HA_EXTRA_PREPARE_FOR_RENAME);
1289
session->close_data_files_and_morph_locks(original_table_identifier);
1294
This leads to the storage engine (SE) not being notified for renames in
1295
rename_table(), because we just juggle with the FRM and nothing
1296
more. If we have an intermediate table, then we notify the SE that
1297
it should become the actual table. Later, we will recycle the old table.
1298
However, in case of ALTER Table RENAME there might be no intermediate
1299
table. This is when the old and new tables are compatible, according to
1300
compare_table(). Then, we need one additional call to
1302
identifier::Table original_table_to_drop(original_table_identifier.getSchemaName(),
1303
old_name, create_proto.type() != message::Table::TEMPORARY ? message::Table::INTERNAL :
1304
message::Table::TEMPORARY);
1306
drizzled::error_t rename_error= EE_OK;
1307
if (rename_table(*session, original_engine, original_table_identifier, original_table_to_drop))
1190
pthread_mutex_lock(&LOCK_open); /* ALTER TABLE */
1193
Data is copied. Now we:
1194
1) Wait until all other threads close old version of table.
1195
2) Close instances of table open by this thread and replace them
1196
with exclusive name-locks.
1197
3) Rename the old table to a temp name, rename the new one to the
1199
4) If we are under LOCK TABLES and don't do ALTER Table ... RENAME
1200
we reopen new version of table.
1201
5) Write statement to the binary log.
1202
6) If we are under LOCK TABLES and do ALTER Table ... RENAME we
1203
remove name-locks from list of open tables and table cache.
1204
7) If we are not not under LOCK TABLES we rely on close_thread_tables()
1205
call to remove name-locks from table cache and list of open table.
1208
session->set_proc_info("rename result table");
1210
snprintf(old_name, sizeof(old_name), "%s2-%lx-%"PRIx64, TMP_FILE_PREFIX, (unsigned long) current_pid, session->thread_id);
1212
my_casedn_str(files_charset_info, old_name);
1214
wait_while_table_is_used(session, table, HA_EXTRA_PREPARE_FOR_RENAME);
1215
session->close_data_files_and_morph_locks(original_table_identifier);
1220
This leads to the storage engine (SE) not being notified for renames in
1221
mysql_rename_table(), because we just juggle with the FRM and nothing
1222
more. If we have an intermediate table, then we notify the SE that
1223
it should become the actual table. Later, we will recycle the old table.
1224
However, in case of ALTER Table RENAME there might be no intermediate
1225
table. This is when the old and new tables are compatible, according to
1226
compare_table(). Then, we need one additional call to
1228
TableIdentifier original_table_to_drop(original_table_identifier.getSchemaName(),
1229
old_name, message::Table::TEMPORARY);
1231
if (mysql_rename_table(*session, original_engine, original_table_identifier, original_table_to_drop))
1234
quick_rm_table(*session, new_table_as_temporary);
1238
if (mysql_rename_table(*session, new_engine, new_table_as_temporary, new_table_identifier) != 0)
1309
error= ER_ERROR_ON_RENAME;
1310
plugin::StorageEngine::dropTable(*session, new_table_as_temporary);
1240
/* Try to get everything back. */
1243
quick_rm_table(*session, new_table_identifier);
1245
quick_rm_table(*session, new_table_as_temporary);
1247
mysql_rename_table(*session, original_engine, original_table_to_drop, original_table_identifier);
1314
if (rename_table(*session, new_engine, new_table_as_temporary, new_table_identifier) != 0)
1316
/* Try to get everything back. */
1317
rename_error= ER_ERROR_ON_RENAME;
1319
plugin::StorageEngine::dropTable(*session, new_table_identifier);
1321
plugin::StorageEngine::dropTable(*session, new_table_as_temporary);
1323
rename_table(*session, original_engine, original_table_to_drop, original_table_identifier);
1327
plugin::StorageEngine::dropTable(*session, original_table_to_drop);
1334
An error happened while we were holding exclusive name-lock on table
1335
being altered. To be safe under LOCK TABLES we should remove placeholders
1336
from list of open tables list and table cache.
1338
session->unlink_open_table(table);
1251
quick_rm_table(*session, original_table_to_drop);
1258
An error happened while we were holding exclusive name-lock on table
1259
being altered. To be safe under LOCK TABLES we should remove placeholders
1260
from list of open tables list and table cache.
1262
session->unlink_open_table(table);
1263
pthread_mutex_unlock(&LOCK_open);
1268
pthread_mutex_unlock(&LOCK_open);
1344
1270
session->set_proc_info("end");
1346
write_bin_log(session, *session->getQueryString());
1272
write_bin_log(session, session->query.c_str());
1347
1273
table_list->table= NULL;
1506
1433
found_count=delete_count=0;
1512
if (to->getShare()->hasPrimaryKey() && to->cursor->primary_key_is_clustered())
1437
if (to->getShare()->hasPrimaryKey() && to->cursor->primary_key_is_clustered())
1439
char warn_buff[DRIZZLE_ERRMSG_SIZE];
1440
snprintf(warn_buff, sizeof(warn_buff),
1441
_("order_st BY ignored because there is a user-defined clustered "
1442
"index in the table '%-.192s'"),
1443
from->getMutableShare()->getTableName());
1444
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR,
1449
from->sort.io_cache= new internal::IO_CACHE;
1451
memset(&tables, 0, sizeof(tables));
1453
tables.alias= tables.table_name= const_cast<char *>(from->getMutableShare()->getTableName());
1454
tables.db= const_cast<char *>(from->getMutableShare()->getSchemaName());
1457
if (session->lex->select_lex.setup_ref_array(session, order_num) ||
1458
setup_order(session, session->lex->select_lex.ref_pointer_array,
1459
&tables, fields, all_fields, order) ||
1460
!(sortorder= make_unireg_sortorder(order, &length, NULL)) ||
1461
(from->sort.found_records= filesort(session, from, sortorder, length,
1462
(optimizer::SqlSelect *) 0, HA_POS_ERROR,
1463
1, &examined_rows)) ==
1514
char warn_buff[DRIZZLE_ERRMSG_SIZE];
1515
snprintf(warn_buff, sizeof(warn_buff),
1516
_("order_st BY ignored because there is a user-defined clustered "
1517
"index in the table '%-.192s'"),
1518
from->getMutableShare()->getTableName());
1519
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR,
1471
/* Tell handler that we have values for all columns in the to table */
1472
to->use_all_columns();
1473
info.init_read_record(session, from, (optimizer::SqlSelect *) 0, 1, true);
1475
to->cursor->extra(HA_EXTRA_IGNORE_DUP_KEY);
1476
session->row_count= 0;
1477
to->restoreRecordAsDefault(); // Create empty record
1478
while (!(error=info.read_record(&info)))
1480
if (session->killed)
1482
session->send_kill_message();
1486
session->row_count++;
1487
/* Return error if source table isn't empty. */
1488
if (error_if_not_empty)
1493
if (to->next_number_field)
1495
if (auto_increment_field_copied)
1496
to->auto_increment_field_not_null= true;
1524
FileSort filesort(*session);
1525
from->sort.io_cache= new internal::IO_CACHE;
1528
tables.setTableName(const_cast<char *>(from->getMutableShare()->getTableName()));
1529
tables.alias= const_cast<char *>(tables.getTableName());
1530
tables.setSchemaName(const_cast<char *>(from->getMutableShare()->getSchemaName()));
1533
if (session->lex->select_lex.setup_ref_array(session, order_num) ||
1534
setup_order(session, session->lex->select_lex.ref_pointer_array,
1535
&tables, fields, all_fields, order) ||
1536
!(sortorder= make_unireg_sortorder(order, &length, NULL)) ||
1537
(from->sort.found_records= filesort.run(from, sortorder, length,
1538
(optimizer::SqlSelect *) 0, HA_POS_ERROR,
1539
1, examined_rows)) == HA_POS_ERROR)
1546
/* Tell handler that we have values for all columns in the to table */
1547
to->use_all_columns();
1549
error= info.init_read_record(session, from, (optimizer::SqlSelect *) 0, 1, true);
1498
to->next_number_field->reset();
1501
for (CopyField *copy_ptr=copy ; copy_ptr != copy_end ; copy_ptr++)
1503
copy_ptr->do_copy(copy_ptr);
1505
prev_insert_id= to->cursor->next_insert_id;
1506
error= to->cursor->insertRecord(to->record[0]);
1507
to->auto_increment_field_not_null= false;
1552
to->print_error(errno, MYF(0));
1559
to->cursor->extra(HA_EXTRA_IGNORE_DUP_KEY);
1562
session->row_count= 0;
1563
to->restoreRecordAsDefault(); // Create empty record
1564
while (not (error=info.read_record(&info)))
1566
if (session->getKilled())
1568
session->send_kill_message();
1572
session->row_count++;
1573
/* Return error if source table isn't empty. */
1574
if (error_if_not_empty)
1579
if (to->next_number_field)
1581
if (auto_increment_field_copied)
1582
to->auto_increment_field_not_null= true;
1584
to->next_number_field->reset();
1587
for (CopyField *copy_ptr= copy; copy_ptr != copy_end ; copy_ptr++)
1589
if (not copy->to_field->hasDefault() and copy->from_null_ptr and *copy->from_null_ptr & copy->from_bit)
1591
copy->to_field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
1592
ER_WARN_DATA_TRUNCATED, 1);
1593
copy->to_field->reset();
1598
copy_ptr->do_copy(copy_ptr);
1606
prev_insert_id= to->cursor->next_insert_id;
1607
error= to->cursor->insertRecord(to->record[0]);
1608
to->auto_increment_field_not_null= false;
1512
to->cursor->is_fatal_error(error, HA_CHECK_DUP))
1612
if (!ignore || to->cursor->is_fatal_error(error, HA_CHECK_DUP))
1614
to->print_error(error, MYF(0));
1617
to->cursor->restore_auto_increment(prev_insert_id);
1514
to->print_error(error, MYF(0));
1517
to->cursor->restore_auto_increment(prev_insert_id);
1626
info.end_read_record();
1627
from->free_io_cache();
1628
delete [] copy; // This is never 0
1630
if (to->cursor->ha_end_bulk_insert() && error <= 0)
1632
to->print_error(errno, MYF(0));
1635
to->cursor->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
1638
Ensure that the new table is saved properly to disk so that we
1641
if (transaction_services.autocommitOrRollback(*session, false))
1644
if (not session->endActiveTransaction())
1649
session->setAbortOnWarning(false);
1526
info.end_read_record();
1527
from->free_io_cache();
1528
delete [] copy; // This is never 0
1530
if (to->cursor->ha_end_bulk_insert() && error <= 0)
1532
to->print_error(errno, MYF(0));
1535
to->cursor->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
1538
Ensure that the new table is saved properly to disk so that we
1541
if (transaction_services.autocommitOrRollback(session, false))
1543
if (! session->endActiveTransaction())
1547
session->abort_on_warning= 0;
1650
1548
from->free_io_cache();
1651
1549
*copied= found_count;
1652
1550
*deleted=delete_count;
1653
1551
to->cursor->ha_release_auto_increment();
1655
if (to->cursor->ha_external_lock(session, F_UNLCK))
1552
if (to->cursor->ha_external_lock(session,F_UNLCK))
1660
1555
return(error > 0 ? -1 : 0);
1663
static Table *open_alter_table(Session *session, Table *table, identifier::Table &identifier)
1559
create_temporary_table(Session *session,
1560
TableIdentifier &identifier,
1561
HA_CREATE_INFO *create_info,
1562
message::Table &create_proto,
1563
AlterInfo *alter_info)
1568
Create a table with a temporary name.
1569
We don't log the statement, it will be logged later.
1571
create_proto.set_name(identifier.getTableName());
1573
create_proto.mutable_engine()->set_name(create_info->db_type->getName());
1575
error= mysql_create_table(session,
1577
create_info, create_proto, alter_info, true, 0, false);
1582
static Table *open_alter_table(Session *session, Table *table, TableIdentifier &identifier)
1665
1584
Table *new_table;