public static RelNode getMaterializedViewByAST(
          ASTNode expandedAST, RelOptCluster optCluster,
          Predicate<Set<RewriteAlgorithm>> filter,
          Hive db,
          Set<TableName> tablesUsedByOriginalPlan,
          Supplier<String> validTxnsList, HiveTxnManager txnManager) {
    try {
      List<HiveRelOptMaterialization> relOptMaterializationList = db.getMaterializedViewsByAST(
          expandedAST, tablesUsedByOriginalPlan, validTxnsList, txnManager);
      for (HiveRelOptMaterialization relOptMaterialization : relOptMaterializationList) {
        if (!filter.test(relOptMaterialization.getScope())) {
          LOG.debug("Filter out materialized view {} scope {}",
                  relOptMaterialization.qualifiedTableName, relOptMaterialization.getScope());
          continue;
        }

        try {
          Table hiveTableMD = extractTable(relOptMaterialization);
          if (HiveMaterializedViewUtils.checkPrivilegeForMaterializedViews(singletonList(hiveTableMD))) {
            Set<TableName> sourceTables = new HashSet<>(1);
            sourceTables.add(hiveTableMD.getFullTableName());
            if (db.validateMaterializedViewsFromRegistry(
                  singletonList(hiveTableMD), sourceTables, validTxnsList, txnManager)) {
              return relOptMaterialization.copyToNewCluster(optCluster).tableRel;
            }
          } else {
            LOG.debug("User does not have privilege to use materialized view {}",
                    relOptMaterialization.qualifiedTableName);
          }
        } catch (HiveException e) {
          LOG.warn("Skipping materialized view due to validation failure: " +
                  relOptMaterialization.qualifiedTableName, e);
        }
      }
    } catch (HiveException e) {
      LOG.warn(String.format("Exception while looking up materialized views for query '%s'", expandedAST), e);
    }

    return null;
  }
1. Look up MVs in the registry by AST
2. Check if we have the correct privilege to scan those MVs
3. Validate if they are up-to-date
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/HiveMaterializedViewASTSubQueryRewriteShuttle.java