From 418e293c1d90f7ad036ea2836182a0737305b87c Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Tue, 9 Jun 2020 11:50:58 +0200 Subject: [PATCH] Enable down_to_unions_subtractions_intersections --- relational/optimizations.py | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/relational/optimizations.py b/relational/optimizations.py index ceca4b9..7d1ff54 100644 --- a/relational/optimizations.py +++ b/relational/optimizations.py @@ -175,7 +175,7 @@ def futile_union_intersection_subtraction(n: parser.Node) -> Tuple[parser.Node, return n, 0 -def down_to_unions_subtractions_intersections(n: parser.Node) -> int: +def down_to_unions_subtractions_intersections(n: parser.Node) -> Tuple[parser.Node, int]: '''This funcion locates things like σ i==2 (c ᑌ d), where the union can be a subtraction and an intersection and replaces them with σ i==2 (c) ᑌ σ i==2(d). @@ -183,27 +183,11 @@ def down_to_unions_subtractions_intersections(n: parser.Node) -> int: changes = 0 _o = (UNION, DIFFERENCE, INTERSECTION) if n.name == SELECTION and n.child.name in _o: + l = parser.Unary(SELECTION, n.prop, n.child.left) + r = parser.Unary(SELECTION, n.prop, n.child.right) - left = parser.Node() - left.prop = n.prop - left.name = n.name - left.child = n.child.left - left.kind = parser.UNARY - right = parser.Node() - right.prop = n.prop - right.name = n.name - right.child = n.child.right - right.kind = parser.UNARY - - n.name = n.child.name - n.left = left - n.right = right - n.child = None - n.prop = None - n.kind = parser.BINARY - changes += 1 - - return changes + recoursive_scan(down_to_unions_subtractions_intersections, n) + return parser.Binary(n.child.name, l, r), 1 + return n, 0 def duplicated_projection(n: parser.Node) -> Tuple[parser.Node, int]: @@ -677,7 +661,7 @@ def useless_projection(n, rels) -> int: general_optimizations = [ duplicated_select, - #down_to_unions_subtractions_intersections, + down_to_unions_subtractions_intersections, duplicated_projection, #selection_inside_projection, #subsequent_renames,