Search in sources :

Example 1 with DBCPlanStyle

use of org.jkiss.dbeaver.model.exec.plan.DBCPlanStyle in project dbeaver by dbeaver.

the class SQLEditor method explainQueryPlan.

private void explainQueryPlan(SQLQuery sqlQuery) {
    // 1. Determine whether planner supports plan extraction
    DBCQueryPlanner planner = DBUtils.getAdapter(DBCQueryPlanner.class, getDataSource());
    if (planner == null) {
        DBUserInterface.getInstance().showError("Execution plan", "Execution plan explain isn't supported by current datasource");
        return;
    }
    DBCPlanStyle planStyle = planner.getPlanStyle();
    if (planStyle == DBCPlanStyle.QUERY) {
        explainPlanFromQuery(planner, sqlQuery);
        return;
    }
    ExplainPlanViewer planView = null;
    for (CTabItem item : resultTabs.getItems()) {
        if (item.getData() instanceof ExplainPlanViewer) {
            ExplainPlanViewer pv = (ExplainPlanViewer) item.getData();
            if (pv.getQuery() != null && pv.getQuery().equals(sqlQuery)) {
                resultTabs.setSelection(item);
                planView = pv;
                break;
            }
        }
    }
    if (planView == null) {
        planView = new ExplainPlanViewer(this, resultTabs);
        final CTabItem item = new CTabItem(resultTabs, SWT.CLOSE);
        item.setControl(planView.getControl());
        item.setText("Exec. Plan");
        item.setToolTipText("Execution plan for\n" + sqlQuery.getText());
        item.setImage(IMG_EXPLAIN_PLAN);
        item.setData(planView);
        UIUtils.disposeControlOnItemDispose(item);
        resultTabs.setSelection(item);
    }
    try {
        planView.explainQueryPlan(getExecutionContext(), sqlQuery);
    } catch (DBCException e) {
        DBUserInterface.getInstance().showError(CoreMessages.editors_sql_error_execution_plan_title, CoreMessages.editors_sql_error_execution_plan_message, e);
    }
}
Also used : DBCQueryPlanner(org.jkiss.dbeaver.model.exec.plan.DBCQueryPlanner) DBCPlanStyle(org.jkiss.dbeaver.model.exec.plan.DBCPlanStyle) ExplainPlanViewer(org.jkiss.dbeaver.ui.views.plan.ExplainPlanViewer) CTabItem(org.eclipse.swt.custom.CTabItem)

Example 2 with DBCPlanStyle

use of org.jkiss.dbeaver.model.exec.plan.DBCPlanStyle in project dbeaver by serge-rider.

the class SQLEditor method explainQueryPlan.

private void explainQueryPlan(SQLQuery sqlQuery) {
    DBCQueryPlanner planner = GeneralUtils.adapt(getDataSource(), DBCQueryPlanner.class);
    DBCPlanStyle planStyle = planner.getPlanStyle();
    if (planStyle == DBCPlanStyle.QUERY) {
        explainPlanFromQuery(planner, sqlQuery);
    } else if (planStyle == DBCPlanStyle.OUTPUT) {
        explainPlanFromQuery(planner, sqlQuery);
        showOutputPanel();
    } else {
        ExplainPlanViewer planView = getPlanView(sqlQuery, planner);
        if (planView != null) {
            planView.explainQueryPlan(sqlQuery, planner);
        }
    }
}
Also used : DBCQueryPlanner(org.jkiss.dbeaver.model.exec.plan.DBCQueryPlanner) DBCPlanStyle(org.jkiss.dbeaver.model.exec.plan.DBCPlanStyle) ExplainPlanViewer(org.jkiss.dbeaver.ui.editors.sql.plan.ExplainPlanViewer)

Aggregations

DBCPlanStyle (org.jkiss.dbeaver.model.exec.plan.DBCPlanStyle)2 DBCQueryPlanner (org.jkiss.dbeaver.model.exec.plan.DBCQueryPlanner)2 CTabItem (org.eclipse.swt.custom.CTabItem)1 ExplainPlanViewer (org.jkiss.dbeaver.ui.editors.sql.plan.ExplainPlanViewer)1 ExplainPlanViewer (org.jkiss.dbeaver.ui.views.plan.ExplainPlanViewer)1