Search in sources :

Example 1 with DBCPlan

use of org.jkiss.dbeaver.model.exec.plan.DBCPlan 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 DBCPlan

use of org.jkiss.dbeaver.model.exec.plan.DBCPlan 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 -> {
        try (DBCSession session = executionContext.openSession(monitor, DBCExecutionPurpose.UTIL, "Prepare plan query")) {
            DBCPlan plan = planner.planQueryExecution(session, sqlQuery.getText());
            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), true, false, true, null);
    }
}
Also used : StringEditorInput(org.jkiss.dbeaver.ui.editors.StringEditorInput) IResultSetListener(org.jkiss.dbeaver.ui.controls.resultset.IResultSetListener) org.eclipse.jface.action(org.eclipse.jface.action) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) CompoundContributionItem(org.eclipse.ui.actions.CompoundContributionItem) SashForm(org.eclipse.swt.custom.SashForm) org.jkiss.dbeaver.ui(org.jkiss.dbeaver.ui) StyledText(org.eclipse.swt.custom.StyledText) DefaultRangeIndicator(org.eclipse.ui.texteditor.DefaultRangeIndicator) SQLQueryListener(org.jkiss.dbeaver.runtime.sql.SQLQueryListener) SQLQueryJob(org.jkiss.dbeaver.runtime.sql.SQLQueryJob) SQLResultsView(org.jkiss.dbeaver.ui.views.SQLResultsView) org.eclipse.jface.text(org.eclipse.jface.text) 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) SQLLogPanel(org.jkiss.dbeaver.ui.editors.sql.log.SQLLogPanel) QMUtils(org.jkiss.dbeaver.model.qm.QMUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ResultSetViewer(org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer) IOUtils(org.jkiss.utils.IOUtils) DBSObjectSelector(org.jkiss.dbeaver.model.struct.DBSObjectSelector) ScriptPositionColumn(org.jkiss.dbeaver.ui.editors.text.ScriptPositionColumn) URI(java.net.URI) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) RulerColumnDescriptor(org.eclipse.ui.texteditor.rulers.RulerColumnDescriptor) SQLResultsConsumer(org.jkiss.dbeaver.runtime.sql.SQLResultsConsumer) EFS(org.eclipse.core.filesystem.EFS) ExplainPlanViewer(org.jkiss.dbeaver.ui.views.plan.ExplainPlanViewer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DBPPreferenceListener(org.jkiss.dbeaver.model.preferences.DBPPreferenceListener) 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) DatabaseTransferProducer(org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferProducer) CTabFolder(org.eclipse.swt.custom.CTabFolder) DBCQueryPlanner(org.jkiss.dbeaver.model.exec.plan.DBCQueryPlanner) DBeaverPreferences(org.jkiss.dbeaver.DBeaverPreferences) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IDataTransferProducer(org.jkiss.dbeaver.tools.transfer.IDataTransferProducer) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) List(java.util.List) RuntimeUtils(org.jkiss.dbeaver.utils.RuntimeUtils) DBException(org.jkiss.dbeaver.DBException) SWT(org.eclipse.swt.SWT) ITextEditorActionConstants(org.eclipse.ui.texteditor.ITextEditorActionConstants) DatabaseEditorUtils(org.jkiss.dbeaver.ui.editors.DatabaseEditorUtils) DefaultServerOutputReader(org.jkiss.dbeaver.model.impl.DefaultServerOutputReader) PrefUtils(org.jkiss.dbeaver.utils.PrefUtils) MouseAdapter(org.eclipse.swt.events.MouseAdapter) IColumnSupport(org.eclipse.ui.texteditor.rulers.IColumnSupport) java.util(java.util) EnterNameDialog(org.jkiss.dbeaver.ui.dialogs.EnterNameDialog) DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore) DBUserInterface(org.jkiss.dbeaver.runtime.ui.DBUserInterface) Image(org.eclipse.swt.graphics.Image) Nullable(org.jkiss.code.Nullable) AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) DataTransferWizard(org.jkiss.dbeaver.tools.transfer.wizard.DataTransferWizard) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) NotNull(org.jkiss.code.NotNull) EditorUtils(org.jkiss.dbeaver.ui.editors.EditorUtils) DataSourceHandler(org.jkiss.dbeaver.ui.actions.datasource.DataSourceHandler) IProject(org.eclipse.core.resources.IProject) INonPersistentEditorInput(org.jkiss.dbeaver.ui.editors.INonPersistentEditorInput) DBRProgressListener(org.jkiss.dbeaver.model.runtime.DBRProgressListener) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) IResultSetContainer(org.jkiss.dbeaver.ui.controls.resultset.IResultSetContainer) IFile(org.eclipse.core.resources.IFile) GridData(org.eclipse.swt.layout.GridData) SQLQueryTransformerCount(org.jkiss.dbeaver.model.impl.sql.SQLQueryTransformerCount) RulerColumnRegistry(org.eclipse.ui.texteditor.rulers.RulerColumnRegistry) ModelPreferences(org.jkiss.dbeaver.ModelPreferences) DBDDataReceiver(org.jkiss.dbeaver.model.data.DBDDataReceiver) IFileStore(org.eclipse.core.filesystem.IFileStore) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) org.jkiss.dbeaver.model(org.jkiss.dbeaver.model) Job(org.eclipse.core.runtime.jobs.Job) org.jkiss.dbeaver.model.exec(org.jkiss.dbeaver.model.exec) org.eclipse.swt.widgets(org.eclipse.swt.widgets) ArrayUtils(org.jkiss.utils.ArrayUtils) CTabItem(org.eclipse.swt.custom.CTabItem) org.eclipse.ui(org.eclipse.ui) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput) org.jkiss.dbeaver.core(org.jkiss.dbeaver.core) org.eclipse.core.runtime(org.eclipse.core.runtime) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer) java.io(java.io) ActiveWizardDialog(org.jkiss.dbeaver.ui.dialogs.ActiveWizardDialog) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) ConfirmationDialog(org.jkiss.dbeaver.ui.dialogs.ConfirmationDialog) org.jkiss.dbeaver.model.sql(org.jkiss.dbeaver.model.sql) DBCPlan(org.jkiss.dbeaver.model.exec.plan.DBCPlan) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBException(org.jkiss.dbeaver.DBException)

Aggregations

java.io (java.io)2 URI (java.net.URI)2 java.util (java.util)2 List (java.util.List)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)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 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 SWT (org.eclipse.swt.SWT)2 CTabFolder (org.eclipse.swt.custom.CTabFolder)2 CTabItem (org.eclipse.swt.custom.CTabItem)2