Search in sources :

Example 1 with DBCQueryPlannerConfiguration

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

the class SQLEditor method explainPlanFromQuery.

private void explainPlanFromQuery(final DBCQueryPlanner planner, final SQLQuery sqlQuery) {
    final String[] planQueryString = new String[1];
    DBRRunnableWithProgress queryObtainTask = monitor -> {
        DBCQueryPlannerConfiguration configuration = ExplainPlanViewer.makeExplainPlanConfiguration(monitor, planner);
        if (configuration == null) {
            return;
        }
        try (DBCSession session = getExecutionContext().openSession(monitor, DBCExecutionPurpose.UTIL, "Prepare plan query")) {
            DBCPlan plan = planner.planQueryExecution(session, sqlQuery.getText(), configuration);
            planQueryString[0] = plan.getPlanQueryString();
        } catch (Exception e) {
            log.error(e);
        }
    };
    if (RuntimeUtils.runTask(queryObtainTask, "Retrieve plan query", 5000) && !CommonUtils.isEmpty(planQueryString[0])) {
        SQLQuery planQuery = new SQLQuery(getDataSource(), planQueryString[0]);
        processQueries(Collections.singletonList(planQuery), false, true, false, true, null, null);
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) DBCPlanStyle(org.jkiss.dbeaver.model.exec.plan.DBCPlanStyle) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) DBDDataFilter(org.jkiss.dbeaver.model.data.DBDDataFilter) Point(org.eclipse.swt.graphics.Point) DBNUtils(org.jkiss.dbeaver.model.navigator.DBNUtils) Matcher(java.util.regex.Matcher) ScriptPositionColumn(org.jkiss.dbeaver.ui.editors.text.ScriptPositionColumn) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) EFS(org.eclipse.core.filesystem.EFS) DatabaseTransferProducer(org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferProducer) CTabFolder(org.eclipse.swt.custom.CTabFolder) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) ExplainPlanViewer(org.jkiss.dbeaver.ui.editors.sql.plan.ExplainPlanViewer) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IDataTransferProducer(org.jkiss.dbeaver.tools.transfer.IDataTransferProducer) SQLQueryDataContainer(org.jkiss.dbeaver.model.sql.data.SQLQueryDataContainer) org.jkiss.dbeaver.ui.controls.resultset(org.jkiss.dbeaver.ui.controls.resultset) RuntimeUtils(org.jkiss.dbeaver.utils.RuntimeUtils) SWT(org.eclipse.swt.SWT) DefaultServerOutputReader(org.jkiss.dbeaver.model.impl.DefaultServerOutputReader) PrefUtils(org.jkiss.dbeaver.utils.PrefUtils) DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) IColumnSupport(org.eclipse.ui.texteditor.rulers.IColumnSupport) java.util(java.util) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore) SimpleDateFormat(java.text.SimpleDateFormat) AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) NotNull(org.jkiss.code.NotNull) EditorUtils(org.jkiss.dbeaver.ui.editors.EditorUtils) INavigatorModelView(org.jkiss.dbeaver.ui.navigator.INavigatorModelView) IFile(org.eclipse.core.resources.IFile) ResultSetMessages(org.jkiss.dbeaver.ui.controls.resultset.internal.ResultSetMessages) GridData(org.eclipse.swt.layout.GridData) RulerColumnRegistry(org.eclipse.ui.texteditor.rulers.RulerColumnRegistry) DBDDataReceiver(org.jkiss.dbeaver.model.data.DBDDataReceiver) org.jkiss.dbeaver.model(org.jkiss.dbeaver.model) org.eclipse.swt.events(org.eclipse.swt.events) SQLPresentationRegistry(org.jkiss.dbeaver.ui.editors.sql.registry.SQLPresentationRegistry) org.eclipse.swt.widgets(org.eclipse.swt.widgets) DBSInstance(org.jkiss.dbeaver.model.struct.DBSInstance) UIServiceConnections(org.jkiss.dbeaver.runtime.ui.UIServiceConnections) SourceViewer(org.eclipse.jface.text.source.SourceViewer) org.eclipse.ui(org.eclipse.ui) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput) org.eclipse.core.runtime(org.eclipse.core.runtime) org.jkiss.dbeaver.model.sql(org.jkiss.dbeaver.model.sql) GridLayout(org.eclipse.swt.layout.GridLayout) StringEditorInput(org.jkiss.dbeaver.ui.editors.StringEditorInput) org.eclipse.jface.action(org.eclipse.jface.action) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) CompoundContributionItem(org.eclipse.ui.actions.CompoundContributionItem) org.jkiss.dbeaver.ui(org.jkiss.dbeaver.ui) DefaultRangeIndicator(org.eclipse.ui.texteditor.DefaultRangeIndicator) org.eclipse.jface.text(org.eclipse.jface.text) SQLLogPanel(org.jkiss.dbeaver.ui.editors.sql.log.SQLLogPanel) SQLPresentationPanelDescriptor(org.jkiss.dbeaver.ui.editors.sql.registry.SQLPresentationPanelDescriptor) ModelMessages(org.jkiss.dbeaver.model.messages.ModelMessages) SQLPresentationDescriptor(org.jkiss.dbeaver.ui.editors.sql.registry.SQLPresentationDescriptor) QMUtils(org.jkiss.dbeaver.model.qm.QMUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) URI(java.net.URI) RulerColumnDescriptor(org.eclipse.ui.texteditor.rulers.RulerColumnDescriptor) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) SQLResultsConsumer(org.jkiss.dbeaver.runtime.sql.SQLResultsConsumer) DBCQueryPlannerConfiguration(org.jkiss.dbeaver.model.exec.plan.DBCQueryPlannerConfiguration) GeneralUtils(org.jkiss.dbeaver.utils.GeneralUtils) CommonUtils(org.jkiss.utils.CommonUtils) IFileState(org.eclipse.core.resources.IFileState) DBCPlan(org.jkiss.dbeaver.model.exec.plan.DBCPlan) NLS(org.eclipse.osgi.util.NLS) DBCQueryPlanner(org.jkiss.dbeaver.model.exec.plan.DBCQueryPlanner) org.jkiss.dbeaver.ui.controls(org.jkiss.dbeaver.ui.controls) SQLEditorMessages(org.jkiss.dbeaver.ui.editors.sql.internal.SQLEditorMessages) DBStyles(org.jkiss.dbeaver.ui.css.DBStyles) List(java.util.List) DBException(org.jkiss.dbeaver.DBException) SQLNavigatorContext(org.jkiss.dbeaver.ui.editors.sql.handlers.SQLNavigatorContext) ITextEditorActionConstants(org.eclipse.ui.texteditor.ITextEditorActionConstants) DatabaseEditorUtils(org.jkiss.dbeaver.ui.editors.DatabaseEditorUtils) Pattern(java.util.regex.Pattern) EnterNameDialog(org.jkiss.dbeaver.ui.dialogs.EnterNameDialog) Image(org.eclipse.swt.graphics.Image) Nullable(org.jkiss.code.Nullable) INonPersistentEditorInput(org.jkiss.dbeaver.ui.editors.INonPersistentEditorInput) DBRProgressListener(org.jkiss.dbeaver.model.runtime.DBRProgressListener) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) SQLQueryJob(org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob) SQLQueryTransformerCount(org.jkiss.dbeaver.model.impl.sql.SQLQueryTransformerCount) FillLayout(org.eclipse.swt.layout.FillLayout) ModelPreferences(org.jkiss.dbeaver.ModelPreferences) IFileStore(org.eclipse.core.filesystem.IFileStore) Job(org.eclipse.core.runtime.jobs.Job) org.jkiss.dbeaver.model.exec(org.jkiss.dbeaver.model.exec) ArrayUtils(org.jkiss.utils.ArrayUtils) DataSourceUtils(org.jkiss.dbeaver.registry.DataSourceUtils) CTabItem(org.eclipse.swt.custom.CTabItem) CSSUtils(org.jkiss.dbeaver.ui.css.CSSUtils) DataTransferWizard(org.jkiss.dbeaver.tools.transfer.ui.wizard.DataTransferWizard) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer) java.io(java.io) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) ConfirmationDialog(org.jkiss.dbeaver.ui.dialogs.ConfirmationDialog) DBCPlan(org.jkiss.dbeaver.model.exec.plan.DBCPlan) DBCQueryPlannerConfiguration(org.jkiss.dbeaver.model.exec.plan.DBCQueryPlannerConfiguration) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBException(org.jkiss.dbeaver.DBException)

