Implemented swap_rename_projection general optimization
git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@182 014f5005-505e-4b48-8d0a-63407b615a7c
This commit is contained in:
parent
d51d4bada7
commit
43766eeeae
@ -83,4 +83,5 @@
|
||||
- Implemented swap_rename_select general optimization
|
||||
- Implemented selection_and_product specific optimization
|
||||
- Added stub for converting SQL to relational algebra
|
||||
- Implemented futile_union_intersection_subtraction general optimization
|
||||
- Implemented futile_union_intersection_subtraction general optimization
|
||||
- Implemented swap_rename_projection general optimization
|
@ -354,6 +354,56 @@ def tokenize_select(expression):
|
||||
tokens.append(temp)
|
||||
return tokens
|
||||
|
||||
def swap_rename_projection(n):
|
||||
'''This function locates things like π k(ρ j(R))
|
||||
and replaces them with ρ j(π k(R)).
|
||||
This will let rename work on a hopefully smaller set
|
||||
and more important, will hopefully allow further optimizations.
|
||||
Will also eliminate fields in the rename that are cutted in the projection.
|
||||
'''
|
||||
#TODO document into the wiki
|
||||
changes=0
|
||||
|
||||
if n.name=='π' and n.child.name=='ρ':
|
||||
changes=1
|
||||
|
||||
#π index,name(ρ id➡index(R))
|
||||
_vars={}
|
||||
for i in n.child.prop.split(','):
|
||||
q=i.split('➡')
|
||||
_vars[q[1].strip()]=q[0].strip()
|
||||
|
||||
_pr=n.prop.split(',')
|
||||
for i in range(len(_pr)):
|
||||
try:
|
||||
_pr[i]=_vars[_pr[i].strip()]
|
||||
except:
|
||||
pass
|
||||
|
||||
_pr_reborn=n.prop.split(',')
|
||||
for i in list(_vars.keys()):
|
||||
if i not in _pr_reborn:
|
||||
_vars.pop(i)
|
||||
n.name=n.child.name
|
||||
n.prop=''
|
||||
for i in _vars.keys():
|
||||
n.prop+='%s➡%s,' % (_vars[i],i)
|
||||
n.prop=n.prop[:-1]
|
||||
|
||||
n.child.name='π'
|
||||
n.child.prop=''
|
||||
for i in _pr:
|
||||
n.child.prop+=i+','
|
||||
n.child.prop=n.child.prop[:-1]
|
||||
|
||||
#recoursive scan
|
||||
if n.kind==optimizer.UNARY:
|
||||
changes+=swap_rename_projection(n.child)
|
||||
elif n.kind==optimizer.BINARY:
|
||||
changes+=swap_rename_projection(n.right)
|
||||
changes+=swap_rename_projection(n.left)
|
||||
return changes
|
||||
|
||||
def swap_rename_select(n):
|
||||
'''This function locates things like σ k(ρ j(R)) and replaces
|
||||
them with ρ j(σ k(R)). Renaming the attributes used in the
|
||||
@ -501,5 +551,5 @@ def selection_and_product(n,rels):
|
||||
changes+=selection_and_product(n.left,rels)
|
||||
return changes
|
||||
|
||||
general_optimizations=[duplicated_select,down_to_unions_subtractions_intersections,duplicated_projection,selection_inside_projection,subsequent_renames,swap_rename_select,futile_union_intersection_subtraction,swap_union_renames]
|
||||
general_optimizations=[duplicated_select,down_to_unions_subtractions_intersections,duplicated_projection,selection_inside_projection,subsequent_renames,swap_rename_select,futile_union_intersection_subtraction,swap_union_renames,swap_rename_projection]
|
||||
specific_optimizations=[selection_and_product]
|
||||
|
@ -284,7 +284,7 @@ if __name__=="__main__":
|
||||
#print n
|
||||
#print n.result_format(rels)
|
||||
|
||||
a=general_optimize("ρ id➡ciao(R) - ρ id➡ciao(Q) ")
|
||||
a=general_optimize('π index,name,turiddu (ρ qq➡ii,id➡index(R))')#"ρ id➡ciao(R) - ρ id➡ciao(Q) ")
|
||||
#a=general_optimize("σ i==2 (σ b>5 (d))")
|
||||
print a
|
||||
#print node(a)
|
||||
|
@ -37,10 +37,12 @@ if __name__ == "__main__":
|
||||
psyco.full()
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
app = QtGui.QApplication(sys.argv)
|
||||
Form = QtGui.QWidget()
|
||||
|
||||
Form.setFont(QtGui.QFont("Lucida Sans Unicode"))
|
||||
|
||||
ui = maingui.Ui_Form()
|
||||
ui.setupUi(Form)
|
||||
Form.show()
|
||||
|
Loading…
Reference in New Issue
Block a user