Skip to content

Commit

Permalink
Use kernel API for count ops in interpreted runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusmelke committed Feb 26, 2018
1 parent ba247d4 commit 98ce8c8
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
Expand Up @@ -137,7 +137,7 @@ STATEMENT <: AnyRef](configV3_4: CypherCompilerConfiguration,
def isPeriodicCommit: Boolean = inner.isPeriodicCommit

def isStale(lastCommittedTxId: LastCommittedTxIdProvider, ctx: TransactionalContextWrapper): CacheCheckResult =
inner.checkPlanResusability(lastCommittedTxId, TransactionBoundGraphStatistics(ctx.readOperations))
inner.checkPlanResusability(lastCommittedTxId, TransactionBoundGraphStatistics(ctx.dataRead, ctx.readOperations))

override val plannerInfo: PlannerInfo = {
new PlannerInfo(inner.plannerUsed.name, inner.runtimeUsed.name, inner.plannedIndexUsage.map {
Expand Down
Expand Up @@ -130,7 +130,7 @@ extends LatestRuntimeVariablePlannerCompatibility[CONTEXT3_4, T, StatementV3_3](
notificationLoggerV3_3, graphStatisticsV3_3))

val graphStatisticsV3_4 = InstrumentedGraphStatisticsV3_4(
TransactionBoundGraphStatistics(transactionalContext.tc.readOperations()),
TransactionBoundGraphStatistics(transactionalContext.dataRead, transactionalContext.tc.readOperations()),
graphStatisticsSnapshotV3_4)
val planContextV3_4 = new ExceptionTranslatingPlanContextV3_4(
new TransactionBoundPlanContext(tcV3_4, notificationLoggerV3_4, graphStatisticsV3_4))
Expand Down
Expand Up @@ -21,17 +21,19 @@ package org.neo4j.cypher.internal.runtime.interpreted

import org.neo4j.cypher.internal.planner.v3_4.spi.{GraphStatistics, IndexDescriptor, StatisticsCompletingGraphStatistics}
import org.neo4j.cypher.internal.util.v3_4.{Cardinality, LabelId, RelTypeId, Selectivity}
import org.neo4j.internal.kernel.api.Read
import org.neo4j.kernel.api.ReadOperations
import org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException

object TransactionBoundGraphStatistics {
def apply(ops: ReadOperations) = new StatisticsCompletingGraphStatistics(new BaseTransactionBoundGraphStatistics(ops))
def apply(read: Read, ops: ReadOperations) = new StatisticsCompletingGraphStatistics(new BaseTransactionBoundGraphStatistics(read, ops))

private class BaseTransactionBoundGraphStatistics(operations: ReadOperations) extends GraphStatistics with IndexDescriptorCompatibility {
//TODD remove ReadOperations when schema ops are ported
private class BaseTransactionBoundGraphStatistics(read: Read, operations: ReadOperations) extends GraphStatistics with IndexDescriptorCompatibility {

def indexSelectivity(index: IndexDescriptor): Option[Selectivity] =
try {
val labeledNodes = operations.countsForNodeWithoutTxState( index.label ).toDouble
val labeledNodes = read.countsForNodeWithoutTxState( index.label ).toDouble

// Probability of any node with the given label, to have a property with a given value
val indexEntrySelectivity = operations.indexUniqueValuesSelectivity(cypherToKernel(index))
Expand All @@ -46,7 +48,7 @@ object TransactionBoundGraphStatistics {

def indexPropertyExistsSelectivity(index: IndexDescriptor): Option[Selectivity] =
try {
val labeledNodes = operations.countsForNodeWithoutTxState( index.label ).toDouble
val labeledNodes = read.countsForNodeWithoutTxState( index.label ).toDouble

// Probability of any node with the given label, to have a given property
val indexSize = operations.indexSize(cypherToKernel(index))
Expand All @@ -59,10 +61,10 @@ object TransactionBoundGraphStatistics {
}

def nodesWithLabelCardinality(labelId: Option[LabelId]): Cardinality =
atLeastOne(operations.countsForNodeWithoutTxState(labelId))
atLeastOne(read.countsForNodeWithoutTxState(labelId))

def cardinalityByLabelsAndRelationshipType(fromLabel: Option[LabelId], relTypeId: Option[RelTypeId], toLabel: Option[LabelId]): Cardinality =
atLeastOne(operations.countsForRelationshipWithoutTxState(fromLabel, relTypeId, toLabel))
atLeastOne(read.countsForRelationshipWithoutTxState(fromLabel, relTypeId, toLabel))

/**
* Due to the way cardinality calculations work, zero is a bit dangerous, as it cancels out
Expand All @@ -76,7 +78,7 @@ object TransactionBoundGraphStatistics {
Cardinality(count)
}

override def nodesAllCardinality(): Cardinality = atLeastOne(operations.countsForNodeWithoutTxState(-1))
override def nodesAllCardinality(): Cardinality = atLeastOne(read.countsForNodeWithoutTxState(-1))
}
}

Expand Down
Expand Up @@ -40,7 +40,8 @@ import scala.collection.JavaConverters._

object TransactionBoundPlanContext {
def apply(tc: TransactionalContextWrapper, logger: InternalNotificationLogger) =
new TransactionBoundPlanContext(tc, logger, InstrumentedGraphStatistics(TransactionBoundGraphStatistics(tc.readOperations),
new TransactionBoundPlanContext(tc, logger, InstrumentedGraphStatistics(TransactionBoundGraphStatistics(tc.dataRead,
tc.readOperations),
new MutableGraphStatisticsSnapshot()))
}

Expand Down
Expand Up @@ -65,9 +65,7 @@ import org.neo4j.kernel.impl.query.Neo4jTransactionalContext
import org.neo4j.kernel.impl.util.ValueUtils.{fromNodeProxy, fromRelationshipProxy}
import org.neo4j.kernel.impl.util.{DefaultValueMapper, NodeProxyWrappingNodeValue, RelationshipProxyWrappingValue}
import org.neo4j.values.storable.CoordinateReferenceSystem.{Cartesian, WGS84}
import org.neo4j.values.storable._
import org.neo4j.values.storable.{PointValue, TextValue, Value, Values}
import org.neo4j.values.storable.{TextValue, Value, Values}
import org.neo4j.values.storable.{PointValue, TextValue, Value, Values, _}
import org.neo4j.values.virtual.{ListValue, NodeValue, RelationshipValue, VirtualValues}
import org.neo4j.values.{AnyValue, ValueMapper}

Expand Down Expand Up @@ -944,11 +942,11 @@ sealed class TransactionBoundQueryContext(val transactionalContext: Transactiona
}

override def nodeCountByCountStore(labelId: Int): Long = {
transactionalContext.statement.readOperations().countsForNode(labelId)
reads().countsForNode(labelId)
}

override def relationshipCountByCountStore(startLabelId: Int, typeId: Int, endLabelId: Int): Long = {
transactionalContext.statement.readOperations().countsForRelationship(startLabelId, typeId, endLabelId)
reads().countsForRelationship(startLabelId, typeId, endLabelId)
}

override def lockNodes(nodeIds: Long*) =
Expand Down

0 comments on commit 98ce8c8

Please sign in to comment.