Skip to content

Commit f0e6fc5

Browse files
author
Richard Jones
committed
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.
1 parent 1cb657d commit f0e6fc5

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

roundup/backends/back_mysql.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,10 +520,12 @@ def filter(self, search_matches, filterspec, sort=(None,None),
520520
where = []
521521
args = []
522522
a = self.db.arg
523+
mlfilt = False
523524
for k, v in filterspec.items():
524525
propclass = props[k]
525526
# now do other where clause stuff
526527
if isinstance(propclass, Multilink):
528+
mlfilt = True
527529
tn = '%s_%s'%(cn, k)
528530
if v in ('-1', ['-1']):
529531
# only match rows that have count(linkid)=0 in the
@@ -671,7 +673,12 @@ def filter(self, search_matches, filterspec, sort=(None,None),
671673
where = ' where ' + (' and '.join(where))
672674
else:
673675
where = ''
674-
cols = ['distinct(id)']
676+
if mlfilt:
677+
# we're joining tables on the id, so we will get dupes if we
678+
# don't distinct()
679+
cols = ['distinct(id)']
680+
else:
681+
cols = ['id']
675682
if orderby:
676683
cols = cols + ordercols
677684
order = ' order by %s'%(','.join(orderby))

roundup/backends/rdbms_common.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: rdbms_common.py,v 1.94 2004-04-25 22:19:15 richard Exp $
1+
# $Id: rdbms_common.py,v 1.95 2004-04-26 20:59:25 richard Exp $
22
''' Relational database (SQL) backend common code.
33
44
Basics:
@@ -1962,10 +1962,12 @@ def filter(self, search_matches, filterspec, sort=(None,None),
19621962
where = []
19631963
args = []
19641964
a = self.db.arg
1965+
mlfilt = False # are we joining with Multilink tables?
19651966
for k, v in filterspec.items():
19661967
propclass = props[k]
19671968
# now do other where clause stuff
19681969
if isinstance(propclass, Multilink):
1970+
mlfilt = True
19691971
tn = '%s_%s'%(cn, k)
19701972
if v in ('-1', ['-1']):
19711973
# only match rows that have count(linkid)=0 in the
@@ -2107,7 +2109,12 @@ def filter(self, search_matches, filterspec, sort=(None,None),
21072109
where = ' where ' + (' and '.join(where))
21082110
else:
21092111
where = ''
2110-
cols = ['distinct(id)']
2112+
if mlfilt:
2113+
# we're joining tables on the id, so we will get dupes if we
2114+
# don't distinct()
2115+
cols = ['distinct(id)']
2116+
else:
2117+
cols = ['id']
21112118
if orderby:
21122119
cols = cols + ordercols
21132120
order = ' order by %s'%(','.join(orderby))

0 commit comments

Comments
 (0)