counting changes on the tree

git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@138 014f5005-505e-4b48-8d0a-63407b615a7c
master
LtWorf 2009-04-29 08:36:28 +07:00
parent 4ba7209964
commit ac0d6fae85
3 changed files with 12 additions and 7 deletions

@ -69,4 +69,5 @@
- In optimizer, added a function that tokenizes an expression
- Document about complexity of operations
- Bug: error in update operation, it changed the original tuple, so also other relations using the same tuple would change. Now it copies it.
- Added make install and uninstall
- Added make install and uninstall
- Optimizer generate a tree from the expression

@ -24,20 +24,23 @@ within a cycle.'''
import optimizer
def duplicated_select(n):
changes=0
'''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
duplicated_select(n)
changes=1
changes+=duplicated_select(n)
#recoursive scan
if n.kind==optimizer.UNARY:
duplicated_select(n.child)
changes+=duplicated_select(n.child)
elif n.kind==optimizer.BINARY:
duplicated_select(n.right)
duplicated_select(n.left)
return n
changes+=duplicated_select(n.right)
changes+=duplicated_select(n.left)
return changes
general_optimizations=[duplicated_select]

@ -165,7 +165,7 @@ def general_optimize(expression):
know the fields used by the relations'''
n=tree(expression) #Gets the tree
for i in optimizations.general_optimizations:
n=i(n) #Performs the optimization
print "Changes done: ", i(n) #Performs the optimization
return n.__str__()
if __name__=="__main__":
@ -178,6 +178,7 @@ if __name__=="__main__":
#a= tokenize(u"π a,b (a*b)")
#a=tokenize("(a-b*c)*(b-c)")
a=general_optimize("σ i==2 (σ b>5 ( σ a>2 (C))) * σ a>2 ( σ a>2 (C))")
#a=general_optimize("σ i==2 (σ b>5 (d))")
print a
#print node(a)
#print tokenize("(a)")