private boolean disableSemiJoinOptDueToExternalTable(HiveConf conf, TableScanOperator ts, DynamicListContext ctx) {
    boolean disableSemiJoin = false;
    if (conf.getBoolVar(HiveConf.ConfVars.HIVE_DISABLE_UNSAFE_EXTERNALTABLE_OPERATIONS)) {
      // We already have the TableScan for one side of the join. Check this now.
      if (!StatsUtils.checkCanProvideStats(new Table(ts.getConf().getTableMetadata().getTTable()))) {
        LOG.debug("Disabling semijoin optimzation on {} since it is an external table and also could not provide statistics.",
            ts.getConf().getTableMetadata().getFullyQualifiedName());
        disableSemiJoin = true;
      } else {
        // Check the other side of the join, using the DynamicListContext
        ExprNodeDesc exprNodeDesc = ctx.getKeyCol();
        ExprNodeColumnDesc colExpr = ExprNodeDescUtils.getColumnExpr(exprNodeDesc);

        if (colExpr != null) {
          // fetch table alias
          ExprNodeDescUtils.ColumnOrigin columnOrigin =
                  ExprNodeDescUtils.findColumnOrigin(exprNodeDesc, ctx.generator);
          if (columnOrigin != null && columnOrigin.op instanceof TableScanOperator) {
            // Join key origin has been traced to a table column. Check if the table is external.
            TableScanOperator joinKeyTs = (TableScanOperator) columnOrigin.op;
            if (!StatsUtils.checkCanProvideStats(new Table(joinKeyTs.getConf().getTableMetadata().getTTable()))) {
              LOG.debug("Join key {} is from {} which is an external table and also could not provide statistics. " +
                      "Disabling semijoin optimization.",
                  columnOrigin.col,
                  joinKeyTs.getConf().getTableMetadata().getFullyQualifiedName());
              disableSemiJoin = true;
            }
          }
        }
      }
    }
    return disableSemiJoin;
  }
This optimization looks for expressions of the kind "x IN (RS[n])". If such
an expression made it to a table scan operator and x is a partition column we
can use an existing join to dynamically prune partitions. This class sets up
the infrastructure for that.
ql/src/java/org/apache/hadoop/hive/ql/optimizer/DynamicPartitionPruningOptimization.java