use of com.cubrid.common.core.queryplan.StructQueryPlan in project cubrid-manager by CUBRID.
the class QueryEditorPart method runQueryPlanOnly.
/**
* Fetch execution plans while running SQLs
*
* @param queries String
*/
private void runQueryPlanOnly(Vector<String> qVector) {
try {
connection.getConnection(true);
} catch (SQLException e) {
CommonUITool.openErrorBox(e.getLocalizedMessage());
return;
}
if (!connection.hasConnection()) {
return;
}
// clearPlan();
CUBRIDStatementProxy statement = null;
int i = 0;
try {
int len = qVector.size();
for (i = 0; i < len; i++) {
String sql = qVector.get(i).toString();
statement = getStatement(connection.getConnection(), false);
StructQueryPlan sq = new StructQueryPlan(sql, statement.getQueryplan(sql), new Date());
if (combinedQueryComposite.getQueryPlanResultComp().isDisposed()) {
combinedQueryComposite.newQueryPlanComp();
}
combinedQueryComposite.getQueryPlanResultComp().makePlan(sq, i);
QueryUtil.freeQuery(statement);
statement = null;
if (collectExecStats) {
displayTuneModeResult(new TuneModeModel(sq, null));
}
}
} catch (Exception ee) {
int errorCode = 0;
if (SQLException.class.isInstance(ee)) {
errorCode = ((SQLException) ee).getErrorCode();
}
String errmsg = "";
if (isAutocommit) {
try {
queryAction(QUERY_ACTION.ROLLBACK);
} catch (SQLException e1) {
LOGGER.error("", e1);
}
}
SQLEditorComposite sqlEditorComp = combinedQueryComposite.getSqlEditorComp();
sqlEditorComp.txtFind((String) qVector.get(i), 0, false, false, true, false);
StyledText txaEdit = sqlEditorComp.getText();
int line = txaEdit.getLineAtOffset(txaEdit.getSelection().x) + 1;
String errorLineMsg = Messages.bind(Messages.errWhere, line);
errmsg += Messages.runError + errorCode + StringUtil.NEWLINE + errorLineMsg + StringUtil.NEWLINE + Messages.errorHead + ee.getMessage();
CTabFolder queryResultTabFolder = combinedQueryComposite.getQueryResultComp().getQueryResultTabFolder();
StyledText logMessagesArea = combinedQueryComposite.getQueryResultComp().getLogMessagesArea();
QueryResultComposite queryResult = combinedQueryComposite.getQueryResultComp();
queryResultTabFolder.setSelection(0);
String logMessage = logMessagesArea.getText();
if (logMessage != null && logMessage.length() > 0) {
logMessage += StringUtil.NEWLINE;
}
logMessagesArea.setText(logMessage + StringUtil.NEWLINE + errmsg);
logMessagesArea.setTopIndex(logMessagesArea.getLineCount() - 1);
queryResult.setSelection();
LOGGER.error(ee.getMessage(), ee);
} finally {
QueryUtil.freeQuery(statement);
statement = null;
}
autoCommitItem.setEnabled(true);
queryPlanItem.setEnabled(true);
setPstmtParaItem.setEnabled(true);
isRunning = false;
}
use of com.cubrid.common.core.queryplan.StructQueryPlan in project cubrid-manager by CUBRID.
the class QueryExecuter method makeTable.
/**
* make query editor result table
*
* @param start int
* @throws SQLException if failed
*/
public TuneModeModel makeTable(int start, boolean useTuneMode) throws SQLException {
int end = start + recordLimit - 1;
String sql = multiQuerySql;
if (multiQuerySql.indexOf(SqlParser.ROWNUM_CONDITION_MARK) != -1) {
if (dontTipNext) {
if (recordLimit > 0) {
sql = this.multiQuerySql.replace(SqlParser.ROWNUM_CONDITION_MARK, "\r\nWHERE ROWNUM >= " + String.valueOf(start));
}
} else {
sql = this.multiQuerySql.replace(SqlParser.ROWNUM_CONDITION_MARK, "\r\nWHERE ROWNUM BETWEEN " + String.valueOf(start) + " AND " + String.valueOf(end));
}
}
TuneModeModel tuneModeModel = null;
long beginTimestamp = 0;
long endTimestamp = 0;
double elapsedTime = 0.0;
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(3);
stmt = null;
rs = null;
boolean isHasError = false;
try {
beginTimestamp = System.currentTimeMillis();
stmt = getStatement(connection.checkAndConnectQuietly(), sql, false, false);
stmt.setQueryInfo(false);
stmt.setOnlyQueryPlan(false);
// begin tune mode
if (queryEditor.isCollectExecStats()) {
queryEditor.beginCollectExecStats();
}
if (columnTableNames == null || columnTableNames.size() == 0) {
columnTableNames = UIQueryUtil.loadColumnTableNameList(stmt);
}
stmt.executeQuery();
String queryPlan = null;
rs = (CUBRIDResultSetProxy) stmt.getResultSet();
endTimestamp = System.currentTimeMillis();
elapsedTime = (endTimestamp - beginTimestamp) * 0.001;
String elapsedTimeStr = new String(nf.format(elapsedTime));
if (start == 1) {
makeResult(rs);
} else {
fillTableItemData(rs);
}
// collect statistics and query plan on tune mode
if (useTuneMode && queryEditor.isCollectExecStats()) {
Map<String, String> stat = CubridUtil.fetchStatistics(connection.checkAndConnectQuietly());
StructQueryPlan sq = new StructQueryPlan(sql, stmt.getQueryplan(sql), new Date());
queryPlan = sq.getPlanRaw();
tuneModeModel = new TuneModeModel(sq, stat);
}
queryMsg += "[ " + elapsedTimeStr + " " + Messages.second + " , " + Messages.totalRows + " : " + cntRecord + " ]" + StringUtil.NEWLINE;
if (useTuneMode && queryEditor.isCollectExecStats() && queryPlan != null) {
this.queryPlanLog = queryPlan;
}
query += sql + StringUtil.NEWLINE;
recordSQLDetail(elapsedTimeStr.toString(), queryMsg);
} catch (SQLException event) {
queryMsg += Messages.runError + event.getErrorCode() + StringUtil.NEWLINE + Messages.errorHead + event.getMessage() + StringUtil.NEWLINE;
query += sql + StringUtil.NEWLINE;
isHasError = true;
LOGGER.error("execute SQL failed sql at query editor: " + query + " error message: " + event.getMessage(), event);
throw event;
} finally {
queryInfo = new QueryInfo(allDataList == null ? 0 : allDataList.size(), pageLimit);
queryInfo.setCurrentPage(1);
QueryUtil.freeQuery(stmt, rs);
stmt = null;
rs = null;
if (!isHasError && cntRecord == recordLimit && recordLimit > 0) {
isEnd = false;
final String msg = Messages.bind(Messages.tooManyRecord, end);
showQueryTip(msg);
if (!isEnd) {
makeTable(end + 1, false);
}
}
}
return tuneModeModel;
}
use of com.cubrid.common.core.queryplan.StructQueryPlan in project cubrid-manager by CUBRID.
the class QueryPlanCompositeWithHistory method fillPlanHistory.
public void fillPlanHistory() {
clearAll();
planHistoryList = new ArrayList<StructQueryPlan>();
List<StructQueryPlan> StructQueryPlanList = PlanHistoryManager.getStructQueryPlanListFromPreference(editor.getSelectedDatabase());
if (StructQueryPlanList != null) {
planHistoryList.addAll(StructQueryPlanList);
}
if (planHistoryList.size() == 0) {
PlanTabItem tabItem = newPlanTab(1);
plansTabFolder.setSelection(tabItem);
}
int index = 1;
for (int i = 0, len = planHistoryList.size(); i < len; i++) {
StructQueryPlan sq = planHistoryList.get(i);
PlanResult planRoot = sq.getSubPlan(0);
if (planRoot == null) {
continue;
}
printHistory(index, sq);
index++;
}
refreshTableByCurrentSort();
}
use of com.cubrid.common.core.queryplan.StructQueryPlan in project cubrid-manager by CUBRID.
the class QueryPlanCompositeWithHistory method createPlanToolbar.
private void createPlanToolbar() {
Composite toolBarComposite = new Composite(this, SWT.NONE);
GridLayout gridLayout = new GridLayout(2, false);
gridLayout.verticalSpacing = 0;
gridLayout.horizontalSpacing = 10;
gridLayout.marginWidth = 0;
gridLayout.marginHeight = 0;
toolBarComposite.setLayout(gridLayout);
toolBarComposite.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false));
ToolBar toolBar = new ToolBar(toolBarComposite, SWT.FLAT | SWT.RIGHT);
dispModeTextItem = new ToolItem(toolBar, SWT.CHECK);
dispModeTextItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/qe_explain_mode_raw.png"));
dispModeTextItem.setToolTipText(Messages.tooltip_qedit_explain_display_mode + "(F11)");
dispModeTextItem.setText(Messages.lblPlanRawBtn);
dispModeTextItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
showSelectedPlan(PLAN_DISPLAY_MODE.TEXT.getInt());
}
});
new ToolItem(toolBar, SWT.SEPARATOR);
dispModeTreeItem = new ToolItem(toolBar, SWT.CHECK);
dispModeTreeItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/qe_explain_mode_tree.png"));
dispModeTreeItem.setToolTipText(Messages.tooltip_qedit_explain_display_mode + "(F11)");
dispModeTreeItem.setText(Messages.lblPlanTreeBtn);
dispModeTreeItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
showSelectedPlan(PLAN_DISPLAY_MODE.TREE.getInt());
}
});
new ToolItem(toolBar, SWT.SEPARATOR);
dispModeGraphItem = new ToolItem(toolBar, SWT.CHECK);
dispModeGraphItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/qe_explain_mode_graph.png"));
dispModeGraphItem.setToolTipText(Messages.tooltip_qedit_explain_display_mode + "(F11)");
dispModeGraphItem.setText(Messages.lblPlanGraph);
dispModeGraphItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
showSelectedPlan(PLAN_DISPLAY_MODE.GRAPH.getInt());
}
});
new ToolItem(toolBar, SWT.SEPARATOR);
editTableItem = new ToolItem(toolBar, SWT.None);
editTableItem.setImage(CommonUIPlugin.getImage("icons/navigator/schema_table_item.png"));
editTableItem.setText(Messages.lblPlanEditTable);
editTableItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
QueryPlanComposite comp = getSelectedQueryPlanComposite();
String tableName = comp.getSelectedTable();
if (StringUtil.isEmpty(tableName)) {
CommonUITool.openErrorBox(Messages.msgPlanEditTable);
return;
}
ISchemaNode node = new DefaultSchemaNode(tableName, tableName, null);
node.setDatabase(editor.getSelectedDatabase());
EditTableAction action = (EditTableAction) ActionManager.getInstance().getAction(EditTableAction.ID);
if (action == null) {
CommonUITool.openErrorBox(Messages.errPlanEditNoAction);
return;
}
action.run((ISchemaNode) node);
}
});
editIndexItem = new ToolItem(toolBar, SWT.None);
editIndexItem.setImage(CommonUIPlugin.getImage("icons/navigator/table_index_item.png"));
editIndexItem.setText(Messages.lblPlanEditIndex);
editIndexItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
QueryPlanComposite comp = getSelectedQueryPlanComposite();
String tableName = comp.getSelectedTable();
// String indexName = comp.getSelectedIndex();
if (StringUtil.isEmpty(tableName)) {
CommonUITool.openErrorBox(Messages.msgPlanEditIndex);
return;
}
ISchemaNode node = new DefaultSchemaNode(tableName, tableName, null);
node.setDatabase(editor.getSelectedDatabase());
EditTableAction action = (EditTableAction) ActionManager.getInstance().getAction(EditTableAction.ID);
if (action == null) {
CommonUITool.openErrorBox(Messages.errPlanEditNoAction);
return;
}
action.editIndexMode((ISchemaNode) node);
}
});
ToolItem comparePlanItem = new ToolItem(toolBar, SWT.None);
comparePlanItem.setImage(CommonUIPlugin.getImage("icons/queryplan/use_compare_queryplan.png"));
comparePlanItem.setText(Messages.lblComparePlan);
comparePlanItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
QueryPlanComposite comp = getSelectedQueryPlanComposite();
StructQueryPlan sq = comp.getQueryPlan();
TuneModeModel tuneModeModel = new TuneModeModel(sq, null);
editor.displayTuneModeResult(tuneModeModel);
}
});
ToolBar delHistoryToolBar = new ToolBar(toolBarComposite, SWT.FLAT);
delHistoryToolBar.setLayoutData(new GridData(SWT.END, SWT.CENTER, true, true));
// Show/hide of the history pane
historyShowHideItem = new ToolItem(delHistoryToolBar, SWT.PUSH);
historyShowHideItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/qe_explain_history_hide.png"));
historyShowHideItem.setToolTipText(Messages.tooltip_qedit_explain_history_show_hide);
historyShowHideItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
boolean isShow = !planHistoryTable.getVisible();
if (isShow) {
showHistoryPane();
} else {
hideHistoryPane();
}
}
});
new ToolItem(delHistoryToolBar, SWT.SEPARATOR);
// Collecting histories switch
historySwitchItem = new ToolItem(delHistoryToolBar, SWT.CHECK);
historySwitchItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/qe_explain_history_switch.png"));
historySwitchItem.setToolTipText(Messages.tooltip_qedit_explain_history_switch);
historySwitchItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
collectToHistoryFlag = !historySwitchItem.getSelection();
}
});
historySwitchItem.setSelection(true);
new ToolItem(delHistoryToolBar, SWT.SEPARATOR);
delHistory = new ToolItem(delHistoryToolBar, SWT.PUSH);
delHistory.setImage(CommonUIPlugin.getImage("icons/action/table_record_delete.png"));
delHistory.setDisabledImage(CommonUIPlugin.getImage("icons/action/table_record_delete_disabled.png"));
delHistory.setToolTipText(Messages.tooltip_qedit_explain_history_delete);
delHistory.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (planHistoryTable.getSelectionIndices().length == 0) {
MessageDialog.openError(PlatformUI.getWorkbench().getDisplay().getActiveShell(), Messages.error, Messages.explain_history_delete_error);
return;
}
deleteHistory();
}
});
}
use of com.cubrid.common.core.queryplan.StructQueryPlan in project cubrid-manager by CUBRID.
the class QueryPlanCompositeWithHistory method initialize.
/**
* Initializing a Plan Tab
*/
private void initialize() {
createPlanToolbar();
//create the plan tab folder and history sash
plansHistorySash = new SashForm(this, SWT.HORIZONTAL);
plansHistorySash.setLayout(new GridLayout(2, true));
plansHistorySash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
//create left plan tab folder
plansTabFolder = new CTabFolder(plansHistorySash, SWT.BOTTOM | SWT.CLOSE);
plansTabFolder.setSimple(false);
plansTabFolder.setUnselectedImageVisible(true);
plansTabFolder.setUnselectedCloseVisible(true);
plansTabFolder.setSelectionBackground(CombinedQueryEditorComposite.BACK_COLOR);
plansTabFolder.setSelectionForeground(ResourceManager.getColor(SWT.COLOR_BLACK));
plansTabFolder.setLayout(new GridLayout(1, true));
plansTabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
TabContextMenuManager tabContextMenuManager = new TabContextMenuManager(plansTabFolder);
tabContextMenuManager.createContextMenu();
//create the right plan history table
planHistoryTable = new Table(plansHistorySash, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
planHistoryTable.setLayout(new GridLayout(1, true));
planHistoryTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
planHistoryTable.setHeaderVisible(true);
planHistoryTable.setLinesVisible(true);
planHistoryTable.addMouseListener(new MouseListener() {
public void mouseDoubleClick(MouseEvent event) {
int selectionIndex = planHistoryTable.getSelectionIndex();
if (selectionIndex < 0) {
return;
}
TableItem tableItem = planHistoryTable.getItem(planHistoryTable.getSelectionIndex());
if (tableItem == null) {
return;
}
int uid = Integer.valueOf(tableItem.getText(0));
StructQueryPlan sq = planHistoryList.get(uid - 1);
PlanTabItem tabItem = findPlanTab(uid);
if (tabItem == null) {
tabItem = newPlanTab(uid);
}
plansTabFolder.setSelection(tabItem);
printPlan(tabItem, sq);
}
public void mouseDown(MouseEvent event) {
}
public void mouseUp(MouseEvent event) {
}
});
int i = 0;
planHistoryTblCols[i] = new TableColumn(planHistoryTable, SWT.RIGHT);
// No
planHistoryTblCols[i].setText(Messages.qedit_plan_history_col1);
planHistoryTblCols[i].setMoveable(true);
planHistoryTblCols[i].setWidth(20);
addNumberSorter(planHistoryTable, planHistoryTblCols[i]);
sortType.put(planHistoryTblCols[i], "NUMBER");
planHistoryTblCols[++i] = new TableColumn(planHistoryTable, SWT.LEFT);
// Date
planHistoryTblCols[i].setText(Messages.qedit_plan_history_col2);
planHistoryTblCols[i].setMoveable(true);
planHistoryTblCols[i].setWidth(100);
addStringSorter(planHistoryTable, planHistoryTblCols[i]);
sortType.put(planHistoryTblCols[i], "STRING");
planHistoryTblCols[++i] = new TableColumn(planHistoryTable, SWT.RIGHT);
// Cost
planHistoryTblCols[i].setText(Messages.qedit_plan_history_col4);
planHistoryTblCols[i].setMoveable(true);
planHistoryTblCols[i].setWidth(90);
addNumberSorter(planHistoryTable, planHistoryTblCols[i]);
sortType.put(planHistoryTblCols[i], "NUMBER");
planHistoryTblCols[++i] = new TableColumn(planHistoryTable, SWT.LEFT);
// Cost
planHistoryTblCols[i].setText(Messages.qedit_plan_history_col3);
planHistoryTblCols[i].setMoveable(false);
planHistoryTblCols[i].setWidth(90);
addStringSorter(planHistoryTable, planHistoryTblCols[i]);
sortType.put(planHistoryTblCols[i], "STRING");
sashPlanWeight = new int[] { 80, 20 };
plansHistorySash.setWeights(sashPlanWeight);
newPlanTab(1);
plansTabFolder.setSelection(0);
hideHistoryPane();
refreshToolbarStatus(QueryOptions.getQueryPlanDisplayType());
}
Aggregations