Class DefaultGqlExecutor

java.lang.Object
org.apache.tinkerpop.gremlin.gql.DefaultGqlExecutor
All Implemented Interfaces:
GqlExecutor

public final class DefaultGqlExecutor extends Object implements GqlExecutor
Executes a GqlMatchPlan against any TinkerPop Graph using a DFS backtracking pattern matching algorithm.

Algorithm

  1. Seed iteration: vertices are scanned from the graph (or looked up via Graph.Index when available), filtered by the seed label and seed property predicates. Each matching vertex is bound to the seed variable and used as the starting point for DFS extension.
  2. DFS extension: the search runs on an explicit stack rather than by recursion, with a shared MatchState holding the current partial match. Each stack frame is either one pending plain step expansion or one hop of a quantified walk, and holds its candidate edge iterator plus what to undo on backtrack. Steps are selected from the remaining list using DAG eligibility (anchor variable already bound), with observed selectivity, then estimated cost, then plain before quantified as the tiebreakers.
  3. Lazy delivery: execute(org.apache.tinkerpop.gremlin.gql.GqlMatchPlan) returns an Iterator that runs the DFS only until the next complete match, so each hasNext()/next() pair does the work for one row and nothing is buffered. Stack depth is bounded by heap, not by the thread stack, so long variable-length walks do not overflow.

The search checks Thread.interrupted() as it iterates and throws TraversalInterruptedException when the thread is interrupted, so a traversal timeout can stop a long-running match.

Index access is provided via Graph.index(). When Graph.Index.countVertexIndex(String, Object) returns a value less than Long.MAX_VALUE for a seed predicate key, an index lookup replaces the full vertex scan. When all counts equal Long.MAX_VALUE (no index), a full scan is used.