From 923ac1258813b888500f7cfee987c5bee6f236c5 Mon Sep 17 00:00:00 2001 From: LtWorf Date: Tue, 28 Apr 2009 20:50:04 +0000 Subject: [PATCH] added module to contain optimizations git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@134 014f5005-505e-4b48-8d0a-63407b615a7c --- relational/optimizations.py | 28 ++++++++++++++++++++++++++++ relational/optimizer.py | 11 ++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 relational/optimizations.py diff --git a/relational/optimizations.py b/relational/optimizations.py new file mode 100644 index 0000000..2cf9cb9 --- /dev/null +++ b/relational/optimizations.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Relational +# Copyright (C) 2009 Salvo "LtWorf" Tomaselli +# +# Relation is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# author Salvo "LtWorf" Tomaselli + +'''This module contains functions to perform various optimizations on the expression trees. +The list general_optimizations contains pointers to general functions, so they can be called +within a cycle.''' + +def duplicated_select(n): + pass + + +general_optimizations=[duplicated_select] \ No newline at end of file diff --git a/relational/optimizer.py b/relational/optimizer.py index 9b457a2..4b0472a 100644 --- a/relational/optimizer.py +++ b/relational/optimizer.py @@ -20,6 +20,9 @@ '''This module optimizes relational expressions into ones that require less time to be executed For now it is highly experimental, and it shouldn't be used in 3rd party applications.''' + +import optimizations + RELATION=0 UNARY=1 BINARY=2 @@ -165,12 +168,14 @@ def tokenize(expression): def tree(expression): '''This function parses a relational algebra expression into a tree and returns the root node using the Node class defined in this module.''' - #isinstance(k,list) return node(tokenize(expression)) -def optimize(expression): +def general_optimize(expression): + '''This function performs general optimizations. Means that it will not need to + know the fields used by the relations''' n=tree(expression) #Gets the tree - + for i in optimizations.general_optimizations: + n=i(n) #Performs the optimization return n.__str__() if __name__=="__main__":