code: void removeAllButDeepestAndAddCacheLeafNodes(int depth) {
          Queue<SchemaTableTree> queue = new LinkedList<>();
          queue.add(this);
          while (!queue.isEmpty()) {
              SchemaTableTree current = queue.remove();
              if (current.stepDepth < depth && current.children.isEmpty() && !current.isEmit() && !current.isOptionalLeftJoin()) {
                  removeNode(current);
              } else {
                  queue.addAll(current.children);
                  if ((current.stepDepth == depth && current.children.isEmpty()) || (current.isEmit() && current.children.isEmpty()) || current.isOptionalLeftJoin() && current.children.isEmpty()) {
                      this.leafNodes.add(current);
                  }
              }
          }
      }
docs: Remove all leaf nodes that are not at the deepest level.
  Those nodes are not to be included in the sql as they do not have enough incident edges.
  i.e. The graph is not deep enough along those labels.
  <p/>
  This is done via a breath first traversal.