Example 2 with DBCQueryPlannerConfiguration

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

the class SQLEditor method explainPlanFromQuery.

private void explainPlanFromQuery(final DBCQueryPlanner planner, final SQLQuery sqlQuery) {
    final String[] planQueryString = new String[1];
    DBRRunnableWithProgress queryObtainTask = monitor -> {
        DBCQueryPlannerConfiguration configuration = ExplainPlanViewer.makeExplainPlanConfiguration(monitor, planner);
        if (configuration == null) {
            return;
        }
        try (DBCSession session = getExecutionContext().openSession(monitor, DBCExecutionPurpose.UTIL, "Prepare plan query")) {
            DBCPlan plan = planner.planQueryExecution(session, sqlQuery.getText(), configuration);
            planQueryString[0] = plan.getPlanQueryString();
        } catch (Exception e) {
            log.error(e);
        }
    };
    if (RuntimeUtils.runTask(queryObtainTask, "Retrieve plan query", 5000) && !CommonUtils.isEmpty(planQueryString[0])) {
        SQLQuery planQuery = new SQLQuery(getDataSource(), planQueryString[0]);
        processQueries(Collections.singletonList(planQuery), false, true, false, true, null, null);
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) DBCPlanStyle(org.jkiss.dbeaver.model.exec.plan.DBCPlanStyle) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) DBDDataFilter(org.jkiss.dbeaver.model.data.DBDDataFilter) Point(org.eclipse.swt.graphics.Point) DBNUtils(org.jkiss.dbeaver.model.navigator.DBNUtils) Matcher(java.util.regex.Matcher) ScriptPositionColumn(org.jkiss.dbeaver.ui.editors.text.ScriptPositionColumn) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) EFS(org.eclipse.core.filesystem.EFS) DatabaseTransferProducer(org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferProducer) CTabFolder(org.eclipse.swt.custom.CTabFolder) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) ExplainPlanViewer(org.jkiss.dbeaver.ui.editors.sql.plan.ExplainPlanViewer) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IDataTransferProducer(org.jkiss.dbeaver.tools.transfer.IDataTransferProducer) SQLQueryDataContainer(org.jkiss.dbeaver.model.sql.data.SQLQueryDataContainer) org.jkiss.dbeaver.ui.controls.resultset(org.jkiss.dbeaver.ui.controls.resultset) RuntimeUtils(org.jkiss.dbeaver.utils.RuntimeUtils) SWT(org.eclipse.swt.SWT) DefaultServerOutputReader(org.jkiss.dbeaver.model.impl.DefaultServerOutputReader) PrefUtils(org.jkiss.dbeaver.utils.PrefUtils) DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) IColumnSupport(org.eclipse.ui.texteditor.rulers.IColumnSupport) java.util(java.util) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore) SimpleDateFormat(java.text.SimpleDateFormat) AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) NotNull(org.jkiss.code.NotNull) EditorUtils(org.jkiss.dbeaver.ui.editors.EditorUtils) INavigatorModelView(org.jkiss.dbeaver.ui.navigator.INavigatorModelView) IFile(org.eclipse.core.resources.IFile) ResultSetMessages(org.jkiss.dbeaver.ui.controls.resultset.internal.ResultSetMessages) GridData(org.eclipse.swt.layout.GridData) RulerColumnRegistry(org.eclipse.ui.texteditor.rulers.RulerColumnRegistry) DBDDataReceiver(org.jkiss.dbeaver.model.data.DBDDataReceiver) org.jkiss.dbeaver.model(org.jkiss.dbeaver.model) org.eclipse.swt.events(org.eclipse.swt.events) SQLPresentationRegistry(org.jkiss.dbeaver.ui.editors.sql.registry.SQLPresentationRegistry) org.eclipse.swt.widgets(org.eclipse.swt.widgets) DBSInstance(org.jkiss.dbeaver.model.struct.DBSInstance) UIServiceConnections(org.jkiss.dbeaver.runtime.ui.UIServiceConnections) SourceViewer(org.eclipse.jface.text.source.SourceViewer) org.eclipse.ui(org.eclipse.ui) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput) org.eclipse.core.runtime(org.eclipse.core.runtime) org.jkiss.dbeaver.model.sql(org.jkiss.dbeaver.model.sql) GridLayout(org.eclipse.swt.layout.GridLayout) StringEditorInput(org.jkiss.dbeaver.ui.editors.StringEditorInput) org.eclipse.jface.action(org.eclipse.jface.action) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) CompoundContributionItem(org.eclipse.ui.actions.CompoundContributionItem) org.jkiss.dbeaver.ui(org.jkiss.dbeaver.ui) DefaultRangeIndicator(org.eclipse.ui.texteditor.DefaultRangeIndicator) org.eclipse.jface.text(org.eclipse.jface.text) SQLLogPanel(org.jkiss.dbeaver.ui.editors.sql.log.SQLLogPanel) SQLPresentationPanelDescriptor(org.jkiss.dbeaver.ui.editors.sql.registry.SQLPresentationPanelDescriptor) ModelMessages(org.jkiss.dbeaver.model.messages.ModelMessages) SQLPresentationDescriptor(org.jkiss.dbeaver.ui.editors.sql.registry.SQLPresentationDescriptor) QMUtils(org.jkiss.dbeaver.model.qm.QMUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) URI(java.net.URI) RulerColumnDescriptor(org.eclipse.ui.texteditor.rulers.RulerColumnDescriptor) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) SQLResultsConsumer(org.jkiss.dbeaver.runtime.sql.SQLResultsConsumer) DBCQueryPlannerConfiguration(org.jkiss.dbeaver.model.exec.plan.DBCQueryPlannerConfiguration) GeneralUtils(org.jkiss.dbeaver.utils.GeneralUtils) CommonUtils(org.jkiss.utils.CommonUtils) IFileState(org.eclipse.core.resources.IFileState) DBCPlan(org.jkiss.dbeaver.model.exec.plan.DBCPlan) NLS(org.eclipse.osgi.util.NLS) DBCQueryPlanner(org.jkiss.dbeaver.model.exec.plan.DBCQueryPlanner) org.jkiss.dbeaver.ui.controls(org.jkiss.dbeaver.ui.controls) SQLEditorMessages(org.jkiss.dbeaver.ui.editors.sql.internal.SQLEditorMessages) DBStyles(org.jkiss.dbeaver.ui.css.DBStyles) List(java.util.List) DBException(org.jkiss.dbeaver.DBException) SQLNavigatorContext(org.jkiss.dbeaver.ui.editors.sql.handlers.SQLNavigatorContext) ITextEditorActionConstants(org.eclipse.ui.texteditor.ITextEditorActionConstants) DatabaseEditorUtils(org.jkiss.dbeaver.ui.editors.DatabaseEditorUtils) Pattern(java.util.regex.Pattern) EnterNameDialog(org.jkiss.dbeaver.ui.dialogs.EnterNameDialog) Image(org.eclipse.swt.graphics.Image) Nullable(org.jkiss.code.Nullable) INonPersistentEditorInput(org.jkiss.dbeaver.ui.editors.INonPersistentEditorInput) DBRProgressListener(org.jkiss.dbeaver.model.runtime.DBRProgressListener) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) SQLQueryJob(org.jkiss.dbeaver.ui.editors.sql.execute.SQLQueryJob) SQLQueryTransformerCount(org.jkiss.dbeaver.model.impl.sql.SQLQueryTransformerCount) FillLayout(org.eclipse.swt.layout.FillLayout) ModelPreferences(org.jkiss.dbeaver.ModelPreferences) IFileStore(org.eclipse.core.filesystem.IFileStore) Job(org.eclipse.core.runtime.jobs.Job) org.jkiss.dbeaver.model.exec(org.jkiss.dbeaver.model.exec) ArrayUtils(org.jkiss.utils.ArrayUtils) DataSourceUtils(org.jkiss.dbeaver.registry.DataSourceUtils) CTabItem(org.eclipse.swt.custom.CTabItem) CSSUtils(org.jkiss.dbeaver.ui.css.CSSUtils) DataTransferWizard(org.jkiss.dbeaver.tools.transfer.ui.wizard.DataTransferWizard) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer) java.io(java.io) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) ConfirmationDialog(org.jkiss.dbeaver.ui.dialogs.ConfirmationDialog) DBCPlan(org.jkiss.dbeaver.model.exec.plan.DBCPlan) DBCQueryPlannerConfiguration(org.jkiss.dbeaver.model.exec.plan.DBCQueryPlannerConfiguration) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBException(org.jkiss.dbeaver.DBException)

Aggregations

java.io (java.io)2 URI (java.net.URI)2 SimpleDateFormat (java.text.SimpleDateFormat)2 java.util (java.util)2 List (java.util.List)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 EFS (org.eclipse.core.filesystem.EFS)2 IFileStore (org.eclipse.core.filesystem.IFileStore)2 IFile (org.eclipse.core.resources.IFile)2 IFileState (org.eclipse.core.resources.IFileState)2 org.eclipse.core.runtime (org.eclipse.core.runtime)2 Job (org.eclipse.core.runtime.jobs.Job)2 org.eclipse.jface.action (org.eclipse.jface.action)2 IDialogConstants (org.eclipse.jface.dialogs.IDialogConstants)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 org.eclipse.jface.text (org.eclipse.jface.text)2 SourceViewer (org.eclipse.jface.text.source.SourceViewer)2 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)2