public List<org.apache.hadoop.hive.common.TableName> getTableNamesWithStats() throws MetaException {
    // Could we also join with ACID tables to only get tables with outdated stats?
    String queryText0 = "SELECT DISTINCT " + TBLS + ".\"TBL_NAME\", " + DBS + ".\"NAME\", "
        + DBS + ".\"CTLG_NAME\" FROM " + TBLS + " INNER JOIN " + DBS + " ON "
        + TBLS + ".\"DB_ID\" = " + DBS + ".\"DB_ID\"";
    String queryText1 = " WHERE " + TBLS + ".\"TBL_TYPE\" IN ("
        + makeParams(STATS_TABLE_TYPES.length) + ")";

    List<org.apache.hadoop.hive.common.TableName> result = new ArrayList<>();

    String queryText = queryText0 + " INNER JOIN " + TAB_COL_STATS
        + " ON " + TBLS + ".\"TBL_ID\" = " + TAB_COL_STATS + ".\"TBL_ID\"" + queryText1;
    getStatsTableListResult(queryText, result);

    queryText = queryText0 + " INNER JOIN " + PARTITIONS + " ON " + TBLS + ".\"TBL_ID\" = "
        + PARTITIONS + ".\"TBL_ID\"" + " INNER JOIN " + PART_COL_STATS + " ON " + PARTITIONS
        + ".\"PART_ID\" = " + PART_COL_STATS + ".\"PART_ID\"" + queryText1;
    getStatsTableListResult(queryText, result);

    return result;
  }
Checks if the column descriptors still has references for other SD-s. If not, then removes
them. Should be called with the list short enough to not trip up Oracle/etc.
@param columnDescriptorIdList The column identifiers
@throws MetaException If there is an SQL exception during the execution it converted to
MetaException
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java