consider intersect *and* distinct
authorSylvain Thenault <sylvain.thenault@logilab.fr>
Wed, 07 Jan 2009 14:55:16 +0100
changeset 340 bfe0e95571aa
parent 339 c0a0ce6c0428
child 341 0a426be2f3a2
consider intersect *and* distinct
server/rqlannotation.py
server/sources/rql2sql.py
server/test/unittest_rql2sql.py
--- a/server/rqlannotation.py	Wed Jan 07 09:47:56 2009 +0100
+++ b/server/rqlannotation.py	Wed Jan 07 14:55:16 2009 +0100
@@ -36,15 +36,14 @@
                         if not var.stinfo['selected'] and len(var.stinfo['possibletypes']) > 1:
                             need_intersect = True
                             break
-                    else:
-                        if rschema.inlined:
-                            try:
-                                var = rel.children[1].children[0].variable
-                            except AttributeError:
-                                pass # rewritten variable
-                            else:
-                                if not var.stinfo['constnode']:
-                                    need_distinct = True
+                    if rschema.inlined:
+                        try:
+                            var = rel.children[1].children[0].variable
+                        except AttributeError:
+                            pass # rewritten variable
+                        else:
+                            if not var.stinfo['constnode']:
+                                need_distinct = True
         elif getrschema(rel.r_type).symetric:
             for vref in rel.iget_nodes(VariableRef):
                 stinfo = vref.variable.stinfo
--- a/server/sources/rql2sql.py	Wed Jan 07 09:47:56 2009 +0100
+++ b/server/sources/rql2sql.py	Wed Jan 07 14:55:16 2009 +0100
@@ -488,7 +488,10 @@
                 sql.insert(1, 'FROM (SELECT 1) AS _T')
             sqls.append('\n'.join(sql))
         if select.need_intersect:
-            return '\nINTERSECT\n'.join(sqls)
+            if distinct:
+                return '\nINTERSECT\n'.join(sqls)
+            else:
+                return '\nINTERSECT ALL\n'.join(sqls)
         elif distinct:
             return '\nUNION\n'.join(sqls)
         else:
--- a/server/test/unittest_rql2sql.py	Wed Jan 07 09:47:56 2009 +0100
+++ b/server/test/unittest_rql2sql.py	Wed Jan 07 14:55:16 2009 +0100
@@ -746,11 +746,11 @@
 WHERE P.for_user IS NULL'''),
 
     ('Any S WHERE NOT X in_state S, X is IN(Affaire, EUser)',
-     '''SELECT S.eid
+     '''SELECT DISTINCT S.eid
 FROM Affaire AS X, State AS S
 WHERE (X.in_state IS NULL OR X.in_state!=S.eid)
 INTERSECT
-SELECT S.eid
+SELECT DISTINCT S.eid
 FROM EUser AS X, State AS S
 WHERE (X.in_state IS NULL OR X.in_state!=S.eid)'''),
     ]