From c7f1aa060ee79c6423aecc10d5d4e66df5a50cd6 Mon Sep 17 00:00:00 2001 From: LtWorf Date: Fri, 8 May 2009 14:51:31 +0000 Subject: [PATCH] completed implementation of selection_inside_projection git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@154 014f5005-505e-4b48-8d0a-63407b615a7c --- CHANGELOG | 3 ++- relational/optimizations.py | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index a77937b..afd9c41 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -73,4 +73,5 @@ - Optimizer generate a tree from the expression - Uses python-psyco when it is available - Ability to perform optimizations from GUI -- Able to (temporarily) store queries with a name \ No newline at end of file +- Able to (temporarily) store queries with a name +- Mechanism to add new kind of optimizations, without having to edit all the code \ No newline at end of file diff --git a/relational/optimizations.py b/relational/optimizations.py index e8e4a27..08af347 100644 --- a/relational/optimizations.py +++ b/relational/optimizations.py @@ -101,6 +101,21 @@ def selection_inside_projection(n): '''This function locates things like σ j (π k(R)) and converts them into π k(σ j (R))''' changes=0 + + if n.name=='σ' and n.child.name=='π': + changes=1 + temp=n.prop + n.prop=n.child.prop + n.child.prop=temp + n.name='π' + n.child.name='σ' + + #recoursive scan + if n.kind==optimizer.UNARY: + changes+=selection_inside_projection(n.child) + elif n.kind==optimizer.BINARY: + changes+=selection_inside_projection(n.right) + changes+=selection_inside_projection(n.left) return changes - general_optimizations=[duplicated_select,down_to_unions_subtractions_intersections,duplicated_projection,selection_inside_projection] +general_optimizations=[duplicated_select,down_to_unions_subtractions_intersections,duplicated_projection,selection_inside_projection]