use of org.voltdb.catalog.MaterializedViewInfo in project voltdb by VoltDB.
the class ViewExplainer method explain.
public static ArrayList<String[]> explain(Table viewTable) throws Exception {
String viewName = viewTable.getTypeName();
MaterializedViewHandlerInfo mvHandlerInfo = viewTable.getMvhandlerinfo().get("mvHandlerInfo");
MaterializedViewInfo mvInfo = null;
CatalogMap<Statement> fallBackQueryStmts;
List<Column> destColumnArray = CatalogUtil.getSortedCatalogItems(viewTable.getColumns(), "index");
ArrayList<String[]> retval = new ArrayList<String[]>();
// Is this view single-table?
if (mvHandlerInfo == null) {
// (Legacy code for single table view uses a different model and code path)
if (viewTable.getMaterializer() == null) {
// If we cannot find view metadata from both locations, this table is not a materialized view.
throw new Exception("Table " + viewName + " is not a view.");
}
mvInfo = viewTable.getMaterializer().getViews().get(viewName);
fallBackQueryStmts = mvInfo.getFallbackquerystmts();
} else {
// For multi-table views we need to show the query plan for evaluating joins.
Statement createQuery = mvHandlerInfo.getCreatequery().get("createQuery");
retval.add(new String[] { "Join Evaluation", Encoder.hexDecodeToString(createQuery.getExplainplan()) });
fallBackQueryStmts = mvHandlerInfo.getFallbackquerystmts();
}
// For each min/max column find out if an execution plan is used.
int minMaxAggIdx = 0;
for (int j = 0; j < destColumnArray.size(); j++) {
Column destColumn = destColumnArray.get(j);
ExpressionType aggType = ExpressionType.get(destColumn.getAggregatetype());
if (aggType == ExpressionType.AGGREGATE_MIN || aggType == ExpressionType.AGGREGATE_MAX) {
Statement fallBackQueryStmt = fallBackQueryStmts.get(String.valueOf(minMaxAggIdx));
// How this min/max will be refreshed?
String plan = "";
// * execution plan
if (mvHandlerInfo == null) {
CatalogMap<IndexRef> hardCodedIndicesForSingleTableView = mvInfo.getIndexforminmax();
String hardCodedIndexName = hardCodedIndicesForSingleTableView.get(String.valueOf(minMaxAggIdx)).getName();
String indexNameUsedInStatement = getIndexNameUsedInStatement(fallBackQueryStmt);
if (!indexNameUsedInStatement.equalsIgnoreCase(hardCodedIndexName)) {
plan = Encoder.hexDecodeToString(fallBackQueryStmt.getExplainplan());
}
// If we do not use execution plan, see which built-in method is used.
if (plan.equals("")) {
if (hardCodedIndexName.equals("")) {
plan = "Built-in sequential scan.";
} else {
plan = "Built-in index scan \"" + hardCodedIndexName + "\".";
}
}
} else {
plan = Encoder.hexDecodeToString(fallBackQueryStmt.getExplainplan());
}
retval.add(new String[] { "Refresh " + (aggType == ExpressionType.AGGREGATE_MIN ? "MIN" : "MAX") + " column \"" + destColumn.getName() + "\"", plan });
minMaxAggIdx++;
}
}
return retval;
}
Aggregations