YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense alongwiththisprogram;ifnot,writetotheFreeSoftware
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
/* Out of memory when building list. */ if (unlikely(thd->is_error())) returnTRUE;
it.init(fk_list);
/* Loop over the set of foreign keys for which this table is a parent. */ while ((fk_info= it++))
{ if (!table->s->db.streq(*fk_info->referenced_db) ||
!table->s->table_name.streq(*fk_info->referenced_table) ||
!table->s->db.streq(*fk_info->foreign_db) ||
!table->s->table_name.streq(*fk_info->foreign_table)) break;
}
/* Table is parent in a non-self-referencing foreign key. */ if (fk_info)
{
my_error(ER_TRUNCATE_ILLEGAL_FK, MYF(0), fk_info_str(thd, fk_info)); returnTRUE;
}
/* If it is a temporary table, no need to take locks. */ if (!is_tmp_table)
{ /* We don't need to load triggers. */
DBUG_ASSERT(table_ref->trg_event_map == 0); /* Ourmetadatalockguaranteesthatnotransactionisreading orwritingintothetable.Yet,toopenawritecursorweneed athr_locklock.Allowtoopenbasetablesonly.
*/
table_ref->required_type= TABLE_TYPE_NORMAL; /* IgnorependingFLUSHTABLESsincewedon'twanttorelease theMDLlocktakenaboveandotherwisethereisnowayto waitforFLUSHTABLESindeadlock-freefashion.
*/
flags= MYSQL_OPEN_IGNORE_FLUSH; /* EventhoughwehaveanMDLlockonthetablehere,wedon't passMYSQL_OPEN_HAS_MDL_LOCKtoopen_and_lock_tables sincetotruncateaMERGEtable,wemustopenandlock mergechildren,andonthosewedon'thaveanMDLlock. ThusclearthetickettosatisfyMDLasserts.
*/
table_ref->mdl_request.ticket= NULL;
}
/* Open the table as it will handle some required preparations. */ if (open_and_lock_tables(thd, table_ref, FALSE, flags))
DBUG_RETURN(TRUNCATE_FAILED_SKIP_BINLOG);
/* Whether to truncate regardless of foreign keys. */ if (! (thd->variables.option_bits & OPTION_NO_FOREIGN_KEY_CHECKS)) if (fk_truncate_illegal_if_parent(thd, table_ref->table))
DBUG_RETURN(TRUNCATE_FAILED_SKIP_BINLOG);
/* Lock types are set in the parser. */
DBUG_ASSERT(table_ref->lock_type == TL_WRITE); /* The handler truncate protocol dictates a exclusive lock. */
DBUG_ASSERT(table_ref->mdl_request.type == MDL_EXCLUSIVE);
if (versioned)
{
my_error(ER_VERS_NOT_SUPPORTED, MYF(0), "TRUNCATE TABLE");
DBUG_RETURN(TRUE);
}
/* Astorageenginecanrecreateortruncatethetableonlyifthere arenoreferencestoitfromanywhere,i.e.nocachedTABLEinthe tablecache.
*/ if (thd->locked_tables_mode)
{
DEBUG_SYNC(thd, "upgrade_lock_for_truncate"); /* To remove the table from the cache we need an exclusive lock. */ if (wait_while_table_is_used(thd, table,
*hton_can_recreate ? HA_EXTRA_PREPARE_FOR_DROP : HA_EXTRA_NOT_USED))
DBUG_RETURN(TRUE);
m_ticket_downgrade= table->mdl_ticket; /* Close if table is going to be recreated. */ if (*hton_can_recreate)
close_all_tables_for_name(thd, table->s, HA_EXTRA_NOT_USED, NULL);
}
DBUG_RETURN(FALSE);
}
/* Initialize, or reinitialize in case of reexecution (SP). */
m_ticket_downgrade= NULL;
/* If it is a temporary table, no need to take locks. */ if (is_temporary_table(table_ref))
{ /* InRBR,thestatementisnotbinloggedifthetableistemporaryor tableisnotuptodateinbinlog.
*/
binlog_stmt= (!thd->is_binlog_format_row() &&
table_ref->table->s->using_binlog());
/* Noneedtoinvalidatethequerycache,querieswithtemporary tablesarenotinthecache.Noneedtowritetothebinary logafailedrow-by-rowdeleteevenifunderRBRasthetable mightnotexistontheslave.
*/
} else/* It's not a temporary table. */
{ bool hton_can_recreate;
#ifdef WITH_WSREP if (WSREP(thd) && wsrep_thd_is_local(thd))
{
wsrep::key_array keys; /* Do not start TOI if table is not found */ if (!wsrep_append_fk_parent_table(thd, table_ref, &keys))
{ if (keys.empty())
{ if (wsrep_to_isolation_begin(thd, table_ref->db.str, table_ref->table_name.str, NULL))
DBUG_RETURN(TRUE);
} else
{ if (wsrep_to_isolation_begin(thd, NULL, NULL, table_ref, NULL, &keys))
DBUG_RETURN(TRUE);
}
}
} #endif/* WITH_WSREP */
if (lock_table(thd, table_ref, &hton_can_recreate))
DBUG_RETURN(TRUE);
/* DDL is logged in statement format, regardless of binlog format. */ if (binlog_stmt)
error|= write_bin_log(thd, !error, thd->query(), thd->query_length());
/* Alockedtableticketwasupgradedtoaexclusivelock.Afterthe thequeryhasbeenwrittentothebinarylog,downgradethelock toasharedone.
*/ if (m_ticket_downgrade)
m_ticket_downgrade->downgrade_lock(MDL_SHARED_NO_READ_WRITE);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.