Edgewall Software

Changes between Initial Version and Version 1 of Ticket #11497


Ignore:
Timestamp:
Feb 23, 2014, 7:07:39 AM (10 years ago)
Author:
Jun Omae
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #11497

    • Property Owner set to Jun Omae
    • Property Status newassigned
  • Ticket #11497 – Description

    initial v1  
    55It would be fast to use `DELETE FROM` for table with no `auto_increment` rather than `TRUNCATE TABLE`.
    66
    7 {{{#!diff
    8 diff --git a/trac/test.py b/trac/test.py
    9 index 69cdd4e..f98a029 100755
    10 --- a/trac/test.py
    11 +++ b/trac/test.py
    12 @@ -205,13 +205,19 @@ def reset_mysql_db(db, db_prop):
    13      dbname = os.path.basename(db_prop['path'])
    14      if dbname:
    15          cursor = db.cursor()
    16 -        cursor.execute('SELECT table_name FROM information_schema.tables '
    17 +        cursor.execute('SELECT table_name, auto_increment '
    18 +                       'FROM information_schema.tables '
    19                         'WHERE table_schema=%s', (dbname,))
    20          tables = cursor.fetchall()
    21 -        for table in tables:
    22 -            # TRUNCATE TABLE is prefered to DELETE FROM, as we need to reset
    23 -            # the auto_increment in MySQL.
    24 -            cursor.execute('TRUNCATE TABLE %s' % table)
    25 +        for table, auto_increment in tables:
    26 +            if auto_increment is None or auto_increment == 1:
    27 +                # If auto_increment is not used or it is 1, we use DELETE FROM
    28 +                # as we need not reset.
    29 +                cursor.execute('DELETE FROM %s' % table)
    30 +            else:
    31 +                # TRUNCATE TABLE is prefered to DELETE FROM, as we need to
    32 +                # reset the auto_increment in MySQL.
    33 +                cursor.execute('TRUNCATE TABLE %s' % table)
    34          db.commit()
    35          return tables
    36 
    37 }}}
     7Proposed changes can be found in [ca0130ae/jomae.git].
    388
    399Results;