From e898eed426980437a9afe08616c0bf18aef2901c Mon Sep 17 00:00:00 2001 From: LtWorf Date: Tue, 28 Apr 2009 21:11:18 +0000 Subject: [PATCH] added 1st optimization git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@135 014f5005-505e-4b48-8d0a-63407b615a7c --- relational/optimizations.py | 18 ++++++++++++++++-- relational/optimizer.py | 5 +++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/relational/optimizations.py b/relational/optimizations.py index 2cf9cb9..a517093 100644 --- a/relational/optimizations.py +++ b/relational/optimizations.py @@ -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] \ No newline at end of file diff --git a/relational/optimizer.py b/relational/optimizer.py index 4b0472a..2266258 100644 --- a/relational/optimizer.py +++ b/relational/optimizer.py @@ -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)") \ No newline at end of file