diff -r 78702b55c089 -r 39f981482e34 server/sources/rql2sql.py --- a/server/sources/rql2sql.py Mon Feb 03 16:30:07 2014 +0100 +++ b/server/sources/rql2sql.py Mon Feb 17 15:32:50 2014 +0100 @@ -116,7 +116,6 @@ continue unstable.remove(varname) newselect = Select() - newselect.need_distinct = False myunion = Union() myunion.append(newselect) # extract aliases / selection @@ -688,7 +687,7 @@ Groups and sort are not handled here since they should not be handled at this level (see cubicweb.server.querier) - we should not have errors here ! + we should not have errors here! WARNING: a CubicWebSQLGenerator instance is not thread safe, but generate is protected by a lock @@ -703,9 +702,6 @@ } if not self.dbhelper.union_parentheses_support: self.union_sql = self.noparen_union_sql - if self.dbhelper.fti_need_distinct: - self.__union_sql = self.union_sql - self.union_sql = self.has_text_need_distinct_union_sql self._lock = threading.Lock() if attrmap is None: attrmap = {} @@ -739,12 +735,6 @@ finally: self._lock.release() - def has_text_need_distinct_union_sql(self, union, needalias=False): - if getattr(union, 'has_text_query', False): - for select in union.children: - select.need_distinct = True - return self.__union_sql(union, needalias) - def union_sql(self, union, needalias=False): # pylint: disable=E0202 if len(union.children) == 1: return self.select_sql(union.children[0], needalias) @@ -772,7 +762,12 @@ :needwrap: boolean telling if the query will be wrapped in an outer query (to deal with aggregat and/or grouping) """ - distinct = selectsortterms = select.need_distinct + if select.distinct: + distinct = True + elif self.dbhelper.fti_need_distinct: + distinct = getattr(select.parent, 'has_text_query', False) + else: + distinct = False sorts = select.orderby groups = select.groupby having = select.having @@ -796,6 +791,7 @@ # selection (union or distinct query) and wrapping (union with groups) needwrap = False sols = select.solutions + selectsortterms = distinct if len(sols) > 1: # remove invariant from solutions sols, existssols, unstable = remove_unused_solutions(