Skip to content

Commit

Permalink
Merge pull request #5603 from Mats-SX/2.2-selectivity-precision
Browse files Browse the repository at this point in the history
Add LDBC test to cover precision loss
  • Loading branch information
pontusmelke committed Oct 15, 2015
2 parents da58f8d + f90ab3f commit 7c11899
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
*/
package org.neo4j.cypher

import org.neo4j.cypher.internal.compiler.v2_2.pipes.RonjaPipe
import org.neo4j.cypher.internal.compiler.v2_2.planDescription._

/**
* Runs the 14 LDBC queries and checks so that the result is what is expected.
*/
Expand All @@ -38,4 +41,32 @@ class LdbcAcceptanceTest extends ExecutionEngineFunSuite with NewPlannerTestSupp
result should equal(ldbcQuery.expectedResult)
}
}

test("LDBC query 12 should not get a bad plan because of lost precision in selectivity calculation") {
executeWithRulePlannerOnly(LdbcQueries.Query12.createQuery, LdbcQueries.Query12.createParams.toSeq: _*)
LdbcQueries.Query12.constraintQueries.foreach(executeWithRulePlannerOnly(_))

val updatedLdbc12 =
"""MATCH (:Person {id:{1}})-[:KNOWS]-(friend:Person)
|MATCH (friend)<-[:COMMENT_HAS_CREATOR]-(comment:Comment)-[:REPLY_OF_POST]->(:Post)-[:POST_HAS_TAG]->(tag:Tag)-[:HAS_TYPE]->(tagClass:TagClass)-[:IS_SUBCLASS_OF*0..]->(baseTagClass:TagClass)
|WHERE tagClass.name = {2} OR baseTagClass.name = {2}
|RETURN friend.id AS friendId, friend.firstName AS friendFirstName, friend.lastName AS friendLastName, collect(DISTINCT tag.name) AS tagNames, count(DISTINCT comment) AS count
|ORDER BY count DESC, friendId ASC
|LIMIT {3}
""".stripMargin

val params: Map[String, Any] = Map("1" -> 0, "2" -> 1, "3" -> 10)

val result = executeWithAllPlanners(s"PROFILE $updatedLdbc12", params.toSeq:_*)

// no precision loss resulting in insane numbers
all (collectEstimations(result.executionPlanDescription())) should be > 0.0
all (collectEstimations(result.executionPlanDescription())) should be < 10.0
}

private def collectEstimations(plan: InternalPlanDescription): Seq[Double] = {
(plan.pipe match {
case r: RonjaPipe => r.estimatedCardinality.get
}) +: plan.children.toSeq.flatMap(collectEstimations)
}
}

0 comments on commit 7c11899

Please sign in to comment.