Package org.apache.tinkerpop.gremlin.gql
Class DefaultGqlPlanner
java.lang.Object
org.apache.tinkerpop.gremlin.gql.DefaultGqlPlanner
- All Implemented Interfaces:
GqlPlanner
Compiles a
QueryGraph into an executable GqlMatchPlan.
Algorithm
- Seed selection — each
QueryVertexis scored viaGraph.countVerticesByLabel(String). The node with the fewest matching vertices is chosen as the seed; ties are broken by list order. Seed selection is recomputed on every call so that graph mutations are always reflected. - Plan compilation — a BFS is performed over the
QueryGraphstarting from the seed node. Within each BFS node, edges are sorted by edge-label density (ascending viaGraph.countEdgesByLabel(String)) so that rarer edge labels produce extension steps earlier in the plan, pruning the DFS sooner. - Parse caching — the parsed
QueryGraphis cached keyed by the original GQL query string in a Caffeine LRU cache bounded byPLAN_CACHE_MAX_SIZE. Seed selection and step ordering are recomputed each call using live counts, avoiding stale plans after mutations.
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultGqlPlanner(Graph graph) DefaultGqlPlanner(Graph graph, com.github.benmanes.caffeine.cache.Cache<String, QueryGraph> queryGraphCache) -
Method Summary
-
Constructor Details
-
DefaultGqlPlanner
-
DefaultGqlPlanner
public DefaultGqlPlanner(Graph graph, com.github.benmanes.caffeine.cache.Cache<String, QueryGraph> queryGraphCache)
-
-
Method Details
-
plan
Returns aGqlMatchPlanfor the given GQL MATCH string. The parsedQueryGraphis cached; seed selection and step ordering are recomputed each call from live label-count data so that graph mutations are always reflected.- Specified by:
planin interfaceGqlPlanner- Parameters:
gqlMatchString- a GQL MATCH expression (e.g."MATCH (a:Person)-[:KNOWS]->(b)")- Returns:
- the compiled execution plan
- Throws:
IllegalArgumentException- if the string cannot be parsed
-