From e5e7dcddd254d2480c260aed6672c760311e469e Mon Sep 17 00:00:00 2001 From: LtWorf Date: Tue, 12 May 2009 13:49:43 +0000 Subject: [PATCH] fixed error that caused an infinite loop git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@166 014f5005-505e-4b48-8d0a-63407b615a7c --- relational/optimizations.py | 9 ++------- relational/optimizer.py | 37 +++++++++++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/relational/optimizations.py b/relational/optimizations.py index 94697d5..d765ddd 100644 --- a/relational/optimizations.py +++ b/relational/optimizations.py @@ -258,8 +258,6 @@ def selection_and_product(n,rels): changes=0 if n.name=='σ' and n.child.name=='*': - changes=1 - l_attr=n.child.left.result_format(rels) r_attr=n.child.right.result_format(rels) @@ -282,9 +280,6 @@ def selection_and_product(n,rels): right=[] both=[] - print "Attributi R",r_attr, "Attributi L",l_attr - print "Gruppi",groups - for i in groups: l_fields=False #has fields in left? r_fields=False #has fields in left? @@ -304,10 +299,9 @@ def selection_and_product(n,rels): else:#Unknown.. adding in both both.append(i) - print "left", left, "right",right,"both",both - #Preparing left selection if len(left)>0: + changes=1 l_node=optimizer.node() l_node.name='σ' l_node.kind=optimizer.UNARY @@ -323,6 +317,7 @@ def selection_and_product(n,rels): #Preparing right selection if len(right)>0: + changes=1 r_node=optimizer.node() r_node.name='σ' r_node.prop='' diff --git a/relational/optimizer.py b/relational/optimizer.py index 994d4e2..d67164c 100644 --- a/relational/optimizer.py +++ b/relational/optimizer.py @@ -220,6 +220,33 @@ def tree(expression): the root node using the Node class defined in this module.''' return node(tokenize(expression)) +def optimize_all(expression,rels): + '''This function performs all the available optimizations''' + n=tree(expression) #Gets the tree + total=1 + while total!=0: + total=0 + for i in optimizations.specific_optimizations: + total+=i(n,rels) #Performs the optimization + print n + for i in optimizations.general_optimizations: + total+=i(n) #Performs the optimization + print n + return n.__str__() + + +def specific_optimize(expression,rels): + '''This function performs specific optimizations. Means that it will need to + know the fields used by the relations''' + n=tree(expression) #Gets the tree + total=1 + while total!=0: + total=0 + for i in optimizations.specific_optimizations: + total+=i(n,rels) #Performs the optimization + return n.__str__() + + def general_optimize(expression): '''This function performs general optimizations. Means that it will not need to know the fields used by the relations''' @@ -251,11 +278,13 @@ if __name__=="__main__": rels["S1"]= relation.relation("/home/salvo/dev/relational/trunk/samples/skillo.csv") print rels #n=tree("π indice,qq,name (ρ age➡qq,id➡indice (P1-P2))") - n=tree("σ id==3 and id==indice and indice==2 and name==5 or name<2(P1 * S1)") - print optimizations.selection_and_product(n,rels) + #n=tree("σ id==3 and indice==2 and name==5 or name<2(P1 * S1)") + #print optimizations.selection_and_product(n,rels) - print n - print n.result_format(rels) + print specific_optimize("σ id==3 and indice==2 and name==5 or name<2(P1 * S1)",rels) + + #print n + #print n.result_format(rels) #a=general_optimize("σ age==3 and qq<=2 or nome!='ciccio d\\'urso'(ρ ciccio➡age,nome➡nom(R-Q))") #a=general_optimize("σ i==2 (σ b>5 (d))")