diff --git a/relational/optimizations.py b/relational/optimizations.py index 3675e20..2aea0dc 100644 --- a/relational/optimizations.py +++ b/relational/optimizations.py @@ -83,7 +83,9 @@ def futile_union_intersection_subtraction(n): '''This function locates things like r ᑌ r, and replaces them with r. R ᑌ R --> R R ᑎ R --> R - R - R --> σ False (R) + R - R --> σ False (R) + σ k (R) - R --> σ False (R) + R - σ k (R) --> σ not k (R) σ k (R) ᑌ R --> R σ k (R) ᑎ R --> σ k (R) ''' @@ -106,13 +108,18 @@ def futile_union_intersection_subtraction(n): else: replace_node(n,n.right) #TODO make work the following line... - #elif (n.name == '-' and ((n.left.name=='σ' and n.left.child==n.right) or (n.right.name=='σ' and n.right.child==n.left))): #Intersection of two equal things, but one has a selection - elif n.name=='-' and n.left==n.right:#Empty relation + elif (n.name == '-' and (n.right.name=='σ' and n.right.child==n.left)): #Subtraction of two equal things, but one has a selection + n.name=n.right.name + n.kind=n.right.kind + n.child=n.right.child + n.prop='(not (%s))' % n.right.prop + n.left=n.right=None + elif (n.name=='-' and ((n.left==n.right) or (n.left.name=='σ' and n.left.child==n.right)) ):#Empty relation changes=1 n.kind=optimizer.UNARY n.name='σ' n.prop='False' - n.child=n.left.get_first_leaf() + n.child=n.left.get_left_leaf() #n.left=n.right=None return changes+recoursive_scan(futile_union_intersection_subtraction,n) diff --git a/relational/parser.py b/relational/parser.py index 759a611..7fce527 100644 --- a/relational/parser.py +++ b/relational/parser.py @@ -105,14 +105,14 @@ class node (object): else: return self.name pass - def get_first_leaf(self): + def get_left_leaf(self): '''This function returns the most left random leaf in the tree. It is needed by some optimizations.''' if self.kind==RELATION: return self elif self.kind==UNARY: - return self.child.get_first_leaf() + return self.child.get_left_leaf() elif self.kind==BINARY: - return self.left.get_first_leaf() + return self.left.get_left_leaf() def result_format(self,rels):