- Implemented select_union_intersect_subtract general optimization

- Added tests for the new optimization



git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@268 014f5005-505e-4b48-8d0a-63407b615a7c
master
LtWorf 2011-02-18 18:11:39 +07:00
parent 7ab6ed8ed7
commit 71697bb2e8
9 changed files with 37 additions and 2 deletions

@ -11,6 +11,7 @@
- Fixed futile_union_intersection_subtraction optimization that didn't work when selection operator was in the left subtree (Rev 261)
- Module parallel does something, can execute queries in parallel
- Set hash method for the classes
- Implemented select_union_intersect_subtract general optimization
0.11
- Font is set only on windows (Rev 206)

@ -449,6 +449,27 @@ def swap_rename_select(n):
return changes+recoursive_scan(swap_rename_select,n)
def select_union_intersect_subtract(n):
'''This function locates things like σ i(a) σ q(a)
and replaces them with σ (i OR q) (a)
Removing a operation like the union'''
changes=0
if n.name in ('', '', '-') and n.left.name=='σ' and n.right.name=='σ' and n.left.child==n.right.child:
cahnges=1
d={'':'or', '':'and', '-':'and not'}
op=d[n.name]
newnode=parser.node()
newnode.prop='((%s) %s (%s))' % (n.left.prop,op,n.right.prop)
newnode.name='σ'
newnode.child=n.left.child
newnode.kind=parser.UNARY
replace_node(n,newnode)
return changes+recoursive_scan(select_union_intersect_subtract,n)
def selection_and_product(n,rels):
'''This function locates things like σ k (R*Q) and converts them into
σ l (σ j (R) * σ i (Q)). Where j contains only attributes belonging to R,
@ -549,7 +570,7 @@ def selection_and_product(n,rels):
return changes+recoursive_scan(selection_and_product,n,rels)
general_optimizations=[duplicated_select,down_to_unions_subtractions_intersections,duplicated_projection,selection_inside_projection,subsequent_renames,swap_rename_select,futile_union_intersection_subtraction,swap_union_renames,swap_rename_projection]
general_optimizations=[duplicated_select,down_to_unions_subtractions_intersections,duplicated_projection,selection_inside_projection,subsequent_renames,swap_rename_select,futile_union_intersection_subtraction,swap_union_renames,swap_rename_projection,select_union_intersect_subtract]
specific_optimizations=[selection_and_product]
if __name__=="__main__":

@ -132,7 +132,7 @@ class node (object):
return '\n'+r
def get_left_leaf(self):
'''This function returns the most left leaf in the tree. It is needed by some optimizations.'''
'''This function returns the leftmost leaf in the tree. It is needed by some optimizations.'''
if self.kind==RELATION:
return self
elif self.kind==UNARY:

@ -0,0 +1 @@
σ skill=='C'(skills) ᑎ σ id%2==0 (skills)

@ -0,0 +1,4 @@
id,skill
0,C
2,C
4,C

@ -0,0 +1 @@
σ skill=='C' (skills) - σ id%2==0(skills)

@ -0,0 +1,3 @@
id,skill
5,C
7,C

@ -0,0 +1 @@
σ age<21 (people) σage >30(people)

@ -0,0 +1,3 @@
id,name,chief,age
3,dean,1,33
1,carl,0,20