Skip to content

Commit e7f576a

Browse files
author
Anthony Baxter
committed
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.
1 parent 1ecc83a commit e7f576a

File tree

4 files changed

+110
-6
lines changed

4 files changed

+110
-6
lines changed

doc/debugging.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Debugging Flags
2+
---------------
3+
4+
Roundup uses a number of debugging environment variables to help you
5+
figure out what the heck it's doing.
6+
7+
HYPERDBDEBUG
8+
============
9+
10+
This environment variable should be set to a filename - the hyperdb will
11+
write debugging information for various events (including, for instance,
12+
the SQL used).
13+
14+
This is only obeyed when python is _not_ running in -O mode.
15+
16+
HYPERDBTRACE
17+
============
18+
19+
This environment variable should be set to a filename - the hyperdb will
20+
write a timestamp entry for various events. This appears to be suffering
21+
rather extreme bit-rot and may go away soon.
22+
23+
This is only obeyed when python is _not_ running in -O mode.
24+
25+
SENDMAILDEBUG
26+
=============
27+
28+
Set to a filename and roundup will write a copy of each email message
29+
that it sends to that file. This environment variable is independent of
30+
the python -O flag.
31+

roundup/backends/back_mysql.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def open_connection(self):
6363
self.database_schema = {}
6464
self.sql("CREATE TABLE schema (schema TEXT) TYPE=BDB")
6565
self.sql("CREATE TABLE ids (name varchar(255), num INT) TYPE=BDB")
66+
self.sql("CREATE INDEX ids_name_idx on ids(name)")
6667

6768
def close(self):
6869
try:

roundup/backends/back_sqlite.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: back_sqlite.py,v 1.9 2003-03-06 06:03:51 richard Exp $
1+
# $Id: back_sqlite.py,v 1.10 2003-10-07 07:17:54 anthonybaxter Exp $
22
__doc__ = '''
33
See https://pysqlite.sourceforge.net/ for pysqlite info
44
'''
@@ -32,6 +32,7 @@ def open_connection(self):
3232
self.database_schema = {}
3333
self.cursor.execute('create table schema (schema varchar)')
3434
self.cursor.execute('create table ids (name varchar, num integer)')
35+
self.cursor.execute('create index ids_name_idx on ids(name)')
3536

3637
def close(self):
3738
''' Close off the connection.

roundup/backends/rdbms_common.py

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: rdbms_common.py,v 1.62 2003-09-08 20:39:18 jlgijsbers Exp $
1+
# $Id: rdbms_common.py,v 1.63 2003-10-07 07:17:54 anthonybaxter Exp $
22
''' Relational database (SQL) backend common code.
33
44
Basics:
@@ -199,7 +199,18 @@ def update_class(self, spec, old_spec):
199199
old_has[name] = 1
200200
if not new_has(name) and isinstance(prop, Multilink):
201201
# it's a multilink, and it's been removed - drop the old
202-
# table
202+
# table. First drop indexes.
203+
index_sqls = [ 'drop index %s_%s_l_idx'%(spec.classname, ml),
204+
'drop index %s_%s_n_idx'%(spec.classname, ml) ]
205+
for index_sql in index_sqls:
206+
if __debug__:
207+
print >>hyperdb.DEBUG, 'drop_index', (self, index_sql)
208+
try:
209+
self.cursor.execute(index_sql)
210+
except:
211+
# The database may not actually have any indexes.
212+
# assume the worst.
213+
pass
203214
sql = 'drop table %s_%s'%(spec.classname, prop)
204215
if __debug__:
205216
print >>hyperdb.DEBUG, 'update_class', (self, sql)
@@ -231,9 +242,19 @@ def update_class(self, spec, old_spec):
231242
self.cursor.execute(sql)
232243
olddata = self.cursor.fetchall()
233244

234-
# drop the old table
245+
# drop the old table - indexes first
246+
index_sqls = [ 'drop index _%s_id_idx'%cn,
247+
'drop index _%s_retired_idx'%cn ]
248+
for index_sql in index_sqls:
249+
if __debug__:
250+
print >>hyperdb.DEBUG, 'drop_index', (self, index_sql)
251+
try:
252+
self.cursor.execute(index_sql)
253+
except:
254+
# The database may not actually have any indexes.
255+
# assume the worst.
256+
pass
235257
self.cursor.execute('drop table _%s'%cn)
236-
237258
# create the new table
238259
self.create_class_table(spec)
239260

