added 1st optimization

git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@135 014f5005-505e-4b48-8d0a-63407b615a7c
master
LtWorf 2009-04-28 21:11:18 +07:00
parent 923ac12588
commit e898eed426
2 changed files with 19 additions and 4 deletions

@ -21,8 +21,22 @@
The list general_optimizations contains pointers to general functions, so they can be called
within a cycle.'''
def duplicated_select(n):
pass
import optimizer
def duplicated_select(n):
'''This function locates and deletes things like
σ a ( σ a(C)) and the ones like σ a ( σ b(C))'''
if n.name=='σ' and n.child.name=='σ':
if n.prop != n.child.prop: #Nested but different, joining them
n.prop = n.prop + " and " + n.child.prop
n.child=n.child.child
#recoursive scan
if n.kind==optimizer.UNARY:
duplicated_select(n.child)
elif n.kind==optimizer.BINARY:
duplicated_select(n.right)
duplicated_select(n.left)
return n
general_optimizations=[duplicated_select]

@ -174,6 +174,7 @@ def general_optimize(expression):
'''This function performs general optimizations. Means that it will not need to
know the fields used by the relations'''
n=tree(expression) #Gets the tree
print n
for i in optimizations.general_optimizations:
n=i(n) #Performs the optimization
return n.__str__()
@ -187,7 +188,7 @@ if __name__=="__main__":
#a= tokenize("(a - (a b) * π a,b (a-b)) - ρ 123 (a)")
#a= tokenize(u"π a,b (a*b)")
#a=tokenize("(a-b*c)*(b-c)")
a=tokenize("((((((((a)))))))) * b -c ")
a=general_optimize("σ b>5 ( σ a>2 (C)) * σ a>2 ( σ a>2 (C))")
print a
print node(a)
#print node(a)
#print tokenize("(a)")