From 9cf8cc34a1db43cc0835ba6a74ca0b83b3b3a558 Mon Sep 17 00:00:00 2001 From: LtWorf Date: Fri, 8 May 2009 15:42:02 +0000 Subject: [PATCH] work on progress on subsequent renames git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@155 014f5005-505e-4b48-8d0a-63407b615a7c --- relational/optimizations.py | 28 +++++++++++++++++++++++++++- relational/optimizer.py | 4 ++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/relational/optimizations.py b/relational/optimizations.py index 08af347..157c98c 100644 --- a/relational/optimizations.py +++ b/relational/optimizations.py @@ -117,5 +117,31 @@ def selection_inside_projection(n): changes+=selection_inside_projection(n.right) changes+=selection_inside_projection(n.left) return changes + +def subsequent_renames(n): + '''This function removes redoundant subsequent renames''' + changes=0 + print "in" + if n.name=='π' and n.child.name==n.name: + changes=1 + print "in-in" + + n.prop+=','+n.child.prop + + _vars={} + for i in n.child.prop.split(','): + q=i.split('➡') + c_vars[q[0]]=q[1] + n.child=n.child.child + -general_optimizations=[duplicated_select,down_to_unions_subtractions_intersections,duplicated_projection,selection_inside_projection] + #recoursive scan + if n.kind==optimizer.UNARY: + changes+=subsequent_renames(n.child) + elif n.kind==optimizer.BINARY: + changes+=subsequent_renames(n.right) + changes+=subsequent_renames(n.left) + return changes + + +general_optimizations=[duplicated_select,down_to_unions_subtractions_intersections,duplicated_projection,selection_inside_projection,subsequent_renames] diff --git a/relational/optimizer.py b/relational/optimizer.py index 14399e8..bb16f70 100644 --- a/relational/optimizer.py +++ b/relational/optimizer.py @@ -193,8 +193,8 @@ if __name__=="__main__": #a= tokenize(u"π a,b (a*b)") #a=tokenize("(a-b*c)*(b-c)") print tree("σ i==2 (c ᑌ d - (aᑎb))") == tree("σ i==3 (c ᑌ d - (aᑎb))") - a=general_optimize("σ i==2 (c ᑌ d - (aᑎb))") + a=general_optimize("π age➡a(π ciccio➡age(R))") #a=general_optimize("σ i==2 (σ b>5 (d))") - print a + print '=========',a #print node(a) #print tokenize("(a)") \ No newline at end of file