From 1d6aa8880564ae3d098b52e4738aa05d34c9182b Mon Sep 17 00:00:00 2001 From: LtWorf Date: Tue, 18 Aug 2009 10:03:55 +0000 Subject: [PATCH] Improved futile_union_intersection_subtraction in case of A-A, when A is a sub-query git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@208 014f5005-505e-4b48-8d0a-63407b615a7c --- CHANGELOG | 3 ++- relational/optimizations.py | 9 ++++++--- relational/parser.py | 10 ++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 8203e1f..e95fd4b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -90,4 +90,5 @@ - Selection can now accept expressions with parenthesis 0.11 -- Font is set only on windows (Rev 206) \ No newline at end of file +- Font is set only on windows (Rev 206) +- Improved futile_union_intersection_subtraction in case of A-A, when A is a sub-query (Rev 208) \ No newline at end of file diff --git a/relational/optimizations.py b/relational/optimizations.py index 38de030..3675e20 100644 --- a/relational/optimizations.py +++ b/relational/optimizations.py @@ -81,8 +81,11 @@ def duplicated_select(n): def futile_union_intersection_subtraction(n): '''This function locates things like r ᑌ r, and replaces them with r. - σ k (r) ᑌ r with r - σ k (r) ᑎ r with σ k (r) + R ᑌ R --> R + R ᑎ R --> R + R - R --> σ False (R) + σ k (R) ᑌ R --> R + σ k (R) ᑎ R --> σ k (R) ''' changes=0 @@ -109,7 +112,7 @@ def futile_union_intersection_subtraction(n): n.kind=optimizer.UNARY n.name='σ' n.prop='False' - n.child=n.left + n.child=n.left.get_first_leaf() #n.left=n.right=None return changes+recoursive_scan(futile_union_intersection_subtraction,n) diff --git a/relational/parser.py b/relational/parser.py index 4603026..759a611 100644 --- a/relational/parser.py +++ b/relational/parser.py @@ -105,6 +105,16 @@ class node (object): else: return self.name pass + def get_first_leaf(self): + '''This function returns the most left random leaf in the tree. It is needed by some optimizations.''' + if self.kind==RELATION: + return self + elif self.kind==UNARY: + return self.child.get_first_leaf() + elif self.kind==BINARY: + return self.left.get_first_leaf() + + def result_format(self,rels): '''This function returns a list containing the fields that the resulting relation will have. Since it needs to know real instances of relations, it requires a dictionary where keys are