public static boolean isRowFilteringPlan(final RelMetadataQuery mq, RelNode operator) {
    final Multimap<Class<? extends RelNode>, RelNode> nodesBelowNonFkInput =
        mq.getNodeTypes(operator);
    for (Entry<Class<? extends RelNode>, Collection<RelNode>> e :
        nodesBelowNonFkInput.asMap().entrySet()) {
      if (e.getKey() == Project.class) {
        // It does not alter cardinality, continue
        continue;
      }

      if (e.getKey() == TableScan.class) {
        if (e.getValue().size() > 1) {
          // Bail out as we may not have more than one TS on non-FK side
          return true;
        }
      } else if (e.getKey() == Aggregate.class) {
        // We check there is are not grouping sets
        for (RelNode node : e.getValue()) {
          Aggregate a = (Aggregate) node;
          if (a.getGroupType() != Group.SIMPLE) {
            // Bail out as it may change cardinality
            return true;
          }
        }
      } else if (e.getKey() == Sort.class) {
        // We check whether there is a limit clause
        for (RelNode node : e.getValue()) {
          Sort s = (Sort) node;
          if (s.fetch != null || s.offset != null) {
            // Bail out as it may change cardinality
            return true;
          }
        }
      } else {
        // Bail out, we cannot rewrite the expression if non-fk side cardinality
        // is being altered
        return true;
      }
    }
    // It passed all the tests
    return false;
  }
Given a RelNode, it checks whether there is any filtering condition
below. Basically we check whether the operators
below altered the PK cardinality in any way
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/HiveRelOptUtil.java