Implemented futile_union_intersection_subtraction general optimization
git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@175 014f5005-505e-4b48-8d0a-63407b615a7c
This commit is contained in:
parent
5dead3a058
commit
5e30121812
@ -82,3 +82,5 @@
|
||||
- Implemented subsequent_renames general optimization
|
||||
- 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
|
@ -52,6 +52,39 @@ def duplicated_select(n):
|
||||
changes+=duplicated_select(n.left)
|
||||
return changes
|
||||
|
||||
def futile_union_intersection_subtraction(n):
|
||||
'''This function locates things like r ᑌ r, and replaces them with r'''
|
||||
#TODO document into the wiki
|
||||
changes=0
|
||||
|
||||
if n.name in ('ᑌ','ᑎ') and n.left==n.right:
|
||||
changes=1
|
||||
n.name=n.left.name
|
||||
n.kind=n.left.kind
|
||||
if n.kind==optimizer.UNARY:
|
||||
n.child=n.left.child
|
||||
n.prop=n.left.prop
|
||||
elif n.kind==optimizer.BINARY:
|
||||
n.right=n.left.right
|
||||
n.left=n.left.left
|
||||
pass
|
||||
elif n.name=='-' and n.left==n.right:#Empty relation
|
||||
changes=1
|
||||
n.kind=optimizer.UNARY
|
||||
n.name='σ'
|
||||
n.prop='False'
|
||||
n.child=n.left
|
||||
#n.left=n.right=None
|
||||
|
||||
#recoursive scan
|
||||
if n.kind==optimizer.UNARY:
|
||||
changes+=futile_union_intersection_subtraction(n.child)
|
||||
elif n.kind==optimizer.BINARY:
|
||||
changes+=futile_union_intersection_subtraction(n.right)
|
||||
changes+=futile_union_intersection_subtraction(n.left)
|
||||
return changes
|
||||
|
||||
|
||||
def down_to_unions_subtractions_intersections(n):
|
||||
'''This funcion locates things like σ i==2 (c ᑌ d), where the union
|
||||
can be a subtraction and an intersection and replaces them with
|
||||
@ -355,5 +388,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]
|
||||
general_optimizations=[duplicated_select,down_to_unions_subtractions_intersections,duplicated_projection,selection_inside_projection,subsequent_renames,swap_rename_select,futile_union_intersection_subtraction]
|
||||
specific_optimizations=[selection_and_product]
|
@ -267,24 +267,24 @@ if __name__=="__main__":
|
||||
|
||||
import relation,optimizations
|
||||
|
||||
rels={}
|
||||
'''rels={}
|
||||
rels["P1"]= relation.relation("/home/salvo/dev/relational/trunk/samples/people.csv")
|
||||
rels["P2"]= relation.relation("/home/salvo/dev/relational/trunk/samples/people.csv")
|
||||
rels["R1"]= relation.relation("/home/salvo/dev/relational/trunk/samples/person_room.csv")
|
||||
rels["R2"]= relation.relation("/home/salvo/dev/relational/trunk/samples/person_room.csv")
|
||||
rels["D1"]= relation.relation("/home/salvo/dev/relational/trunk/samples/dates.csv")
|
||||
rels["S1"]= relation.relation("/home/salvo/dev/relational/trunk/samples/skillo.csv")
|
||||
print rels
|
||||
print rels'''
|
||||
#n=tree("π indice,qq,name (ρ age➡qq,id➡indice (P1-P2))")
|
||||
#n=tree("σ id==3 and indice==2 and name==5 or name<2(P1 * S1)")
|
||||
#print optimizations.selection_and_product(n,rels)
|
||||
|
||||
print specific_optimize("σ name==skill and age>21 and id==indice and skill=='C'(P1ᐅᐊS1)",rels)
|
||||
#print specific_optimize("σ name==skill and age>21 and id==indice and skill=='C'(P1ᐅᐊS1)",rels)
|
||||
|
||||
#print n
|
||||
#print n.result_format(rels)
|
||||
|
||||
#a=general_optimize("σ age==3 and qq<=2 or nome!='ciccio d\\'urso'(ρ ciccio➡age,nome➡nom(R-Q))")
|
||||
a=general_optimize("ρ i➡index(ρ id➡i (people))")
|
||||
#a=general_optimize("σ i==2 (σ b>5 (d))")
|
||||
#print a
|
||||
#print node(a)
|
||||
|
@ -19,7 +19,20 @@
|
||||
|
||||
'''This module offers capability of executing relational queries in parallel.'''
|
||||
|
||||
def weight (n):
|
||||
import optimizer
|
||||
|
||||
def weight (n,rels):
|
||||
'''This function returns a weight that tries to give an approssimation of the
|
||||
time that will be required to execute the expression'''
|
||||
if n.kind==optimizer.RELATION: #Weight of a relation is its size
|
||||
r=rels[n.name]
|
||||
return len(r.content) * len(r.header.attributes)
|
||||
elif n.kind==optimizer.BINARY and n.name=='ρ':
|
||||
pass
|
||||
elif n.kind==optimizer.BINARY and n.name=='σ':
|
||||
pass
|
||||
elif n.kind==optimizer.BINARY and n.name=='π':
|
||||
pass
|
||||
|
||||
|
||||
pass
|
26
relational/sql.py
Normal file
26
relational/sql.py
Normal file
@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Relational
|
||||
# Copyright (C) 2009 Salvo "LtWorf" Tomaselli
|
||||
#
|
||||
# Relation is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# author Salvo "LtWorf" Tomaselli <tiposchi@tiscali.it>
|
||||
|
||||
'''This module converts SQL queries into relational algebra expressions'''
|
||||
|
||||
def stub():
|
||||
"NATURAL JOIN"
|
||||
"CROSS JOIN" ,
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user