From: anthonybaxter Date: Tue, 7 Oct 2003 07:17:54 +0000 (+0000) Subject: make the RDBMS common backend and the SQLite and MYsql backend create X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=ea6ee3fd907cd054a88e44a1ffc6dca4eeba8cdc;p=roundup.git make the RDBMS common backend and the SQLite and MYsql backend create and drop indexes for the basic columns - index multilinks, index id and retired columns of all class tables. git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1903 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/doc/debugging.txt b/doc/debugging.txt new file mode 100644 index 0000000..52b37cc --- /dev/null +++ b/doc/debugging.txt @@ -0,0 +1,31 @@ +Debugging Flags +--------------- + +Roundup uses a number of debugging environment variables to help you +figure out what the heck it's doing. + +HYPERDBDEBUG +============ + +This environment variable should be set to a filename - the hyperdb will +write debugging information for various events (including, for instance, +the SQL used). + +This is only obeyed when python is _not_ running in -O mode. + +HYPERDBTRACE +============ + +This environment variable should be set to a filename - the hyperdb will +write a timestamp entry for various events. This appears to be suffering +rather extreme bit-rot and may go away soon. + +This is only obeyed when python is _not_ running in -O mode. + +SENDMAILDEBUG +============= + +Set to a filename and roundup will write a copy of each email message +that it sends to that file. This environment variable is independent of +the python -O flag. + diff --git a/roundup/backends/back_mysql.py b/roundup/backends/back_mysql.py index ef3d538..0e1d085 100644 --- a/roundup/backends/back_mysql.py +++ b/roundup/backends/back_mysql.py @@ -63,6 +63,7 @@ class Database(Database): self.database_schema = {} self.sql("CREATE TABLE schema (schema TEXT) TYPE=BDB") self.sql("CREATE TABLE ids (name varchar(255), num INT) TYPE=BDB") + self.sql("CREATE INDEX ids_name_idx on ids(name)") def close(self): try: diff --git a/roundup/backends/back_sqlite.py b/roundup/backends/back_sqlite.py index 8d2e57f..d0091b6 100644 --- a/roundup/backends/back_sqlite.py +++ b/roundup/backends/back_sqlite.py @@ -1,4 +1,4 @@ -# $Id: back_sqlite.py,v 1.9 2003-03-06 06:03:51 richard Exp $ +# $Id: back_sqlite.py,v 1.10 2003-10-07 07:17:54 anthonybaxter Exp $ __doc__ = ''' See https://pysqlite.sourceforge.net/ for pysqlite info ''' @@ -32,6 +32,7 @@ class Database(Database): self.database_schema = {} self.cursor.execute('create table schema (schema varchar)') self.cursor.execute('create table ids (name varchar, num integer)') + self.cursor.execute('create index ids_name_idx on ids(name)') def close(self): ''' Close off the connection. diff --git a/roundup/backends/rdbms_common.py b/roundup/backends/rdbms_common.py index 5d67abc..4cdb2da 100644 --- a/roundup/backends/rdbms_common.py +++ b/roundup/backends/rdbms_common.py @@ -1,4 +1,4 @@ -# $Id: rdbms_common.py,v 1.62 2003-09-08 20:39:18 jlgijsbers Exp $ +# $Id: rdbms_common.py,v 1.63 2003-10-07 07:17:54 anthonybaxter Exp $ ''' Relational database (SQL) backend common code. Basics: @@ -199,7 +199,18 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database): old_has[name] = 1 if not new_has(name) and isinstance(prop, Multilink): # it's a multilink, and it's been removed - drop the old - # table + # table. First drop indexes. + index_sqls = [ 'drop index %s_%s_l_idx'%(spec.classname, ml), + 'drop index %s_%s_n_idx'%(spec.classname, ml) ] + for index_sql in index_sqls: + if __debug__: + print >>hyperdb.DEBUG, 'drop_index', (self, index_sql) + try: + self.cursor.execute(index_sql) + except: + # The database may not actually have any indexes. + # assume the worst. + pass sql = 'drop table %s_%s'%(spec.classname, prop) if __debug__: print >>hyperdb.DEBUG, 'update_class', (self, sql) @@ -231,9 +242,19 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database): self.cursor.execute(sql) olddata = self.cursor.fetchall() - # drop the old table + # drop the old table - indexes first + index_sqls = [ 'drop index _%s_id_idx'%cn, + 'drop index _%s_retired_idx'%cn ] + for index_sql in index_sqls: + if __debug__: + print >>hyperdb.DEBUG, 'drop_index', (self, index_sql) + try: + self.cursor.execute(index_sql) + except: + # The database may not actually have any indexes. + # assume the worst. + pass self.cursor.execute('drop table _%s'%cn) - # create the new table self.create_class_table(spec) @@ -263,6 +284,16 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database): if __debug__: print >>hyperdb.DEBUG, 'create_class', (self, sql) self.cursor.execute(sql) + index_sql1 = 'create index _%s_id_idx on _%s(id)'%( + spec.classname, spec.classname) + if __debug__: + print >>hyperdb.DEBUG, 'create_index', (self, index_sql1) + self.cursor.execute(index_sql1) + index_sql2 = 'create index _%s_retired_idx on _%s(__retired__)'%( + spec.classname, spec.classname) + if __debug__: + print >>hyperdb.DEBUG, 'create_index', (self, index_sql2) + self.cursor.execute(index_sql2) return cols, mls @@ -277,6 +308,11 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database): if __debug__: print >>hyperdb.DEBUG, 'create_class', (self, sql) self.cursor.execute(sql) + index_sql = 'create index %s_journ_idx on %s__journal(nodeid)'%( + spec.classname, spec.classname) + if __debug__: + print >>hyperdb.DEBUG, 'create_index', (self, index_sql) + self.cursor.execute(index_sql) def create_multilink_table(self, spec, ml): ''' Create a multilink table for the "ml" property of the class @@ -287,6 +323,16 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database): if __debug__: print >>hyperdb.DEBUG, 'create_class', (self, sql) self.cursor.execute(sql) + index_sql = 'create index %s_%s_l_idx on %s_%s(linkid)'%( + spec.classname, ml, spec.classname, ml) + if __debug__: + print >>hyperdb.DEBUG, 'create_index', (self, index_sql) + self.cursor.execute(index_sql) + index_sql = 'create index %s_%s_n_idx on %s_%s(nodeid)'%( + spec.classname, ml, spec.classname, ml) + if __debug__: + print >>hyperdb.DEBUG, 'create_index', (self, index_sql) + self.cursor.execute(index_sql) def create_class(self, spec): ''' Create a database table according to the given spec. @@ -316,17 +362,42 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database): if isinstance(prop, Multilink): mls.append(col) + index_sqls = [ 'drop index _%s_id_idx'%cn, + 'drop index _%s_retired_idx'%cn, + 'drop index %s_journ_idx'%cn ] + for index_sql in index_sqls: + if __debug__: + print >>hyperdb.DEBUG, 'drop_index', (self, index_sql) + try: + self.cursor.execute(index_sql) + except: + # The database may not actually have any indexes. + # assume the worst. + pass + sql = 'drop table _%s'%spec.classname if __debug__: print >>hyperdb.DEBUG, 'drop_class', (self, sql) self.cursor.execute(sql) - sql = 'drop table %s__journal'%spec.classname if __debug__: print >>hyperdb.DEBUG, 'drop_class', (self, sql) self.cursor.execute(sql) for ml in mls: + index_sqls = [ + 'drop index %s_%s_n_idx'%(spec.classname, ml), + 'drop index %s_%s_l_idx'%(spec.classname, ml), + ] + for index_sql in index_sqls: + if __debug__: + print >>hyperdb.DEBUG, 'drop_index', (self, index_sql) + try: + self.cursor.execute(index_sql) + except: + # The database may not actually have any indexes. + # assume the worst. + pass sql = 'drop table %s_%s'%(spec.classname, ml) if __debug__: print >>hyperdb.DEBUG, 'drop_class', (self, sql)