/* // $Id: //guest/julian_hyde/saffron/src/main/saffron/opt/RelSet.java#3 $ // 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 saffron.rel.Rel; import saffron.util.Util; import java.util.Set; import java.util.Vector; /** * A <code>RelSet</code> is an equivalence-set of expressions; that is, a set * of expressions which have identical semantics. We are generally interested * in using the expression which has the lowest cost. * * <p>All of the expressions in an <code>RelSet</code> have the same calling * convention.</p> * * @author jhyde * @since 16 December, 2001 * @version $Id: //guest/julian_hyde/saffron/src/main/saffron/opt/RelSet.java#3 $ **/ public class RelSet { Rel rel; int id; Vector rels; Vector subsets; /** Set to false after the set has been merged with another. **/ boolean alive = true; Set variablesSet; Set variablesUsed; RelSet() { this.rels = new Vector(); this.subsets = new Vector(); } /** * Add a relational expression to a set, with its results available * under a particular calling convention. An expression may be in the * set several times with different calling conventions (and hence * different costs). */ public RelSubset add(Rel rel) { RelSubset subset = getOrCreateSubset( rel.getCluster(), rel.getConvention()); boolean fail = false; subset.add(rel, fail); return subset; } /** * Adds an expression <code>rel</code> to this set, without creating a * {@link saffron.opt.RelSubset}. (Called only from {@link * saffron.opt.RelSubset#add}. **/ void addInternal(Rel rel) { if (!rels.contains(rel)) { rels.addElement(rel); } if (this.rel == null) { this.rel = rel; } else { Util.assert(rel.getCorelVariable() == null); String corel = this.rel.getCorelVariable(); if (corel != null) { rel.setCorelVariable(corel); } if (this.rel.getRowType() != rel.getRowType()) { failType(rel); } } } private void failType(Rel rel) { String s = "Cannot add expression of different type to set: " + Util.lineSeparator + "set type is " + this.rel.getRowType() + Util.lineSeparator + "expression type is " + rel.getRowType() + Util.lineSeparator + "set is " + toString() + Util.lineSeparator + "expression is " + rel.toString(); throw Util.newInternal(s); } RelSubset getOrCreateSubset(Cluster cluster, int convention) { RelSubset subset = getSubset(convention); if (subset == null) { subset = new RelSubset(cluster, this, convention); subsets.addElement(subset); } return subset; } public RelSubset getSubset(int convention) { for (int i = 0; i < subsets.size(); i++) { RelSubset subset = (RelSubset) subsets.elementAt(i); if (subset.convention == convention) { return subset; } } return null; } void mergeWith(VolcanoPlanner planner, RelSet set) { Util.assert(this != set); Util.assert(alive); if (!set.alive) { return; // set has already been merged } set.alive = false; // remove from table boolean existed = planner.allSets.remove(set); Util.assert(existed, "merging with a dead set"); // merge subsets for (int i = 0; i < set.subsets.size(); i++) { RelSubset subset = (RelSubset) set.subsets.elementAt(i); for (int j = 0; j < subset.rels.size(); j++) { Rel rel = (Rel) subset.rels.elementAt(j); RelSubset subset2 = add(rel); planner.mapRel2Subset.put(rel, subset2); } } } } // End RelSet.java
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 1801 | Julian Hyde |
saffron: add ObjectSchema; rules can now be matched more than once; started to implement correlations in queries in from list. |
||
#2 | 1474 | Julian Hyde |
saffron: Aggregations are working. Renamed 'aggregator' to 'aggregation'. |
||
#1 | 1467 | Julian Hyde |
saffron: First saffron check-in; incorporate my changes to openjava. |