From 6fdd572faad9e2bbaeab54b4aaae2e28a85a98d2 Mon Sep 17 00:00:00 2001 From: LtWorf Date: Mon, 11 Oct 2010 10:49:55 +0000 Subject: [PATCH] - Fixed optimization involving selection and parenthesis in the expression - Added more clear documentation in recoursive_scan git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@260 014f5005-505e-4b48-8d0a-63407b615a7c --- CHANGELOG | 3 ++- relational/optimizations.py | 23 +++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 821a5bf..857b1dd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,6 +7,7 @@ - Rename will mark the resulting relation as readonly and subsequent updates, insert, updates or deletes will actually copy the content - Added testsuite - Fixed python expression tokenization, now uses native tokenizer +- Fixed optimization involving selection and parenthesis in the expression (Rev 260) 0.11 - Font is set only on windows (Rev 206) @@ -18,7 +19,7 @@ - Added .desktop file on svn (Rev 216) - Automatically fills some fields in the survey (Rev 217) - When a query fails, shows the message of the exception (Rev220) -- Improved tokenizer for select in optimizations, now can accept operators in identifiers (Rev220) +- Improved tokenizer for select in optimizations, now can accept operators in identifiers (Rev 220) - Uses getopt to handle the command line in a more standard way - Organized code so the ui can be either qt or command line - Does not depend on QT anymore diff --git a/relational/optimizations.py b/relational/optimizations.py index 267bfd4..6a51f63 100644 --- a/relational/optimizations.py +++ b/relational/optimizations.py @@ -52,7 +52,17 @@ def replace_node(replace,replacement): replace.left=replacement.left def recoursive_scan(function,node,rels=None): - '''Does a recoursive optimization on the tree''' + '''Does a recoursive optimization on the tree. + + This function will recoursively execute the function given + as "function" parameter starting from node to all the tree. + if rels is provided it will be passed as argument to the function. + Otherwise the function will be called just on the node. + + Result value: function is supposed to return the amount of changes + it has performed on the tree. + The various result will be added up and this final value will be the + returned value.''' changes=0 #recoursive scan if node.kind==optimizer.UNARY: @@ -72,11 +82,20 @@ def recoursive_scan(function,node,rels=None): def duplicated_select(n): '''This function locates and deletes things like - σ a ( σ a(C)) and the ones like σ a ( σ b(C))''' + σ a ( σ a(C)) and the ones like σ a ( σ b(C)) + replacing the 1st one with a single select and + the 2nd one with a single select with both conditions + in and + ''' changes=0 if n.name=='σ' and n.child.name=='σ': if n.prop != n.child.prop: #Nested but different, joining them n.prop = n.prop + " and " + n.child.prop + + #This adds parenthesis if they are needed + if n.child.prop.startswith('(') or n.prop.startswith('('): + n.prop= '(%s)' % n.prop + n.child=n.child.child changes=1 changes+=duplicated_select(n)