server/rqlannotation.py
branchstable
changeset 7193 7eaef037ea9d
parent 7041 5a6fd60f7617
child 7357 5ad3154a8810
--- a/server/rqlannotation.py	Wed Apr 06 23:01:58 2011 +0200
+++ b/server/rqlannotation.py	Wed Apr 06 23:23:48 2011 +0200
@@ -98,10 +98,19 @@
                     # variable of an inlined relation
                     if not rel in stinfo['rhsrelations'] and rschema.inlined:
                         break
-                else:
-                    # variable used as main variable of an optional relation
-                    # can't be invariant
+                # variable used as main variable of an optional relation can't
+                # be invariant, unless we can use some other relation as
+                # reference for the outer join
+                elif not stinfo['constnode']:
                     break
+                elif len(stinfo['relations']) == 2:
+                    if onlhs:
+                        ostinfo = rhs.children[0].variable.stinfo
+                    else:
+                        ostinfo = lhs.variable.stinfo
+                    if not any(orel for orel in ostinfo['relations']
+                               if orel.optional and orel is not rel):
+                        break
             if rschema.final or (onlhs and rschema.inlined):
                 if rschema.type != 'has_text':
                     # need join anyway if the variable appears in a final or