Enable futile_union_intersection_subtraction
This commit is contained in:
parent
0dcd639c9d
commit
50647294cb
@ -125,7 +125,7 @@ def duplicated_select(n: parser.Node) -> Tuple[parser.Node, int]:
|
|||||||
return n, changes
|
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.
|
'''This function locates things like r ᑌ r, and replaces them with r.
|
||||||
R ᑌ R --> R
|
R ᑌ R --> 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
|
# 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:
|
if n.name in (UNION, INTERSECTION, JOIN, JOIN_LEFT, JOIN_RIGHT, JOIN_FULL) and n.left == n.right:
|
||||||
changes = 1
|
return n.left, 1
|
||||||
replace_node(n, n.left)
|
|
||||||
|
|
||||||
# selection and union of the same thing
|
# selection and union of the same thing
|
||||||
elif (n.name == UNION):
|
elif (n.name == UNION):
|
||||||
if n.left.name == SELECTION and n.left.child == n.right:
|
if n.left.name == SELECTION and n.left.child == n.right:
|
||||||
changes = 1
|
return n.right, 1
|
||||||
replace_node(n, n.right)
|
|
||||||
elif n.right.name == SELECTION and n.right.child == n.left:
|
elif n.right.name == SELECTION and n.right.child == n.left:
|
||||||
changes = 1
|
return n.left, 1
|
||||||
replace_node(n, n.left)
|
|
||||||
|
|
||||||
# selection and intersection of the same thing
|
# selection and intersection of the same thing
|
||||||
elif n.name == INTERSECTION:
|
elif n.name == INTERSECTION:
|
||||||
if n.left.name == SELECTION and n.left.child == n.right:
|
if n.left.name == SELECTION and n.left.child == n.right:
|
||||||
changes = 1
|
return n.left, 1
|
||||||
replace_node(n, n.left)
|
|
||||||
elif n.right.name == SELECTION and n.right.child == n.left:
|
elif n.right.name == SELECTION and n.right.child == n.left:
|
||||||
changes = 1
|
return n.right, 1
|
||||||
replace_node(n, n.right)
|
|
||||||
|
|
||||||
# Subtraction and selection of the same thing
|
# Subtraction and selection of the same thing
|
||||||
elif n.name == DIFFERENCE and \
|
elif n.name == DIFFERENCE and \
|
||||||
n.right.name == SELECTION and \
|
n.right.name == SELECTION and \
|
||||||
n.right.child == n.left:
|
n.right.child == n.left:
|
||||||
n.name = n.right.name
|
return parser.Unary(
|
||||||
n.kind = n.right.kind
|
SELECTION,
|
||||||
n.child = n.right.child
|
'(not (%s))' % n.right.prop,
|
||||||
n.prop = '(not (%s))' % n.right.prop
|
n.right.child), 1
|
||||||
n.left = n.right = None
|
|
||||||
|
|
||||||
# Subtraction of the same thing or with selection on the left child
|
# 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)):
|
elif n.name == DIFFERENCE and (n.left == n.right or (n.left.name == SELECTION and n.left.child == n.right)):
|
||||||
changes = 1
|
return parser.Unary(
|
||||||
n.kind = parser.UNARY
|
SELECTION,
|
||||||
n.name = SELECTION
|
'False',
|
||||||
n.prop = 'False'
|
n.get_left_leaf()
|
||||||
n.child = n.left.get_left_leaf()
|
), 1
|
||||||
# n.left=n.right=None
|
return n, 0
|
||||||
|
|
||||||
return changes + recoursive_scan(futile_union_intersection_subtraction, n)
|
|
||||||
|
|
||||||
|
|
||||||
def down_to_unions_subtractions_intersections(n: parser.Node) -> int:
|
def down_to_unions_subtractions_intersections(n: parser.Node) -> int:
|
||||||
@ -690,7 +682,7 @@ general_optimizations = [
|
|||||||
#selection_inside_projection,
|
#selection_inside_projection,
|
||||||
#subsequent_renames,
|
#subsequent_renames,
|
||||||
#swap_rename_select,
|
#swap_rename_select,
|
||||||
#futile_union_intersection_subtraction,
|
futile_union_intersection_subtraction,
|
||||||
#swap_union_renames,
|
#swap_union_renames,
|
||||||
#swap_rename_projection,
|
#swap_rename_projection,
|
||||||
#select_union_intersect_subtract,
|
#select_union_intersect_subtract,
|
||||||
|
Loading…
Reference in New Issue
Block a user