New optimization: useless projection

If a projection is done on every attribute it is useless and
can be removed.

The new optimization does this.
master
Salvo 'LtWorf' Tomaselli 2016-01-03 17:15:04 +07:00
parent 17410a0b19
commit 1dd1298ee0
1 changed files with 14 additions and 0 deletions

@ -664,6 +664,19 @@ def selection_and_product(n, rels):
return changes + recoursive_scan(selection_and_product, n, rels) return changes + recoursive_scan(selection_and_product, n, rels)
def useless_projection(n, rels):
'''
Removes projections that are over all the fields
'''
changes = 0
if n.name == PROJECTION and \
set(n.child.result_format(rels)) == set(i.strip() for i in n.prop.split(',')):
changes = 1
replace_node(n, n.child)
return changes + recoursive_scan(useless_projection, n, rels)
general_optimizations = [ general_optimizations = [
duplicated_select, duplicated_select,
down_to_unions_subtractions_intersections, down_to_unions_subtractions_intersections,
@ -680,6 +693,7 @@ general_optimizations = [
specific_optimizations = [ specific_optimizations = [
selection_and_product, selection_and_product,
projection_and_union, projection_and_union,
useless_projection,
] ]
if __name__ == "__main__": if __name__ == "__main__":