Optimization for rearrangements

git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@145 014f5005-505e-4b48-8d0a-63407b615a7c
This commit is contained in:
LtWorf 2009-05-01 13:47:54 +00:00
parent 444d3f9987
commit 52907e67e7
2 changed files with 17 additions and 6 deletions

View File

@ -70,6 +70,14 @@ Notation
the new tuple was already added to the new relation. And this brings the new tuple was already added to the new relation. And this brings
the complexity to O(|n|²). the complexity to O(|n|²).
But the projection can also be used to "rearrange" fields, which
makes no sense in pure relational algebra, but can be usefull to make
two relations match (in fact it is used internally to make relations
match if they have the same fields in different order). In this case
there is no need to check if the tuple already exists, because it is
assumed that the relation was correct. This gives a complexity of
O(|n|) in the best case.
2. BINARY OPERATORS 2. BINARY OPERATORS
Relational defines nine binary operations, and they will be studied Relational defines nine binary operations, and they will be studied
@ -123,4 +131,5 @@ Notation
2.9 Join 2.9 Join
Same as above. Same as above.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

View File

@ -143,7 +143,7 @@ class relation (object):
Will delete duplicate items Will delete duplicate items
If an empty list or no parameters are provided, returns None''' If an empty list or no parameters are provided, returns None'''
#Parameters are supplied in a list, instead with multiple parameters #Parameters are supplied in a list, instead with multiple parameters
if attributes[0].__class__ == list().__class__: if isinstance(attributes[0],list):
attributes=attributes[0] attributes=attributes[0]
#Avoiding duplicated attributes #Avoiding duplicated attributes
@ -153,6 +153,10 @@ class relation (object):
attributes1.append(i) attributes1.append(i)
attributes=attributes1 attributes=attributes1
#If source and dest has the same number of attributes, we are just rearranging
#so we won't need to check for duplicated entries
attributes_same_count=len(attributes)==len(self.header.attributes)
ids=self.header.getAttributesId(attributes) ids=self.header.getAttributesId(attributes)
if len(ids)==0: if len(ids)==0:
@ -169,12 +173,10 @@ class relation (object):
row=[] row=[]
for j in ids: for j in ids:
row.append(i[j]) row.append(i[j])
if row not in newt.content:#Avoids duplicated items if attributes_same_count or row not in newt.content:
newt.content.append(row) newt.content.append(row)
return newt return newt
def rename(self,params): def rename(self,params):
'''Operation rename. Takes a dictionary '''Operation rename. Takes a dictionary
Will replace the itmem with its content. Will replace the itmem with its content.