354
352
static int rm_table_part2(Session *session, TableList *tables)
356
TransactionServices &transaction_services= TransactionServices::singleton();
358
354
TableList *table;
359
355
String wrong_tables;
361
357
bool foreign_key_error= false;
364
table::Cache::singleton().mutex().lock(); /* Part 2 of rm a table */
366
if (session->lock_table_names_exclusively(tables))
368
table::Cache::singleton().mutex().unlock();
372
/* Don't give warnings for not found errors, as we already generate notes */
373
session->no_warnings_for_error= 1;
375
for (table= tables; table; table= table->next_local)
377
const char *db=table->getSchemaName();
378
TableIdentifier identifier(table->getSchemaName(), table->getTableName());
380
plugin::StorageEngine *table_type;
382
error= session->drop_temporary_table(identifier);
386
// removed temporary table
390
tables->unlock_table_names();
391
table::Cache::singleton().mutex().unlock();
359
LOCK_open.lock(); /* Part 2 of rm a table */
362
If we have the table in the definition cache, we don't have to check the
363
.frm cursor to find if the table is a normal table (not view) and what
367
for (table= tables; table; table= table->next_local)
369
TableIdentifier identifier(table->db, table->table_name);
371
table->setDbType(NULL);
372
if ((share= TableShare::getShare(identifier)))
374
table->setDbType(share->db_type());
378
if (lock_table_names_exclusively(session, tables))
384
/* Don't give warnings for not found errors, as we already generate notes */
385
session->no_warnings_for_error= 1;
387
for (table= tables; table; table= table->next_local)
390
plugin::StorageEngine *table_type;
392
error= session->drop_temporary_table(table);
396
// removed temporary table
400
unlock_table_names(tables, NULL);
402
session->no_warnings_for_error= 0;
406
// temporary table not found
410
table_type= table->getDbType();
412
TableIdentifier identifier(db, table->table_name);
416
abort_locked_tables(session, identifier);
417
remove_table_from_cache(session, identifier,
418
RTFC_WAIT_OTHER_THREAD_FLAG |
419
RTFC_CHECK_KILLED_FLAG);
421
If the table was used in lock tables, remember it so that
422
unlock_table_names can free it
424
if ((locked_table= drop_locked_tables(session, identifier)))
425
table->table= locked_table;
430
unlock_table_names(tables, NULL);
392
432
session->no_warnings_for_error= 0;
396
// temporary table not found
400
table_type= table->getDbType();
404
abort_locked_tables(session, identifier);
405
table::Cache::singleton().removeTable(session, identifier,
406
RTFC_WAIT_OTHER_THREAD_FLAG |
407
RTFC_CHECK_KILLED_FLAG);
409
If the table was used in lock tables, remember it so that
410
unlock_table_names can free it
412
if ((locked_table= drop_locked_tables(session, identifier)))
413
table->table= locked_table;
415
if (session->getKilled())
418
tables->unlock_table_names();
419
table::Cache::singleton().mutex().unlock();
420
session->no_warnings_for_error= 0;
425
identifier.getPath();
427
if (table_type == NULL && not plugin::StorageEngine::doesTableExist(*session, identifier))
429
// Table was not found on disk and table can't be created from engine
430
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
431
ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR),
432
table->getTableName());
436
error= plugin::StorageEngine::dropTable(*session, identifier);
438
if ((error == ENOENT || error == HA_ERR_NO_SUCH_TABLE))
441
session->clear_error();
444
if (error == HA_ERR_ROW_IS_REFERENCED)
446
/* the table is referenced by a foreign key constraint */
447
foreign_key_error= true;
451
if (error == 0 || (foreign_key_error == false))
453
transaction_services.dropTable(session, string(db), string(table->getTableName()), true);
458
if (wrong_tables.length())
459
wrong_tables.append(',');
460
wrong_tables.append(String(table->getTableName(),system_charset_info));
464
It's safe to unlock table::Cache::singleton().mutex(): we have an exclusive lock
467
table::Cache::singleton().mutex().unlock();
437
identifier.getPath();
439
if (table_type == NULL && not plugin::StorageEngine::doesTableExist(*session, identifier))
441
// Table was not found on disk and table can't be created from engine
442
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
443
ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR),
448
error= plugin::StorageEngine::dropTable(*session, identifier);
450
if ((error == ENOENT || error == HA_ERR_NO_SUCH_TABLE))
453
session->clear_error();
456
if (error == HA_ERR_ROW_IS_REFERENCED)
458
/* the table is referenced by a foreign key constraint */
459
foreign_key_error= true;
463
if (error == 0 || (foreign_key_error == false))
464
write_bin_log_drop_table(session, true, db, table->table_name);
468
if (wrong_tables.length())
469
wrong_tables.append(',');
470
wrong_tables.append(String(table->table_name,system_charset_info));
474
It's safe to unlock LOCK_open: we have an exclusive lock
471
479
if (wrong_tables.length())