Improved futile_union_intersection_subtraction, handles when a branch of subtracion has a selection

git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@209 014f5005-505e-4b48-8d0a-63407b615a7c
master
LtWorf 2009-08-18 10:28:34 +07:00
parent 1d6aa88805
commit 6734fc66e5
2 changed files with 14 additions and 7 deletions

@ -84,6 +84,8 @@ def futile_union_intersection_subtraction(n):
R R --> R
R R --> 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)

@ -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):