Merge pull request #8437 from sminnee/faster-cleartable-ss4

FIX: Use DELETE FROM instead of TRUNCATE for clearTable
This commit is contained in:
Loz Calver 2018-10-11 12:32:31 +02:00 committed by GitHub
commit 26f2044533
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -523,4 +523,24 @@ class MySQLDatabase extends Database
{ {
return 'RAND()'; return 'RAND()';
} }
/**
* Clear all data in a given table
*
* @param string $table Name of table
*/
public function clearTable($table)
{
$this->query("DELETE FROM \"$table\"");
// Check if resetting the auto-increment is needed
$autoIncrement = $this->preparedQuery(
'SELECT "AUTO_INCREMENT" FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?',
[ $this->getSelectedDatabase(), $table]
)->value();
if ($autoIncrement > 1) {
$this->query("ALTER TABLE \"$table\" AUTO_INCREMENT = 1");
}
}
} }