id,summary,reporter,owner,description,type,status,component,version,severity,resolution,keywords,cc,stage,has_patch,needs_docs,needs_tests,needs_better_patch,easy,ui_ux 31275,Optimize MariaDB/MySQL sql_flush,Adam Johnson,Masashi SHIBATA,"This was suggested as an extra feature for Django-MySQL by @jonatron in https://github.com/adamchainz/django-mysql/pull/611/files , but it would make more sense to make it in Django core. Currently MySQL's sql_flush emits TRUNCATE TABLE statements. These are relatively slow on small tables since they force recreation of the table on disk. The alternative, `DELETE FROM`, is faster. I can see a diference even for a single empty table locally (MariaDB 10.4): {{{ chainz@localhost [21]> truncate t2; Query OK, 0 rows affected (0.005 sec) chainz@localhost [22]> delete from t2; Query OK, 0 rows affected (0.000 sec) }}} `TransactionTestCase` uses sql_flush, via the flush management command, to reset the database. Most test suites don't use very large tables, so using `DELETE FROM` should normally be faster in this case. Optimizing it MySQL to use `DELETE FROM` for flushing, at least for tables up to a certain size (1000 rows or similar heuristic) could save lot of time when using `TransactionTestCase`.",Cleanup/optimization,closed,"Database layer (models, ORM)",dev,Normal,fixed,,Simon Charette,Ready for checkin,1,0,0,0,0,0