use of com.alibaba.maxgraph.compiler.cost.CostModelManager in project GraphScope by alibaba.
the class LogicalPlanBuilder method processCostModel.
private void processCostModel(TreeNode currentNode, LogicalQueryPlan queryPlan, ContextManager contextManager, GraphSchema schema, Set<Integer> labelIdList) {
CostModelManager costModelManager = contextManager.getCostModelManager();
TreeNodeLabelManager treeNodeLabelManager = contextManager.getTreeNodeLabelManager();
VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
if (costModelManager.hasBestPath()) {
CostMappingManager costMappingManager = costModelManager.getCostMappingManager();
RowFieldManager rowFieldManager = costModelManager.getPathFieldManager();
if (null == rowFieldManager) {
return;
}
RowField rowField = rowFieldManager.getRowField();
Set<String> birthFieldList = rowFieldManager.getBirthFieldList();
Set<String> fieldList = rowField.getFieldList();
for (String field : fieldList) {
LogicalVertex outputVertex = queryPlan.getOutputVertex();
if (birthFieldList.contains(field)) {
buildLabelValuePlan(queryPlan, contextManager, schema, outputVertex, treeNodeLabelManager, vertexIdManager, costMappingManager, field, currentNode);
} else {
RowFieldManager parentFieldManager = rowFieldManager.getParent();
if (!parentFieldManager.getRowField().getFieldList().contains(field)) {
buildLabelValuePlan(queryPlan, contextManager, schema, outputVertex, treeNodeLabelManager, vertexIdManager, costMappingManager, field, currentNode);
}
}
}
currentNode.setFinishVertex(queryPlan.getOutputVertex(), null);
}
List<LogicalVertex> logicalVertexList = queryPlan.getLogicalVertexList();
for (LogicalVertex vertex : logicalVertexList) {
if (vertex.getProcessorFunction() != null && vertex.getProcessorFunction().getOperatorType() == QueryFlowOuterClass.OperatorType.LABEL_VALUE) {
if (vertex.getProcessorFunction().getArgumentBuilder().getIntValue() != 0) {
labelIdList.add(vertex.getProcessorFunction().getArgumentBuilder().getIntValue());
}
} else {
vertex.getBeforeRequirementList().removeIf(vv -> {
if (vv.getReqType() == QueryFlowOuterClass.RequirementType.LABEL_START) {
List<Integer> intValueList = Lists.newArrayList(vv.getReqArgument().getIntValueListList());
intValueList.removeIf(labelIdList::contains);
if (intValueList.isEmpty()) {
return true;
}
vv.getReqArgumentBuilder().clearIntValueList().addAllIntValueList(intValueList);
}
return false;
});
}
}
}
use of com.alibaba.maxgraph.compiler.cost.CostModelManager in project GraphScope by alibaba.
the class MixedOpProcessor method buildCostPathList.
private List<String> buildCostPathList(GraphTraversal traversal) {
TreeBuilder treeBuilder = TreeBuilder.newTreeBuilder(this.schemaFetcher.getSchemaSnapshotPair().getLeft(), new OptimizeConfig(), true);
TreeManager treeManager = treeBuilder.build(traversal);
treeManager.optimizeTree();
CostModelManager costModelManager = treeManager.optimizeCostModel();
List<CostPath> pathList = costModelManager.getPathList();
if (pathList == null || pathList.isEmpty()) {
return Lists.newArrayList();
}
return pathList.stream().map(CostPath::toString).collect(Collectors.toList());
}
use of com.alibaba.maxgraph.compiler.cost.CostModelManager in project GraphScope by alibaba.
the class LogicalPlanBuilder method build.
/**
* Build logical plan from tree manager
*
* @param treeManager The given tree manager
* @return The result logical plan
*/
public LogicalQueryPlan build(TreeManager treeManager) {
CostModelManager costModelManager = treeManager.optimizeCostModel();
TreeNodeLabelManager labelManager = treeManager.getLabelManager();
VertexIdManager vertexIdManager = VertexIdManager.createVertexIdManager();
ContextManager contextManager = new ContextManager(costModelManager, treeManager.getQueryConfig(), vertexIdManager, labelManager);
TreeNode leafNode = treeManager.getTreeLeaf();
return buildPlan(leafNode, contextManager, treeManager.getSchema());
}
use of com.alibaba.maxgraph.compiler.cost.CostModelManager in project GraphScope by alibaba.
the class TreeManager method optimizeCostModel.
public CostModelManager optimizeCostModel() {
List<TreeNode> treeNodeList = TreeNodeUtils.buildTreeNodeListFromLeaf(this.getTreeLeaf());
CostGraph costGraph = CostUtils.buildCostGraph(this.getTreeLeaf(), this.labelManager);
NodeLabelManager nodeLabelManager = new NodeLabelManager();
NodeLabelList previousNodeLabel = null;
for (TreeNode treeNode : treeNodeList) {
NodeLabelList nodeLabelList = NodeLabelList.buildNodeLabel(previousNodeLabel, treeNode, schema);
nodeLabelManager.addNodeLabelList(nodeLabelList);
previousNodeLabel = nodeLabelList;
}
int pathIndex = this.getQueryConfig().getInt(CompilerConstant.QUERY_COSTMODEL_PLAN_PATH, -1);
List<CostPath> costPathList = costGraph.getCostPathList();
CostPath useCostPath;
if (pathIndex < 0 || pathIndex >= costPathList.size()) {
CostDataStatistics costDataStatistics = CostDataStatistics.getInstance();
List<Double> stepCountList = costDataStatistics.computeStepCountList(nodeLabelManager, treeNodeList);
List<Double> shuffleThresholdList = Lists.newArrayList(1.0);
for (int i = 1; i < stepCountList.size(); i++) {
shuffleThresholdList.add(1.5);
}
useCostPath = costGraph.computePath(stepCountList, shuffleThresholdList);
} else {
useCostPath = costPathList.get(pathIndex);
logger.info("Use specify cost path " + useCostPath.toString());
}
return new CostModelManager(costGraph, useCostPath);
}
Aggregations