@@ -263,6 +284,16 @@ def create_class_table(self, spec):
263284
if __debug__:
264285
print >>hyperdb.DEBUG, 'create_class', (self, sql)
265286
self.cursor.execute(sql)
287+
index_sql1 = 'create index _%s_id_idx on _%s(id)'%(
288+
spec.classname, spec.classname)
289+
if __debug__:
290+
print >>hyperdb.DEBUG, 'create_index', (self, index_sql1)
291+
self.cursor.execute(index_sql1)
292+
index_sql2 = 'create index _%s_retired_idx on _%s(__retired__)'%(
293+
spec.classname, spec.classname)
294+
if __debug__:
295+
print >>hyperdb.DEBUG, 'create_index', (self, index_sql2)
296+
self.cursor.execute(index_sql2)
266297

267298
return cols, mls
268299

@@ -277,6 +308,11 @@ def create_journal_table(self, spec):
277308
if __debug__:
278309
print >>hyperdb.DEBUG, 'create_class', (self, sql)
279310
self.cursor.execute(sql)
311+
index_sql = 'create index %s_journ_idx on %s__journal(nodeid)'%(
312+
spec.classname, spec.classname)
313+
if __debug__:
314+
print >>hyperdb.DEBUG, 'create_index', (self, index_sql)
315+
self.cursor.execute(index_sql)
280316

281317
def create_multilink_table(self, spec, ml):
282318
''' Create a multilink table for the "ml" property of the class
@@ -287,6 +323,16 @@ def create_multilink_table(self, spec, ml):
287323
if __debug__:
288324
print >>hyperdb.DEBUG, 'create_class', (self, sql)
289325
self.cursor.execute(sql)
326+
index_sql = 'create index %s_%s_l_idx on %s_%s(linkid)'%(
327+
spec.classname, ml, spec.classname, ml)
328+
if __debug__:
329+
print >>hyperdb.DEBUG, 'create_index', (self, index_sql)
330+
self.cursor.execute(index_sql)
331+
index_sql = 'create index %s_%s_n_idx on %s_%s(nodeid)'%(
332+
spec.classname, ml, spec.classname, ml)
333+
if __debug__:
334+
print >>hyperdb.DEBUG, 'create_index', (self, index_sql)
335+
self.cursor.execute(index_sql)
290336

291337
def create_class(self, spec):
292338
''' Create a database table according to the given spec.
@@ -316,17 +362,42 @@ def drop_class(self, spec):
316362
if isinstance(prop, Multilink):
317363
mls.append(col)
318364

365+
index_sqls = [ 'drop index _%s_id_idx'%cn,
366+
'drop index _%s_retired_idx'%cn,
367+
'drop index %s_journ_idx'%cn ]
368+
for index_sql in index_sqls:
369+
if __debug__:
370+
print >>hyperdb.DEBUG, 'drop_index', (self, index_sql)
371+
try:
372+
self.cursor.execute(index_sql)
373+
except:
374+
# The database may not actually have any indexes.
375+
# assume the worst.
376+
pass
377+
319378
sql = 'drop table _%s'%spec.classname
320379
if __debug__:
321380
print >>hyperdb.DEBUG, 'drop_class', (self, sql)
322381
self.cursor.execute(sql)
323-
324382
sql = 'drop table %s__journal'%spec.classname
325383
if __debug__:
326384
print >>hyperdb.DEBUG, 'drop_class', (self, sql)
327385
self.cursor.execute(sql)
328386

329387
for ml in mls:
388+
index_sqls = [
389+
'drop index %s_%s_n_idx'%(spec.classname, ml),
390+
'drop index %s_%s_l_idx'%(spec.classname, ml),
391+
]
392+
for index_sql in index_sqls:
393+
if __debug__:
394+
print >>hyperdb.DEBUG, 'drop_index', (self, index_sql)
395+
try:
396+
self.cursor.execute(index_sql)
397+
except:
398+
# The database may not actually have any indexes.
399+
# assume the worst.
400+
pass
330401
sql = 'drop table %s_%s'%(spec.classname, ml)
331402
if __debug__:
332403
print >>hyperdb.DEBUG, 'drop_class', (self, sql)

0 commit comments

Comments
 (0)