[ms planning] test and fix bad plannification of a query used on cascading delete of a deleted (external) entity relations stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 05 Nov 2010 09:17:43 +0100
branchstable
changeset 6673 5eb2f1f2c277
parent 6672 2008fd2f628c
child 6674 fd9c76196bf7
[ms planning] test and fix bad plannification of a query used on cascading delete of a deleted (external) entity relations
server/msplanner.py
server/test/unittest_msplanner.py
--- a/server/msplanner.py	Fri Nov 05 09:14:10 2010 +0100
+++ b/server/msplanner.py	Fri Nov 05 09:17:43 2010 +0100
@@ -745,6 +745,15 @@
                                                and self._need_ext_source_access(term, rel):
                                             self.needsplit = True
                                             return
+        else:
+            # remove sources only accessing to constant nodes
+            for source, terms in self._sourcesterms.items():
+                if source is self.system_source:
+                    continue
+                if not any(x for x in terms if not isinstance(x, Constant)):
+                    del self._sourcesterms[source]
+            if len(self._sourcesterms) < 2:
+                self.needsplit = False
 
     @cached
     def _need_ext_source_access(self, var, rel):
--- a/server/test/unittest_msplanner.py	Fri Nov 05 09:14:10 2010 +0100
+++ b/server/test/unittest_msplanner.py	Fri Nov 05 09:17:43 2010 +0100
@@ -1709,6 +1709,18 @@
                     ],
                    {'x': ueid, 'y': ueid})
 
+    def test_delete_relation3(self):
+        repo._type_source_cache[999999] = ('Note', 'cards', 999999)
+        self._test('DELETE Y multisource_inlined_rel X WHERE X eid %(x)s, NOT (Y cw_source S, S name %(source)s)',
+                   [('DeleteRelationsStep',
+                     [('OneFetchStep',
+                       [('Any Y,999999 WHERE Y multisource_inlined_rel 999999, NOT EXISTS(Y cw_source S, S name "cards"), S is CWSource, Y is IN(Card, Note)',
+                         [{'S': 'CWSource', 'Y': 'Card'}, {'S': 'CWSource', 'Y': 'Note'}])],
+                       None, None, [self.system], {},
+                       [])]
+                     )],
+                   {'x': 999999, 'source': 'cards'})
+
     def test_delete_entity1(self):
         repo._type_source_cache[999999] = ('Note', 'system', 999999)
         self._test('DELETE Note X WHERE X eid %(x)s, NOT Y multisource_rel X',