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]