Opened 10 years ago
Last modified 10 years ago
#11497 closed enhancement
Unit tests is very slow on MySQL 5.1 or later — at Initial Version
Reported by: | Jun Omae | Owned by: | |
---|---|---|---|
Priority: | normal | Milestone: | 0.12.6 |
Component: | database backend | Version: | |
Severity: | normal | Keywords: | test mysql |
Cc: | Branch: | ||
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
If database backend is MySQL 5.1 or later, unit tests is very slow.
reset_mysql_db
in trac/test.py
executes TRUNCATE TABLE
for tearDown of each test. This TRUNCATE TABLE
is very slow on MySQL 5.1 or later. We use TRUNCATE TABLE
because we need to reset auto_increment
value of tables.
It would be fast to use DELETE FROM
for table with no auto_increment
rather than TRUNCATE TABLE
.
-
trac/test.py
diff --git a/trac/test.py b/trac/test.py index 69cdd4e..f98a029 100755
a b def reset_mysql_db(db, db_prop): 205 205 dbname = os.path.basename(db_prop['path']) 206 206 if dbname: 207 207 cursor = db.cursor() 208 cursor.execute('SELECT table_name FROM information_schema.tables ' 208 cursor.execute('SELECT table_name, auto_increment ' 209 'FROM information_schema.tables ' 209 210 'WHERE table_schema=%s', (dbname,)) 210 211 tables = cursor.fetchall() 211 for table in tables: 212 # TRUNCATE TABLE is prefered to DELETE FROM, as we need to reset 213 # the auto_increment in MySQL. 214 cursor.execute('TRUNCATE TABLE %s' % table) 212 for table, auto_increment in tables: 213 if auto_increment is None or auto_increment == 1: 214 # If auto_increment is not used or it is 1, we use DELETE FROM 215 # as we need not reset. 216 cursor.execute('DELETE FROM %s' % table) 217 else: 218 # TRUNCATE TABLE is prefered to DELETE FROM, as we need to 219 # reset the auto_increment in MySQL. 220 cursor.execute('TRUNCATE TABLE %s' % table) 215 221 db.commit() 216 222 return tables 217 223
Results;
Before | After | |
---|---|---|
0.12-stable with MySQL 5.0.95 | 113.387s | 85.090s |
0.12-stable with MySQL 5.1.71 | 1359.702s | 323.143s |
0.12-stable with MySQL 5.5.35 | 788.180s | 253.629s |
Note:
See TracTickets
for help on using tickets.