How to use precomputed custom cardinalities instead of cardinalities estimated by Neo4j in the query optimizer?


I’d like to compare the query execution time using my custom cardinalities with that using cardinalities estimated by Neo4j's query optimizer.

I have the following plans to know the effect of cardinality estimation on the query execution time by modifying Neo4j code, but I'm not sure whether the following plans are correct or not.

  1. Given a query, precompute “custom_cardinality” for all subqueries(all possible query plans) of the given query. (Here, “custom_cardinality” can be an actual cardinality or estimate obtained by the other ways.)
  2. Modify “LogicalPlanProducer.scala” using “cardinalities.set(, custom_cardinality)” instead of “cardinalities.set(, cardinality)” (Here, custom_cardinality is precomputed in Step 1.)

I referred to the following code. (LogicalPlanProducer.scala in Neo4j-4.0)
(neo4j/LogicalPlanProducer.scala at 4.0 · neo4j/neo4j · GitHub)

  1. Is it correct to compare the query execution time of the original code with the modified code as planned above?

  2. Are there any other modifications I have to consider?

  3. I’d like to know how to dump the plan using “LogicalPlan” data structure in "LogicalPlanProducer.scala".