Search in sources :

Example 1 with PlannerGraph

use of com.apple.foundationdb.record.query.plan.temp.explain.PlannerGraph in project fdb-record-layer by FoundationDB.

the class RecordQueryInUnionPlan method rewritePlannerGraph.

@Nonnull
@Override
public PlannerGraph rewritePlannerGraph(@Nonnull final List<? extends PlannerGraph> childGraphs) {
    final PlannerGraph.Node root = new PlannerGraph.OperatorNodeWithInfo(this, NodeInfo.IN_UNION_OPERATOR, ImmutableList.of("COMPARE BY {{comparisonKey}}"), ImmutableMap.of("comparisonKey", Attribute.gml(comparisonKey.toString())));
    final PlannerGraph graphForInner = Iterables.getOnlyElement(childGraphs);
    final PlannerGraph.DataNodeWithInfo valuesNode = new PlannerGraph.DataNodeWithInfo(NodeInfo.VALUES_DATA, ImmutableList.of("VALUES({{values}}"), ImmutableMap.of("values", Attribute.gml(Objects.requireNonNull(valuesSources).stream().map(String::valueOf).map(Attribute::gml).collect(ImmutableList.toImmutableList()))));
    final PlannerGraph.Edge fromValuesEdge = new PlannerGraph.Edge();
    return PlannerGraph.builder(root).addGraph(graphForInner).addNode(valuesNode).addEdge(valuesNode, root, fromValuesEdge).addEdge(graphForInner.getRoot(), root, new PlannerGraph.Edge(ImmutableSet.of(fromValuesEdge))).build();
}
Also used : Attribute(com.apple.foundationdb.record.query.plan.temp.explain.Attribute) PlannerGraph(com.apple.foundationdb.record.query.plan.temp.explain.PlannerGraph) Nonnull(javax.annotation.Nonnull)

Example 2 with PlannerGraph

use of com.apple.foundationdb.record.query.plan.temp.explain.PlannerGraph in project fdb-record-layer by FoundationDB.

the class RecordQueryInParameterJoinPlan method rewritePlannerGraph.

/**
 * Rewrite the planner graph for better visualization of a query index plan.
 * @param childGraphs planner graphs of children expression that already have been computed
 * @return the rewritten planner graph that models this operator as a logical nested loop join
 *         joining an outer table of iterated values over a parameter in the IN clause to the correlated inner
 *         result of executing (usually) a index lookup for each bound outer value.
 */
@Nonnull
@Override
public PlannerGraph rewritePlannerGraph(@Nonnull List<? extends PlannerGraph> childGraphs) {
    final PlannerGraph.Node root = new PlannerGraph.OperatorNodeWithInfo(this, NodeInfo.NESTED_LOOP_JOIN_OPERATOR);
    final PlannerGraph graphForInner = Iterables.getOnlyElement(childGraphs);
    final PlannerGraph.NodeWithInfo explodeNode = new PlannerGraph.LogicalOperatorNodeWithInfo(this, NodeInfo.TABLE_FUNCTION_OPERATOR, ImmutableList.of("EXPLODE({{externalBinding}})"), ImmutableMap.of("externalBinding", Attribute.gml(inParameterSource().getParameterName())));
    final PlannerGraph.Edge fromExplodeEdge = new PlannerGraph.Edge();
    return PlannerGraph.builder(root).addGraph(graphForInner).addNode(explodeNode).addEdge(explodeNode, root, fromExplodeEdge).addEdge(graphForInner.getRoot(), root, new PlannerGraph.Edge(ImmutableSet.of(fromExplodeEdge))).build();
}
Also used : PlannerGraph(com.apple.foundationdb.record.query.plan.temp.explain.PlannerGraph) Nonnull(javax.annotation.Nonnull)

Example 3 with PlannerGraph

use of com.apple.foundationdb.record.query.plan.temp.explain.PlannerGraph in project fdb-record-layer by FoundationDB.

the class RecordQueryScanPlan method rewritePlannerGraph.

/**
 * Rewrite the planner graph for better visualization of a query scan plan.
 * @param childGraphs planner graphs of children expression that already have been computed
 * @return the rewritten planner graph that models scanned storage as a separate node that is connected to the
 *         actual scan plan node.
 */
