Class DefaultGqlPlanner

java.lang.Object
org.apache.tinkerpop.gremlin.gql.DefaultGqlPlanner
All Implemented Interfaces:
GqlPlanner

public final class DefaultGqlPlanner extends Object implements GqlPlanner
Compiles a QueryGraph into an executable GqlMatchPlan.

Algorithm

  1. Seed selection — each QueryVertex is scored via Graph.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.
  2. Plan compilation — a BFS is performed over the QueryGraph starting from the seed node. Within each BFS node, edges are sorted by edge-label density (ascending via Graph.countEdgesByLabel(String)) so that rarer edge labels produce extension steps earlier in the plan, pruning the DFS sooner.
  3. Parse caching — the parsed QueryGraph is cached keyed by the original GQL query string in a Caffeine LRU cache bounded by PLAN_CACHE_MAX_SIZE. Seed selection and step ordering are recomputed each call using live counts, avoiding stale plans after mutations.
  • Constructor Details

    • DefaultGqlPlanner

      public DefaultGqlPlanner(Graph graph)
    • DefaultGqlPlanner

      public DefaultGqlPlanner(Graph graph, com.github.benmanes.caffeine.cache.Cache<String,QueryGraph> queryGraphCache)
  • Method Details

    • plan

      public GqlMatchPlan plan(String gqlMatchString)
      Returns a GqlMatchPlan for the given GQL MATCH string. The parsed QueryGraph is cached; seed selection and step ordering are recomputed each call from live label-count data so that graph mutations are always reflected.
      Specified by:
      plan in interface GqlPlanner
      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