server/sources/rql2sql.py
changeset 9518 54ead5f372bb
parent 9492 c7fc56eecd1a
child 9543 39f981482e34
--- a/server/sources/rql2sql.py	Tue Feb 11 11:03:01 2014 +0100
+++ b/server/sources/rql2sql.py	Fri Dec 20 08:39:03 2013 +0100
@@ -116,7 +116,6 @@
             continue
         unstable.remove(varname)
         newselect = Select()
-        newselect.need_distinct = False
         myunion = Union()
         myunion.append(newselect)
         # extract aliases / selection
@@ -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(