From 50647294cb98c6bf3415e50c9620db3c09715bb1 Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Tue, 9 Jun 2020 11:43:14 +0200 Subject: [PATCH] Enable futile_union_intersection_subtraction --- relational/optimizations.py | 42 +++++++++++++++---------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/relational/optimizations.py b/relational/optimizations.py index 1133907..0c1ca08 100644 --- a/relational/optimizations.py +++ b/relational/optimizations.py @@ -125,7 +125,7 @@ def duplicated_select(n: parser.Node) -> Tuple[parser.Node, int]: return n, changes -def futile_union_intersection_subtraction(n: parser.Node) -> int: +def futile_union_intersection_subtraction(n: parser.Node) -> Tuple[parser.Node, int]: '''This function locates things like r ᑌ r, and replaces them with r. R ᑌ R --> R R ᑎ R --> R @@ -140,47 +140,39 @@ def futile_union_intersection_subtraction(n: parser.Node) -> int: # Union and intersection of the same thing if n.name in (UNION, INTERSECTION, JOIN, JOIN_LEFT, JOIN_RIGHT, JOIN_FULL) and n.left == n.right: - changes = 1 - replace_node(n, n.left) + return n.left, 1 # selection and union of the same thing elif (n.name == UNION): if n.left.name == SELECTION and n.left.child == n.right: - changes = 1 - replace_node(n, n.right) + return n.right, 1 elif n.right.name == SELECTION and n.right.child == n.left: - changes = 1 - replace_node(n, n.left) + return n.left, 1 # selection and intersection of the same thing elif n.name == INTERSECTION: if n.left.name == SELECTION and n.left.child == n.right: - changes = 1 - replace_node(n, n.left) + return n.left, 1 elif n.right.name == SELECTION and n.right.child == n.left: - changes = 1 - replace_node(n, n.right) + return n.right, 1 # Subtraction and selection of the same thing elif n.name == DIFFERENCE and \ n.right.name == SELECTION and \ n.right.child == n.left: - n.name = n.right.name - n.kind = n.right.kind - n.child = n.right.child - n.prop = '(not (%s))' % n.right.prop - n.left = n.right = None + return parser.Unary( + SELECTION, + '(not (%s))' % n.right.prop, + n.right.child), 1 # Subtraction of the same thing or with selection on the left child elif n.name == DIFFERENCE and (n.left == n.right or (n.left.name == SELECTION and n.left.child == n.right)): - changes = 1 - n.kind = parser.UNARY - n.name = SELECTION - n.prop = 'False' - n.child = n.left.get_left_leaf() - # n.left=n.right=None - - return changes + recoursive_scan(futile_union_intersection_subtraction, n) + return parser.Unary( + SELECTION, + 'False', + n.get_left_leaf() + ), 1 + return n, 0 def down_to_unions_subtractions_intersections(n: parser.Node) -> int: @@ -690,7 +682,7 @@ general_optimizations = [ #selection_inside_projection, #subsequent_renames, #swap_rename_select, - #futile_union_intersection_subtraction, + futile_union_intersection_subtraction, #swap_union_renames, #swap_rename_projection, #select_union_intersect_subtract,