Mercurial > p > roundup > code
changeset 2733:ef396596a24e
more efficient find() in RDBMS [SF#1012781]
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Fri, 08 Oct 2004 01:28:32 +0000 |
| parents | 7c472ed6babf |
| children | 85b9dcf908a2 |
| files | CHANGES.txt roundup/backends/rdbms_common.py |
| diffstat | 2 files changed, 14 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/CHANGES.txt Fri Oct 08 00:56:12 2004 +0000 +++ b/CHANGES.txt Fri Oct 08 01:28:32 2004 +0000 @@ -48,6 +48,7 @@ - date.Interval() now accepts an Interval as a spec (sf bug 1041266) - handle deleted properties in RDBMS history - apply timezone in correct direction in user input (sf bug 1013097) +- more efficient find() in RDBMS (sf bug 1012781) 2004-07-21 0.7.6
--- a/roundup/backends/rdbms_common.py Fri Oct 08 00:56:12 2004 +0000 +++ b/roundup/backends/rdbms_common.py Fri Oct 08 01:28:32 2004 +0000 @@ -1,4 +1,4 @@ -# $Id: rdbms_common.py,v 1.135 2004-10-08 00:56:12 richard Exp $ +# $Id: rdbms_common.py,v 1.136 2004-10-08 01:28:32 richard Exp $ ''' Relational database (SQL) backend common code. Basics: @@ -1904,8 +1904,8 @@ # first, links a = self.db.arg - allvalues = (1,) - o = [] + allvalues = () + sql = [] where = [] for prop, values in propspec: if not isinstance(props[prop], hyperdb.Link): @@ -1926,9 +1926,10 @@ allvalues += tuple(values) s += '_%s in (%s)'%(prop, ','.join([a]*len(values))) where.append('(' + s +')') - tables = ['_%s'%self.classname] if where: - o.append('(' + ' and '.join(where) + ')') + allvalues = (1, ) + allvalues + sql.append('''select id from _%s where __retired__ <> %s + and %s'''%(self.classname, a, ' and '.join(where))) # now multilinks for prop, values in propspec: @@ -1936,6 +1937,7 @@ continue if not values: continue + allvalues += (1, ) if type(values) is type(''): allvalues += (values,) s = a @@ -1943,18 +1945,13 @@ allvalues += tuple(values.keys()) s = ','.join([a]*len(values)) tn = '%s_%s'%(self.classname, prop) - tables.append(tn) - o.append('(id=%s.nodeid and %s.linkid in (%s))'%(tn, tn, s)) - - if not o: + sql.append('''select id from _%s, %s where __retired__ <> %s + and id = %s.nodeid and %s.linkid in (%s)'''%(self.classname, + tn, a, tn, tn, s)) + + if not sql: return [] - elif len(o) > 1: - o = '(' + ' or '.join(['(%s)'%i for i in o]) + ')' - else: - o = o[0] - t = ', '.join(tables) - sql = 'select distinct(id) from %s where __retired__ <> %s and %s'%( - t, a, o) + sql = ' union '.join(sql) self.db.sql(sql, allvalues) # XXX numeric ids l = [str(x[0]) for x in self.db.sql_fetchall()]