@Nonnull
@Override
public PlannerGraph rewritePlannerGraph(@Nonnull List<? extends PlannerGraph> childGraphs) {
    Verify.verify(childGraphs.isEmpty());
    @Nullable final TupleRange tupleRange = comparisons.toTupleRangeWithoutContext();
    final ImmutableList.Builder<String> detailsBuilder = ImmutableList.builder();
    final ImmutableMap.Builder<String, Attribute> additionalAttributes = ImmutableMap.builder();
    if (tupleRange != null) {
        detailsBuilder.add("range: " + tupleRange.getLowEndpoint().toString(false) + "{{low}}, {{high}}" + tupleRange.getHighEndpoint().toString(true));
        additionalAttributes.put("low", Attribute.gml(tupleRange.getLow() == null ? "-∞" : tupleRange.getLow().toString()));
        additionalAttributes.put("high", Attribute.gml(tupleRange.getHigh() == null ? "∞" : tupleRange.getHigh().toString()));
    } else {
        detailsBuilder.add("comparisons: {{comparisons}}");
        additionalAttributes.put("comparisons", Attribute.gml(comparisons.toString()));
    }
    if (reverse) {
        detailsBuilder.add("direction: {{direction}}");
        additionalAttributes.put("direction", Attribute.gml("reversed"));
    }
    final PlannerGraph.DataNodeWithInfo dataNodeWithInfo;
    if (getRecordTypes() == null) {
        dataNodeWithInfo = new PlannerGraph.DataNodeWithInfo(NodeInfo.BASE_DATA, ImmutableList.of("ALL"));
    } else {
        dataNodeWithInfo = new PlannerGraph.DataNodeWithInfo(NodeInfo.BASE_DATA, ImmutableList.of("record types: {{types}}"), ImmutableMap.of("types", Attribute.gml(getRecordTypes().stream().map(Attribute::gml).collect(ImmutableList.toImmutableList()))));
    }
    return PlannerGraph.fromNodeAndChildGraphs(new PlannerGraph.OperatorNodeWithInfo(this, NodeInfo.SCAN_OPERATOR, detailsBuilder.build(), additionalAttributes.build()), ImmutableList.of(PlannerGraph.fromNodeAndChildGraphs(dataNodeWithInfo, childGraphs)));
}
Also used : Attribute(com.apple.foundationdb.record.query.plan.temp.explain.Attribute) ImmutableList(com.google.common.collect.ImmutableList) TupleRange(com.apple.foundationdb.record.TupleRange) PlannerGraph(com.apple.foundationdb.record.query.plan.temp.explain.PlannerGraph) Nullable(javax.annotation.Nullable) ImmutableMap(com.google.common.collect.ImmutableMap) Nonnull(javax.annotation.Nonnull)

Example 4 with PlannerGraph

use of com.apple.foundationdb.record.query.plan.temp.explain.PlannerGraph in project fdb-record-layer by FoundationDB.

the class RecordQueryInValuesJoinPlan method rewritePlannerGraph.

/**
 * Rewrite the planner graph for better visualization of a query index plan.
 * @param childGraphs planner graphs of children expression that already have been computed
 * @return the rewritten planner graph that models this operator as a logical nested loop join
 *         joining an outer table of values in the IN clause to the correlated inner result of executing (usually)
 *         a index lookup for each bound outer value.
 */
@Nonnull
@Override
public PlannerGraph rewritePlannerGraph(@Nonnull List<? extends PlannerGraph> childGraphs) {
    final PlannerGraph.Node root = new PlannerGraph.OperatorNodeWithInfo(this, NodeInfo.NESTED_LOOP_JOIN_OPERATOR);
    final PlannerGraph graphForInner = Iterables.getOnlyElement(childGraphs);
    final PlannerGraph.DataNodeWithInfo valuesNode = new PlannerGraph.DataNodeWithInfo(NodeInfo.VALUES_DATA, ImmutableList.of("VALUES({{values}}"), ImmutableMap.of("values", Attribute.gml(Objects.requireNonNull(getInListValues()).stream().map(String::valueOf).map(Attribute::gml).collect(ImmutableList.toImmutableList()))));
    final PlannerGraph.Edge fromValuesEdge = new PlannerGraph.Edge();
    return PlannerGraph.builder(root).addGraph(graphForInner).addNode(valuesNode).addEdge(valuesNode, root, fromValuesEdge).addEdge(graphForInner.getRoot(), root, new PlannerGraph.Edge(ImmutableSet.of(fromValuesEdge))).build();
}
Also used : Attribute(com.apple.foundationdb.record.query.plan.temp.explain.Attribute) PlannerGraph(com.apple.foundationdb.record.query.plan.temp.explain.PlannerGraph) Nonnull(javax.annotation.Nonnull)

Aggregations

PlannerGraph (com.apple.foundationdb.record.query.plan.temp.explain.PlannerGraph)4 Nonnull (javax.annotation.Nonnull)4 Attribute (com.apple.foundationdb.record.query.plan.temp.explain.Attribute)3 TupleRange (com.apple.foundationdb.record.TupleRange)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Nullable (javax.annotation.Nullable)1