New optimization
Turns π a,b,c(A) ∪ π a,b,c(B) into π a,b,c(A ∪ B) if A and B are union compatible Works with union, intersection and difference.
This commit is contained in:
parent
eadcca6da7
commit
3b3888e9be
@ -2,7 +2,7 @@
|
|||||||
- Added again make install target
|
- Added again make install target
|
||||||
- Ctrl+C in the terminal will terminate the GUI
|
- Ctrl+C in the terminal will terminate the GUI
|
||||||
- UI indicates ongoing processing with a label
|
- UI indicates ongoing processing with a label
|
||||||
- Added new optimization
|
- Added new optimizations
|
||||||
- Added shortcuts within the UI
|
- Added shortcuts within the UI
|
||||||
- History can be navigated with up/down arrows
|
- History can be navigated with up/down arrows
|
||||||
- Single line edit mode allows for the resulting relation to be written
|
- Single line edit mode allows for the resulting relation to be written
|
||||||
|
@ -544,6 +544,39 @@ def union_and_product(n):
|
|||||||
changes = 1
|
changes = 1
|
||||||
return changes + recoursive_scan(union_and_product, n)
|
return changes + recoursive_scan(union_and_product, n)
|
||||||
|
|
||||||
|
def projection_and_union(n, rels):
|
||||||
|
'''
|
||||||
|
Turns
|
||||||
|
π a,b,c(A) ∪ π a,b,c(B)
|
||||||
|
|
||||||
|
into
|
||||||
|
π a,b,c(A ∪ B)
|
||||||
|
|
||||||
|
if A and B are union compatible
|
||||||
|
'''
|
||||||
|
changes = 0
|
||||||
|
if n.name in {UNION, INTERSECTION, DIFFERENCE} and \
|
||||||
|
n.left.name == PROJECTION and \
|
||||||
|
n.right.name == PROJECTION and \
|
||||||
|
set(n.left.result_format(rels)) == set(n.right.result_format(rels)) and \
|
||||||
|
set(n.left.child.result_format(rels)) == set(n.right.child.result_format(rels)):
|
||||||
|
newchild = parser.Node()
|
||||||
|
|
||||||
|
newchild.kind = parser.BINARY
|
||||||
|
newchild.name = n.name
|
||||||
|
newchild.left = n.left.child
|
||||||
|
newchild.right = n.right.child
|
||||||
|
|
||||||
|
newnode = parser.Node()
|
||||||
|
newnode.child = newchild
|
||||||
|
newnode.kind = parser.UNARY
|
||||||
|
newnode.name = PROJECTION
|
||||||
|
newnode.prop = n.right.prop
|
||||||
|
replace_node(n, newnode)
|
||||||
|
changes = 1
|
||||||
|
return changes + recoursive_scan(projection_and_union, n, rels)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def selection_and_product(n, rels):
|
def selection_and_product(n, rels):
|
||||||
'''This function locates things like σ k (R*Q) and converts them into
|
'''This function locates things like σ k (R*Q) and converts them into
|
||||||
@ -653,9 +686,12 @@ general_optimizations = [
|
|||||||
swap_union_renames,
|
swap_union_renames,
|
||||||
swap_rename_projection,
|
swap_rename_projection,
|
||||||
select_union_intersect_subtract,
|
select_union_intersect_subtract,
|
||||||
union_and_product
|
union_and_product,
|
||||||
|
]
|
||||||
|
specific_optimizations = [
|
||||||
|
selection_and_product,
|
||||||
|
projection_and_union,
|
||||||
]
|
]
|
||||||
specific_optimizations = [selection_and_product]
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print (tokenize_select("skill == 'C' and id % 2 == 0"))
|
print (tokenize_select("skill == 'C' and id % 2 == 0"))
|
||||||
|
1
test/union_projection.query
Normal file
1
test/union_projection.query
Normal file
@ -0,0 +1 @@
|
|||||||
|
πname,skill(σ skill == 'Perl' (people⋈skills)) ∪ πname,skill(σ skill == 'C' (people⋈skills))
|
8
test/union_projection.result
Normal file
8
test/union_projection.result
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
name,skill
|
||||||
|
jack,C
|
||||||
|
eve,Perl
|
||||||
|
duncan,Perl
|
||||||
|
duncan,C
|
||||||
|
john,C
|
||||||
|
alia,C
|
||||||
|
eve,C
|
Loading…
x
Reference in New Issue
Block a user