Description:
According to the docs, truncating an innodb table that is referenced in a foreign key of another table uses a "slow" delete in which every row must be checked for references. For large tables, this is very painful.
A common use-case for foreign keys is the parent/child schema paradigm in which the child has a single foreign key to the parent. Truncating the child table is very fast since it is not referenced by any other tables. However, the parent table invokes the slow delete even though it is not possible for a foreign key to fail after the child has been truncated.
I propose adding in a check at the beginning of truncate to perform a fast delete if all referencing tables are empty.
There should be no MVCC/transaction issues since:
"Truncate operations are not transaction-safe; an error occurs when attempting one in the course of an active transaction or active table lock."
How to repeat:
create a parent table
create a child table with a not null foreign key to parent
insert 1,000,000 rows into parent
insert 1,000,000 row into child
truncate table child; <- fast
truncate table parent; <- slow