361
359
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();
361
LOCK_open.lock(); /* Part 2 of rm a table */
364
If we have the table in the definition cache, we don't have to check the
365
.frm cursor to find if the table is a normal table (not view) and what
369
for (table= tables; table; table= table->next_local)
371
TableIdentifier identifier(table->db, table->table_name);
373
table->setDbType(NULL);
374
if ((share= TableShare::getShare(identifier)))
376
table->setDbType(share->db_type());
380
if (lock_table_names_exclusively(session, tables))
386
/* Don't give warnings for not found errors, as we already generate notes */
387
session->no_warnings_for_error= 1;
389
for (table= tables; table; table= table->next_local)
392
plugin::StorageEngine *table_type;
394
error= session->drop_temporary_table(table);
398
// removed temporary table
402
unlock_table_names(tables, NULL);
404
session->no_warnings_for_error= 0;
408
// temporary table not found
412
table_type= table->getDbType();
414
TableIdentifier identifier(db, table->table_name);
418
abort_locked_tables(session, identifier);
419
remove_table_from_cache(session, identifier,
420
RTFC_WAIT_OTHER_THREAD_FLAG |
421
RTFC_CHECK_KILLED_FLAG);
423
If the table was used in lock tables, remember it so that
424
unlock_table_names can free it
426
if ((locked_table= drop_locked_tables(session, identifier)))
427
table->table= locked_table;
432
unlock_table_names(tables, NULL);
392
434
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();
439
identifier.getPath();
441
if (table_type == NULL && not plugin::StorageEngine::doesTableExist(*session, identifier))
443
// Table was not found on disk and table can't be created from engine
444
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
445
ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR),
450
error= plugin::StorageEngine::dropTable(*session, identifier);
452
if ((error == ENOENT || error == HA_ERR_NO_SUCH_TABLE))
455
session->clear_error();
458
if (error == HA_ERR_ROW_IS_REFERENCED)
460
/* the table is referenced by a foreign key constraint */
461
foreign_key_error= true;
465
if (error == 0 || (foreign_key_error == false))
467
transaction_services.dropTable(session, string(db), string(table->table_name), true);
472
if (wrong_tables.length())
473
wrong_tables.append(',');
474
wrong_tables.append(String(table->table_name,system_charset_info));
478
It's safe to unlock LOCK_open: we have an exclusive lock
471
483
if (wrong_tables.length())