Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DbStructureLogicalPlanningConfiguration
- Loading branch information
Showing
17 changed files
with
824 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...st/scala/org/neo4j/cypher/internal/compiler/v2_2/planner/DbStructureGraphStatistics.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Copyright (c) 2002-2015 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.cypher.internal.compiler.v2_2.planner | ||
|
||
import org.neo4j.cypher.internal.compiler.v2_2.{NameId, PropertyKeyId, RelTypeId, LabelId} | ||
import org.neo4j.cypher.internal.compiler.v2_2.planner.logical.{Selectivity, Cardinality} | ||
import org.neo4j.cypher.internal.compiler.v2_2.spi.GraphStatistics | ||
import org.neo4j.kernel.impl.util.dbstructure.DbStructureLookup | ||
|
||
class DbStructureGraphStatistics(lookup: DbStructureLookup) extends GraphStatistics { | ||
|
||
import NameId._ | ||
|
||
override def nodesWithLabelCardinality( label: Option[LabelId] ): Cardinality = | ||
Cardinality(lookup.nodesWithLabelCardinality(label)) | ||
|
||
override def cardinalityByLabelsAndRelationshipType( fromLabel: Option[LabelId], relTypeId: Option[RelTypeId], toLabel: Option[LabelId] ): Cardinality = | ||
Cardinality(lookup.cardinalityByLabelsAndRelationshipType(fromLabel, relTypeId, toLabel)) | ||
|
||
/* | ||
Probability of any node with the given label, to have a property with a given value | ||
indexSelectivity(:X, prop) = s => |MATCH (a:X)| * s = |MATCH (a:X) WHERE x.prop = *| | ||
*/ | ||
override def indexSelectivity( label: LabelId, property: PropertyKeyId ): Option[Selectivity] = { | ||
val result = lookup.indexSelectivity( label.id, property.id ) | ||
if (result.isNaN) None else Some(Selectivity(result)) | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...neo4j/cypher/internal/compiler/v2_2/planner/DbStructureLogicalPlanningConfiguration.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* Copyright (c) 2002-2015 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.cypher.internal.compiler.v2_2.planner | ||
|
||
import java.util | ||
|
||
import org.neo4j.cypher.internal.compiler.v2_2.spi.{GraphStatistics, StatisticsCompletingGraphStatistics} | ||
import org.neo4j.cypher.internal.compiler.v2_2.{LabelId, PropertyKeyId, RelTypeId} | ||
import org.neo4j.helpers.Pair | ||
import org.neo4j.helpers.collection.Visitable | ||
import org.neo4j.kernel.impl.util.dbstructure.{DbStructureCollector, DbStructureLookup, DbStructureVisitor} | ||
|
||
import scala.collection.JavaConverters._ | ||
import scala.collection.mutable | ||
|
||
object DbStructureLogicalPlanningConfiguration { | ||
|
||
def apply(visitable: Visitable[DbStructureVisitor]): LogicalPlanningConfiguration = { | ||
val collector = new DbStructureCollector | ||
visitable.accept(collector) | ||
val lookup = collector.lookup() | ||
apply(lookup, new DbStructureGraphStatistics(lookup)) | ||
} | ||
|
||
def apply(lookup: DbStructureLookup, underlyingStatistics: GraphStatistics): LogicalPlanningConfiguration = { | ||
val resolvedLabels: mutable.Map[String, LabelId] = resolveTokens(lookup.labels())(LabelId) | ||
val resolvedPropertyKeys = resolveTokens(lookup.properties())(PropertyKeyId) | ||
val resolvedRelTypeNames = resolveTokens(lookup.relationshipTypes())(RelTypeId) | ||
|
||
new RealLogicalPlanningConfiguration { | ||
|
||
override val computeSemanticTable: SemanticTable = new SemanticTable( | ||
resolvedLabelIds = resolvedLabels, | ||
resolvedPropertyKeyNames = resolvedPropertyKeys, | ||
resolvedRelTypeNames = resolvedRelTypeNames | ||
) | ||
|
||
override val graphStatistics: GraphStatistics = | ||
new StatisticsCompletingGraphStatistics(underlyingStatistics) | ||
|
||
override val indexes: Set[(String, String)] = indexSet(lookup.knownIndices()) | ||
override val knownLabels: Set[String] = resolvedLabels.keys.toSet | ||
override val uniqueIndexes: Set[(String, String)] = indexSet(lookup.knownUniqueIndices()) | ||
} | ||
} | ||
|
||
private def indexSet(indices: util.Iterator[Pair[String, String]]): Set[(String, String)] = | ||
indices.asScala.map { pair => pair.first() -> pair.other() }.toSet | ||
|
||
private def resolveTokens[T](iterator: util.Iterator[Pair[Integer, String]])(f: Int => T): mutable.Map[String, T] = { | ||
val builder = mutable.Map.newBuilder[String, T] | ||
while (iterator.hasNext) { | ||
val next = iterator.next() | ||
builder += next.other() -> f(next.first()) | ||
} | ||
builder.result() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...la/org/neo4j/cypher/internal/compiler/v2_2/planner/RealLogicalPlanningConfiguration.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* Copyright (c) 2002-2015 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.cypher.internal.compiler.v2_2.planner | ||
|
||
import org.neo4j.cypher.internal.compiler.v2_2.HardcodedGraphStatistics | ||
import org.neo4j.cypher.internal.compiler.v2_2.planner.logical.plans.LogicalPlan | ||
import org.neo4j.cypher.internal.compiler.v2_2.planner.logical.{CardinalityCostModel, Cost, StatisticsBackedCardinalityModel, Metrics} | ||
import org.neo4j.cypher.internal.compiler.v2_2.planner.logical.Metrics.{CardinalityModel, QueryGraphCardinalityInput, QueryGraphCardinalityModel} | ||
import org.neo4j.cypher.internal.compiler.v2_2.spi.GraphStatistics | ||
|
||
case class RealLogicalPlanningConfiguration() | ||
extends LogicalPlanningConfiguration with LogicalPlanningConfigurationAdHocSemanticTable { | ||
|
||
def cardinalityModel(queryGraphCardinalityModel: QueryGraphCardinalityModel, semanticTable: SemanticTable) = { | ||
val model: Metrics.CardinalityModel = new StatisticsBackedCardinalityModel(queryGraphCardinalityModel) | ||
({ | ||
case (plan: LogicalPlan, card: QueryGraphCardinalityInput) => model(plan, card) | ||
}) | ||
} | ||
|
||
def costModel(cardinality: CardinalityModel): PartialFunction[LogicalPlan, Cost] = { | ||
val model: Metrics.CostModel = new CardinalityCostModel(cardinality) | ||
({ | ||
case (plan: LogicalPlan) => model(plan, QueryGraphCardinalityInput.empty) | ||
}) | ||
} | ||
|
||
def graphStatistics: GraphStatistics = HardcodedGraphStatistics | ||
def indexes = Set.empty | ||
def uniqueIndexes = Set.empty | ||
def labelCardinality = Map.empty | ||
def knownLabels = Set.empty | ||
|
||
def qg: QueryGraph = ??? | ||
} |
Oops, something went wrong.