opencypher.org opencypher.org | opencypher@googlegroups.com
• • • • • • opencypher.org opencypher.org | opencypher@googlegroups.com
START john=node:Person(name="John") MATCH john-[:KNOWS]-friend-[:KNOWS]-foaf RETURN foaf opencypher.org opencypher.org | opencypher@googlegroups.com
START john=node:Person(name="John") MATCH (john)-[:KNOWS]-(friend)-[:KNOWS]-(foaf) WHERE NOT (john)-[:KNOWS]-(foaf) AND NOT (john)-[:RECOMMENDATION]->(foaf) CREATE (john)-[:RECOMMENDATION]->(foaf) RETURN foaf opencypher.org opencypher.org | opencypher@googlegroups.com
MATCH (john:Person{name:"John"}), (john)-[:KNOWS]-(friend)-[:KNOWS]-(foaf) WHERE NOT (john)-[:KNOWS]-(foaf) MERGE (john)-[:RECOMMENDATION]->(foaf) opencypher.org opencypher.org | opencypher@googlegroups.com
Query => AST => AST’ AST’ => Query Graph => Logical Plan L Plan => Instruction => CodeGen => JVM Class opencypher.org opencypher.org | opencypher@googlegroups.com
(query:String)-[:PARSED_TO]->(:AST {pos: $pos}) opencypher.org opencypher.org | opencypher@googlegroups.com
SemanticState => SemanticState opencypher.org opencypher.org | opencypher@googlegroups.com
The AST is optimised and canonicalized Custom functional rewriting code opencypher.org opencypher.org | opencypher@googlegroups.com
opencypher.org opencypher.org | opencypher@googlegroups.com
Output: Logical Plans similar to relational query plans Expand/VarExpand are the main differences to normal relational algebra opencypher.org opencypher.org | opencypher@googlegroups.com
Similar to the System R - Dynamic Programming Quick Reminder, the Selinger Algorithm: 1. Enumerate all access paths for single relation 2. Consider all ways to join two relations 3. Consider all ways to join three relations, etc [Access path selection in a relational database management system, Selinger et al] opencypher.org opencypher.org | opencypher@googlegroups.com
Neo4j Cost Planner 1. Enumerate all access paths for pattern nodes 2. Consider all ways to expand pattern relationships 3. Consider all ways to solve two pattern relationships, either by expand or join, etc for three, four patter relationships [Iterative dynamic programming: a new class of query optimization algorithms, Kossman, Stocker] opencypher.org opencypher.org | opencypher@googlegroups.com
Pattern: (a)-[r1]->(b)<-[r2]-(c) e -[r2]-> (c) ⋈ Solutions: e (b)<-[r2]- e -[r1]-> (b) e -[r1]-> (b) |a| |a| |c| opencypher.org opencypher.org | opencypher@googlegroups.com
opencypher.org opencypher.org | opencypher@googlegroups.com
opencypher.org opencypher.org | opencypher@googlegroups.com
IDPSolver SingleComponentPlanner CardinalityCostModel opencypher.org opencypher.org | opencypher@googlegroups.com
• • accept(...) L Plan => Instruction => CodeGen => JVM Class [Efficiently Compiling Efficient Query Plans for Modern Hardware, Thomas Neumann] opencypher.org opencypher.org | opencypher@googlegroups.com
Instruction Cypher While(Variable("v1") -> ScanAllNodes()){ Selection( MATCH (n) If("v1=100", WHERE n.x = 100 AcceptVisitor( Map("n"-> NodeProjection(Variable("v1")))))) RETURN n } ) opencypher.org opencypher.org | opencypher@googlegroups.com
AllNodesScan Filter Project opencypher.org opencypher.org | opencypher@googlegroups.com
AllNodesScan Filter Project opencypher.org opencypher.org | opencypher@googlegroups.com
opencypher.org opencypher.org | opencypher@googlegroups.com
Recommend
More recommend