From 99692f7d70b6f909e985105c3431a95995e40af4 Mon Sep 17 00:00:00 2001 From: LtWorf Date: Mon, 11 Oct 2010 12:06:41 +0000 Subject: [PATCH] - Fixed futile_union_intersection_subtraction optimization that didn't work when selection operator was in the left subtree git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@262 014f5005-505e-4b48-8d0a-63407b615a7c --- CHANGELOG | 1 + relational/optimizations.py | 28 +++++++++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 857b1dd..36f7490 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -8,6 +8,7 @@ - Added testsuite - Fixed python expression tokenization, now uses native tokenizer - Fixed optimization involving selection and parenthesis in the expression (Rev 260) +- Fixed futile_union_intersection_subtraction optimization that didn't work when selection operator was in the left subtree (Rev 261) 0.11 - Font is set only on windows (Rev 206) diff --git a/relational/optimizations.py b/relational/optimizations.py index 6a51f63..553de04 100644 --- a/relational/optimizations.py +++ b/relational/optimizations.py @@ -115,28 +115,38 @@ def futile_union_intersection_subtraction(n): changes=0 + #Union and intersection of the same thing if n.name in ('ᑌ','ᑎ') and n.left==n.right: changes=1 replace_node(n,n.left) - elif (n.name == 'ᑌ' and ((n.left.name=='σ' and n.left.child==n.right) or (n.right.name=='σ' and n.right.child==n.left))): #Union of two equal things, but one has a selection - changes=1 - if n.left=='σ':#Selection on left. replacing self with right. + + #selection and union of the same thing + elif (n.name == 'ᑌ'): + if n.left.name=='σ' and n.left.child==n.right: + changes=1 replace_node(n,n.right) - else:#Selection on left. replacing self with right. + elif n.right.name=='σ' and n.right.child==n.left: + changes=1 replace_node(n,n.left) - elif (n.name == 'ᑎ' and ((n.left.name=='σ' and n.left.child==n.right) or (n.right.name=='σ' and n.right.child==n.left))): #Intersection of two equal things, but one has a selection - changes=1 - if n.left=='σ':#Swapping with the selection + + #selection and intersection of the same thing + elif n.name == 'ᑎ': + if n.left.name=='σ' and n.left.child==n.right: + changes=1 replace_node(n,n.left) - else: + elif n.right.name=='σ' and n.right.child==n.left: + changes=1 replace_node(n,n.right) - #TODO make work the following line... + + #Subtraction and selection of the same thing elif (n.name == '-' and (n.right.name=='σ' and n.right.child==n.left)): #Subtraction of two equal things, but one has a selection n.name=n.right.name n.kind=n.right.kind n.child=n.right.child n.prop='(not (%s))' % n.right.prop n.left=n.right=None + + #Subtraction of the same thing or with selection on the left child elif (n.name=='-' and ((n.left==n.right) or (n.left.name=='σ' and n.left.child==n.right)) ):#Empty relation changes=1 n.kind=optimizer.UNARY