#31275: Optimize MariaDB/MySQL sql_flush
-------------------------------------+-------------------------------------
               Reporter:  Adam       |          Owner:  nobody
  (Chainz) Johnson                   |
                   Type:             |         Status:  new
  Cleanup/optimization               |
              Component:  Database   |        Version:  master
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 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`.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31275>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/053.f0adde989786cb9400eae85a6ac77b83%40djangoproject.com.

Reply via email to