From f4a8344f3ed781e67734e8b081c0e8c0f07d85da Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Tue, 9 Jun 2020 19:43:56 +0200 Subject: [PATCH] projection_and_union --- relational/optimizations.py | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/relational/optimizations.py b/relational/optimizations.py index 1ce87f0..bdf31aa 100644 --- a/relational/optimizations.py +++ b/relational/optimizations.py @@ -447,7 +447,7 @@ def union_and_product(n: parser.Node) -> Tuple[parser.Node, int]: return n, 0 -def projection_and_union(n, rels): +def projection_and_union(n: parser.Node, rels: Dict[str, Relation]) -> Tuple[parser.Node, int]: ''' Turns π a,b,c(A) ∪ π a,b,c(B) @@ -462,20 +462,9 @@ def projection_and_union(n, rels): n.left.name == PROJECTION and \ n.right.name == PROJECTION and \ set(n.left.child.result_format(rels)) == set(n.right.child.result_format(rels)): - newchild = parser.Node() - newchild.kind = parser.BINARY - newchild.name = UNION - 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 + child = parser.Binary(UNION, n.left.child, n.right.child) + return parser.Unary(PROJECTION, n.right.prop, child), 0 return n, 0 @@ -603,6 +592,6 @@ general_optimizations = [ ] specific_optimizations = [ #selection_and_product, - #projection_and_union, + projection_and_union, useless_projection, ]