From 3978259f4a66faf8ef75a08da26205f0f89bd0fb Mon Sep 17 00:00:00 2001 From: LtWorf Date: Mon, 7 Nov 2011 19:01:33 +0000 Subject: [PATCH] - improved an optimization, to produce a simpler select condition under certain circumstances git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@343 014f5005-505e-4b48-8d0a-63407b615a7c --- CHANGELOG | 1 + relational/optimizations.py | 17 ++++++++++++++++- test/select_join_opt.query | 1 + test/select_join_opt.result | 3 +++ 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 test/select_join_opt.query create mode 100644 test/select_join_opt.result diff --git a/CHANGELOG b/CHANGELOG index 6e0f286..fc23812 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ 1.2 - Better tokenizer, gives more indicative errors - Parser gives more indicative errors +- Improved select_union_intersect_subtract optimization to avoid parenthesis whenever possible 1.1 - Incorrect relational operations now raise an exception instead of returning None diff --git a/relational/optimizations.py b/relational/optimizations.py index 0a4db5e..18885cb 100644 --- a/relational/optimizations.py +++ b/relational/optimizations.py @@ -475,7 +475,22 @@ def select_union_intersect_subtract(n): newnode=parser.node() - newnode.prop='((%s) %s (%s))' % (n.left.prop,op,n.right.prop) + if n.left.prop.startswith('(') or n.right.prop.startswith('('): + t_str='(' + if n.left.prop.startswith('('): + t_str+='(%s)' + else: + t_str+='%s' + t_str+=' %s ' + if n.right.prop.startswith('('): + t_str+='(%s)' + else: + t_str+='%s' + t_str+=')' + + newnode.prop= t_str % (n.left.prop,op,n.right.prop) + else: + newnode.prop='%s %s %s' % (n.left.prop,op,n.right.prop) newnode.name=SELECTION newnode.child=n.left.child newnode.kind=parser.UNARY diff --git a/test/select_join_opt.query b/test/select_join_opt.query new file mode 100644 index 0000000..384b709 --- /dev/null +++ b/test/select_join_opt.query @@ -0,0 +1 @@ +σ skill=='C' and chief==0 ((σ age<30 (people) ᑌ σ age>40(people)) ᐅᐊ skills) diff --git a/test/select_join_opt.result b/test/select_join_opt.result new file mode 100644 index 0000000..8a76bff --- /dev/null +++ b/test/select_join_opt.result @@ -0,0 +1,3 @@ +id,name,chief,age,skill +0,jack,0,22,C +4,eve,0,25,C