@Override
    boolean isFatal(Exception e) {
      // Non-CBO path for the following exceptions fail with completely different error and mask the original failure
      return e instanceof CalciteSubquerySemanticException || e instanceof CalciteViewSemanticException
          || e instanceof CalciteSubqueryRuntimeException;
    }
Use the legacy optimizer only when the CBO exception is not related to subqueries and views.
ql/src/java/org/apache/hadoop/hive/ql/parse/CBOFallbackStrategy.java