/* // $Id: //guest/julian_hyde/saffron/src/main/saffron/opt/RelSubset.java#1 $ // Saffron preprocessor and data engine // Copyright (C) 2002 Julian Hyde <julian.hyde@mail.com> // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public // License as published by the Free Software Foundation; either // version 2 of the License, or (at your option) any later version. // // This library 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 // Library General Public License for more details. // // You should have received a copy of the GNU Library General Public // License along with this library; if not, write to the // Free Software Foundation, Inc., 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. // // See the COPYING file located in the top-level-directory of // the archive of this library for complete text of license. */ package saffron.opt; import openjava.mop.OJClass; import saffron.PlanWriter; import saffron.Planner; import saffron.rel.Rel; import saffron.util.RelVisitor; import saffron.util.Util; import java.util.Vector; /** * A <code>RelSubset</code> is set of expressions in a set which have the same * calling convention. An expression may be in more than one sub-set of a set; * the same expression is used. * * @author jhyde * @since 16 December, 2001 * @version $Id: //guest/julian_hyde/saffron/src/main/saffron/opt/RelSubset.java#1 $ **/ public class RelSubset extends Rel { RelSet set; int convention; Vector rels; Vector parents; /** cost of best known plan (it may have improved since) */ Cost bestCost; /** best known plan */ Rel best; /** whether findBestPlan is being called */ boolean active; RelSubset(Cluster cluster, RelSet set, int convention) { super(cluster); this.set = set; this.convention = convention; this.rels = new Vector(); this.parents = new Vector(); this.bestCost = VolcanoPlanner.VolcanoCost.INFINITY; } RelSet getSet() { return set; } /** Add expression <code>rel</code> to this subset. */ void add(Rel rel, boolean fail) { if (rels.contains(rel)) { if (fail) { throw Util.newInternal(); } else { return; } } rels.addElement(rel); set.addInternal(rel); } /** An <code>RelSet</code> is its own clone. */ public Object clone() { return this; } /** * There are no children, as such. We throw an exception because you * probably don't want to be walking over trees which contain * <code>RelSet</code>s. **/ public Rel[] getInputs() { throw new UnsupportedOperationException(); } // implement Rel protected OJClass deriveRowType() { return set.rel.getRowType(); } // implement Plan public Cost computeSelfCost(Planner planner) { return planner.makeZeroCost(); } // implement Rel public void explain(PlanWriter pw) { pw.explainSubset( id + ": RelSubset(" + CallingConvention.getName(convention) + ")", (Rel) rels.elementAt(0)); } // implement Rel public int getConvention() { return convention; } /** * Recursively build a tree consisting of the cheapest plan at each * node. */ Rel buildCheapestPlan(Planner planner) { CheapestPlanReplacer replacer = new CheapestPlanReplacer(planner); RelSubset clone = (RelSubset) Util.clone(this); Rel cheapest = (Rel) Util.go(replacer, clone); return cheapest; } } /** * <code>CheapestPlanReplacer</code> walks over a tree of {@link RelSet}s, * replacing each with the cheapest implementation of the expression. **/ class CheapestPlanReplacer extends RelVisitor { Planner planner; CheapestPlanReplacer(Planner planner) { super(); this.planner = planner; } // implement RelVisitor public void visit(Rel p, int ordinal, Rel parent) { if (p instanceof RelSubset) { RelSubset subset = (RelSubset) p; Rel cheapest = subset.best; if (cheapest == null) { throw Util.newInternal( "node could not be implemented: " + subset.toString()); } // todo: do we still need to notify? // for (int i = 0, n = subset.rels.size(); i < n; i++) { // ((Rel) subset.rels.elementAt(i)).notifyRefs(cheapest); // } parent.replaceInput(ordinal, cheapest); p = cheapest; } p.childrenAccept(this); } }; // End RelSubset.java
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 1801 | Julian Hyde |
saffron: add ObjectSchema; rules can now be matched more than once; started to implement correlations in queries in from list. |
||
#1 | 1467 | Julian Hyde |
saffron: First saffron check-in; incorporate my changes to openjava. |