Exemplo n.º 1
0
  /**
   * Return best iterator for computing a given logical join, given the specified statistics, and
   * the provided left and right subplans. Note that there is insufficient information to determine
   * which plan should be the inner/outer here -- because DbIterator's don't provide any cardinality
   * estimates, and stats only has information about the base tables. For this reason, the plan1
   *
   * @param lj The join being considered
   * @param plan1 The left join node's child
   * @param plan2 The right join node's child
   */
  public static DbIterator instantiateJoin(LogicalJoinNode lj, DbIterator plan1, DbIterator plan2)
      throws ParsingException {

    int t1id = 0, t2id = 0;
    DbIterator j;

    try {
      t1id = plan1.getTupleDesc().fieldNameToIndex(lj.f1QuantifiedName);
    } catch (NoSuchElementException e) {
      throw new ParsingException("Unknown field " + lj.f1QuantifiedName);
    }

    if (lj instanceof LogicalSubplanJoinNode) {
      t2id = 0;
    } else {
      try {
        t2id = plan2.getTupleDesc().fieldNameToIndex(lj.f2QuantifiedName);
      } catch (NoSuchElementException e) {
        throw new ParsingException("Unknown field " + lj.f2QuantifiedName);
      }
    }

    JoinPredicate p = new JoinPredicate(t1id, lj.p, t2id);

    j = new Join(p, plan1, plan2);

    return j;
  }