提交 dfb3c81b 编写于 作者: S Serge Rider

Plan: cost/duaration, layout and rendering fix

上级 cf3369ab
......@@ -22,13 +22,11 @@ import org.jkiss.dbeaver.model.exec.DBCSession;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.exec.plan.DBCPlanNode;
import org.jkiss.dbeaver.model.impl.plan.AbstractExecutionPlan;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
......@@ -38,7 +36,7 @@ public class MySQLPlanAnalyser extends AbstractExecutionPlan {
private MySQLDataSource dataSource;
private String query;
private List<DBCPlanNode> rootNodes;
private List<MySQLPlanNode> rootNodes;
public MySQLPlanAnalyser(MySQLDataSource dataSource, String query)
{
......@@ -58,7 +56,7 @@ public class MySQLPlanAnalyser extends AbstractExecutionPlan {
}
@Override
public Collection<DBCPlanNode> getPlanNodes()
public List<MySQLPlanNode> getPlanNodes()
{
return rootNodes;
}
......@@ -79,13 +77,66 @@ public class MySQLPlanAnalyser extends AbstractExecutionPlan {
MySQLPlanNode node = new MySQLPlanNode(null, dbResult);
nodes.add(node);
}
MySQLPlanNode rootNode = new MySQLPlanNode(nodes);
rootNodes = new ArrayList<>();
rootNodes.add(rootNode);
rootNodes = convertToPlanTree(nodes);
}
}
} catch (SQLException e) {
throw new DBCException(e, session.getDataSource());
}
}
private List<MySQLPlanNode> convertToPlanTree(List<MySQLPlanNode> srcNodes) {
List<MySQLPlanNode> roots = new ArrayList<>();
if (srcNodes.size() == 1) {
// Just one node
roots.add(srcNodes.get(0));
} else {
List<MySQLPlanNode> parsed = new ArrayList<>();
for (int id = 1; ; id++) {
List<MySQLPlanNode> nodes = getQueriesById(srcNodes, id);
if (nodes.isEmpty()) {
break;
}
if (nodes.size() == 1) {
roots.add(nodes.get(0));
} else {
roots.add(joinNodes(srcNodes, nodes));
}
parsed.addAll(nodes);
}
// Add the rest
for (MySQLPlanNode node : srcNodes) {
if (!parsed.contains(node)) {
roots.add(node);
}
}
}
return roots;
}
private List<MySQLPlanNode> getQueriesById(List<MySQLPlanNode> srcNodes, int id) {
List<MySQLPlanNode> subList = new ArrayList<>();
for (MySQLPlanNode node : srcNodes) {
if (node.getId() != null && node.getId() == id) {
subList.add(node);
}
}
return subList;
}
private MySQLPlanNode joinNodes(List<MySQLPlanNode> srcNodes, List<MySQLPlanNode> nodes) {
MySQLPlanNode result = null;
MySQLPlanNode leftNode = nodes.get(0);
for (int i = 1 ; i < nodes.size(); i++) {
leftNode = new MySQLPlanNodeJoin(leftNode.getParent(), leftNode, nodes.get(i));
if (result == null) {
result = leftNode;
}
}
return result;
}
}
......@@ -30,20 +30,20 @@ import java.util.List;
*/
public class MySQLPlanNode extends AbstractExecutionPlanNode implements DBCPlanCostNode {
private long id;
private String selectType;
private String table;
private String type;
private String possibleKeys;
private String key;
private String keyLength;
private String ref;
private long rowCount;
private double filtered;
private String extra;
private MySQLPlanNode parent;
private List<MySQLPlanNode> nested;
protected Integer id;
protected String selectType;
protected String table;
protected String type;
protected String possibleKeys;
protected String key;
protected String keyLength;
protected String ref;
protected long rowCount;
protected double filtered;
protected String extra;
protected MySQLPlanNode parent;
protected List<MySQLPlanNode> nested;
public MySQLPlanNode(List<MySQLPlanNode> nodes) {
// Root node
......@@ -56,7 +56,7 @@ public class MySQLPlanNode extends AbstractExecutionPlanNode implements DBCPlanC
public MySQLPlanNode(MySQLPlanNode parent, ResultSet dbResult) {
this.parent = parent;
this.id = JDBCUtils.safeGetLong(dbResult, "id");
this.id = JDBCUtils.safeGetInteger(dbResult, "id");
this.selectType = JDBCUtils.safeGetString(dbResult, "select_type");
this.table = JDBCUtils.safeGetString(dbResult, "table");
this.type = JDBCUtils.safeGetString(dbResult, "type");
......@@ -69,8 +69,13 @@ public class MySQLPlanNode extends AbstractExecutionPlanNode implements DBCPlanC
this.extra = JDBCUtils.safeGetString(dbResult, "extra");
}
public MySQLPlanNode(MySQLPlanNode parent, String type) {
this.parent = parent;
this.type = type;
}
@Override
public DBCPlanNode getParent() {
public MySQLPlanNode getParent() {
return parent;
}
......@@ -96,7 +101,7 @@ public class MySQLPlanNode extends AbstractExecutionPlanNode implements DBCPlanC
}
@Property(order = 0, viewable = true)
public long getId() {
public Integer getId() {
return id;
}
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.mysql.model.plan;
import org.jkiss.dbeaver.model.exec.plan.DBCPlanCostNode;
import org.jkiss.dbeaver.model.exec.plan.DBCPlanNode;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.impl.plan.AbstractExecutionPlanNode;
import org.jkiss.dbeaver.model.meta.Property;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
/**
* MySQL execution plan node
*/
public class MySQLPlanNodeJoin extends MySQLPlanNode {
public MySQLPlanNodeJoin(MySQLPlanNode parent, MySQLPlanNode left, MySQLPlanNode right) {
super(parent, "JOIN");
this.id = left.id;
this.nested = new ArrayList<>(2);
this.nested.add(left);
this.nested.add(right);
left.parent = this;
right.parent = this;
}
}
......@@ -23,6 +23,7 @@ import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.exec.plan.DBCPlanCostNode;
import org.jkiss.dbeaver.model.impl.plan.AbstractExecutionPlan;
import org.jkiss.utils.IntKeyMap;
import org.jkiss.utils.SecurityUtils;
......@@ -55,6 +56,19 @@ public class OraclePlanAnalyser extends AbstractExecutionPlan {
this.query = query;
}
@Override
public Object getPlanFeature(String feature) {
if (DBCPlanCostNode.FEATURE_PLAN_COST.equalsIgnoreCase(feature) |
DBCPlanCostNode.FEATURE_PLAN_DURATION.equalsIgnoreCase(feature))
{
return true;
} else if (DBCPlanCostNode.PLAN_DURATION_MEASURE.equals(feature)) {
return "KC";
}
return super.getPlanFeature(feature);
}
@Override
public String getQueryString()
{
......
......@@ -20,6 +20,7 @@ import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.oracle.model.OracleDataSource;
import org.jkiss.dbeaver.ext.oracle.model.OracleObjectType;
import org.jkiss.dbeaver.ext.oracle.model.OracleTablePhysical;
import org.jkiss.dbeaver.model.exec.plan.DBCPlanCostNode;
import org.jkiss.dbeaver.model.exec.plan.DBCPlanNode;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.impl.plan.AbstractExecutionPlanNode;
......@@ -38,7 +39,7 @@ import java.util.List;
/**
* Oracle execution plan node
*/
public class OraclePlanNode extends AbstractExecutionPlanNode {
public class OraclePlanNode extends AbstractExecutionPlanNode implements DBCPlanCostNode {
private final OracleDataSource dataSource;
private String statementId;
......@@ -197,7 +198,7 @@ public class OraclePlanNode extends AbstractExecutionPlanNode {
@Property(order = 5, viewable = true, supportsPreview = true)
public Object getObject(DBRProgressMonitor monitor) throws DBException
{
if (monitor == null || CommonUtils.isEmpty(objectOwner)) {
if (monitor == null || CommonUtils.isEmpty(objectOwner) || CommonUtils.isEmpty(objectName)) {
return objectName == null ? "" : objectName;
}
String objectTypeName = objectType;
......@@ -329,4 +330,24 @@ public class OraclePlanNode extends AbstractExecutionPlanNode {
{
return operation + " " + CommonUtils.toString(options) + " " + CommonUtils.toString(objectName);
}
@Override
public Number getNodeCost() {
return cost;
}
@Override
public Number getNodePercent() {
return null;
}
@Override
public Number getNodeDuration() {
return (double)cpuCost / 1000;
}
@Override
public Number getNodeRowCount() {
return cardinality;
}
}
......@@ -26,6 +26,8 @@ public interface DBCPlanCostNode extends DBCPlanNode {
String FEATURE_PLAN_ROWS = "plan.rows";
String FEATURE_PLAN_DURATION = "plan.duration";
String PLAN_DURATION_MEASURE = "plan.duration.measure";
Number getNodeCost();
Number getNodePercent();
......
......@@ -18,6 +18,7 @@
package org.jkiss.dbeaver.model.impl.plan;
import org.jkiss.dbeaver.model.exec.plan.DBCPlan;
import org.jkiss.dbeaver.model.exec.plan.DBCPlanCostNode;
/**
* Abstract execution plan
......@@ -25,6 +26,9 @@ import org.jkiss.dbeaver.model.exec.plan.DBCPlan;
public abstract class AbstractExecutionPlan implements DBCPlan {
public Object getPlanFeature(String feature) {
if (DBCPlanCostNode.PLAN_DURATION_MEASURE.equals(feature)) {
return "ms";
}
return null;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册