Mercurial > p > roundup > code
changeset 2240:ad4b717e12b9
Small optimisation to only use "select distinct(id) ..."...
...when we join with a multilink table in filter(). It's unnecessary otherwise.
25% gain for sqlite.
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Mon, 26 Apr 2004 20:59:25 +0000 |
| parents | c8a06e10e2c6 |
| children | 629c7906f1c2 |
| files | roundup/backends/back_mysql.py roundup/backends/rdbms_common.py |
| diffstat | 2 files changed, 17 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/roundup/backends/back_mysql.py Mon Apr 26 00:46:34 2004 +0000 +++ b/roundup/backends/back_mysql.py Mon Apr 26 20:59:25 2004 +0000 @@ -520,10 +520,12 @@ where = [] args = [] a = self.db.arg + mlfilt = False for k, v in filterspec.items(): propclass = props[k] # now do other where clause stuff if isinstance(propclass, Multilink): + mlfilt = True tn = '%s_%s'%(cn, k) if v in ('-1', ['-1']): # only match rows that have count(linkid)=0 in the @@ -671,7 +673,12 @@ where = ' where ' + (' and '.join(where)) else: where = '' - cols = ['distinct(id)'] + if mlfilt: + # we're joining tables on the id, so we will get dupes if we + # don't distinct() + cols = ['distinct(id)'] + else: + cols = ['id'] if orderby: cols = cols + ordercols order = ' order by %s'%(','.join(orderby))
--- a/roundup/backends/rdbms_common.py Mon Apr 26 00:46:34 2004 +0000 +++ b/roundup/backends/rdbms_common.py Mon Apr 26 20:59:25 2004 +0000 @@ -1,4 +1,4 @@ -# $Id: rdbms_common.py,v 1.94 2004-04-25 22:19:15 richard Exp $ +# $Id: rdbms_common.py,v 1.95 2004-04-26 20:59:25 richard Exp $ ''' Relational database (SQL) backend common code. Basics: @@ -1962,10 +1962,12 @@ where = [] args = [] a = self.db.arg + mlfilt = False # are we joining with Multilink tables? for k, v in filterspec.items(): propclass = props[k] # now do other where clause stuff if isinstance(propclass, Multilink): + mlfilt = True tn = '%s_%s'%(cn, k) if v in ('-1', ['-1']): # only match rows that have count(linkid)=0 in the @@ -2107,7 +2109,12 @@ where = ' where ' + (' and '.join(where)) else: where = '' - cols = ['distinct(id)'] + if mlfilt: + # we're joining tables on the id, so we will get dupes if we + # don't distinct() + cols = ['distinct(id)'] + else: + cols = ['id'] if orderby: cols = cols + ordercols order = ' order by %s'%(','.join(orderby))
