diff --git a/CHANGELOG b/CHANGELOG index 6e4a9aa..777dfdf 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 \ No newline at end of file +- Added make install and uninstall +- Optimizer generate a tree from the expression \ No newline at end of file diff --git a/relational/optimizations.py b/relational/optimizations.py index 7d058da..62b10ea 100644 --- a/relational/optimizations.py +++ b/relational/optimizations.py @@ -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] \ No newline at end of file diff --git a/relational/optimizer.py b/relational/optimizer.py index 032aa7b..2aa0191 100644 --- a/relational/optimizer.py +++ b/relational/optimizer.py @@ -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)") \ No newline at end of file