private JavaFrame findFrame() {
      RelNode previous = rel;
      while (true) {
        JavaFrame frame = (JavaFrame) mapRel2Frame.get(previous);
        if (frame.bind != null) {
          tracer.log(
              Level.FINE,
              "Bind " + rel.toString() + " to " + previous.toString() + "(" + frame.bind + ")");
          return frame;
        }

        // go deeper
        List<RelNode> inputs = previous.getInputs();
        assert (inputs.size() == 1) : "input is not bound";
        previous = inputs.get(0);
      }
    }
 /**
  * Records the fact that instances of <code>rel</code> are available via <code>bind</code> (which
  * may be eager or lazy).
  */
 private void bind(RelNode rel, Bind bind) {
   tracer.log(Level.FINE, "Bind " + rel.toString() + " to " + bind);
   JavaFrame frame = (JavaFrame) mapRel2Frame.get(rel);
   frame.bind = bind;
   boolean stupid = SaffronProperties.instance().stupid.get();
   if (stupid) {
     // trigger the declaration of the variable, even though it
     // may not be used
     Util.discard(bind.getVariable());
   }
 }