private static boolean swapInputs(
          RelMetadataQuery mq,
          HiveLoptMultiJoin multiJoin,
          HiveLoptJoinTree left,
          HiveLoptJoinTree right,
          boolean selfJoin) {
    boolean swap = false;

    if (selfJoin) {
      return !multiJoin.isLeftFactorInRemovableSelfJoin(
              ((HiveLoptJoinTree.Leaf) left.getFactorTree()).getId());
    }

    final Double leftRowCount = mq.getRowCount(left.getJoinTree());
    final Double rightRowCount = mq.getRowCount(right.getJoinTree());

    // The left side is smaller than the right if it has fewer rows,
    // or if it has the same number of rows as the right (excluding
    // roundoff), but fewer columns.
    if ((leftRowCount != null)
            && (rightRowCount != null)
            && ((leftRowCount < rightRowCount)
            || ((Math.abs(leftRowCount - rightRowCount) < RelOptUtil.EPSILON)
            && (rowWidthCost(left.getJoinTree()) < rowWidthCost(right.getJoinTree()))))) {
      swap = true;
    }
    return swap;
  }
Swaps the operands to a join, so the smaller input is on the right. Or,
if this is a removable self-join, swap so the factor that should be
preserved when the self-join is removed is put on the left.

@param multiJoin join factors being optimized
@param left left side of join tree
@param right right hand side of join tree
@param selfJoin true if the join is a removable self-join

@return true if swapping should be done
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveLoptOptimizeJoinRule.java