Search in sources :

Example 6 with MaterializedViewInfo

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;
}
Also used : MaterializedViewInfo(org.voltdb.catalog.MaterializedViewInfo) Statement(org.voltdb.catalog.Statement) ArrayList(java.util.ArrayList) IndexRef(org.voltdb.catalog.IndexRef) Column(org.voltdb.catalog.Column) MaterializedViewHandlerInfo(org.voltdb.catalog.MaterializedViewHandlerInfo) ExpressionType(org.voltdb.types.ExpressionType)

Aggregations

MaterializedViewInfo (org.voltdb.catalog.MaterializedViewInfo)6 Table (org.voltdb.catalog.Table)5 MaterializedViewHandlerInfo (org.voltdb.catalog.MaterializedViewHandlerInfo)4 ArrayList (java.util.ArrayList)3 Column (org.voltdb.catalog.Column)3 HashSet (java.util.HashSet)2 JSONException (org.json_voltpatches.JSONException)2 IndexRef (org.voltdb.catalog.IndexRef)2 AbstractExpression (org.voltdb.expressions.AbstractExpression)2 TupleValueExpression (org.voltdb.expressions.TupleValueExpression)2 ExpressionType (org.voltdb.types.ExpressionType)2 File (java.io.File)1 HashMap (java.util.HashMap)1 HSQLParseException (org.hsqldb_voltpatches.HSQLInterface.HSQLParseException)1 VoltXMLElement (org.hsqldb_voltpatches.VoltXMLElement)1 ColumnRef (org.voltdb.catalog.ColumnRef)1 Constraint (org.voltdb.catalog.Constraint)1 Database (org.voltdb.catalog.Database)1 Index (org.voltdb.catalog.Index)1 Statement (org.voltdb.catalog.Statement)1