concept explain() in category graphs

appears as: explain()
Graph Databases in Action

This is an excerpt from Manning's book Graph Databases in Action.

We should say upfront that the explain() step is rarely our first step in troubleshooting. We usually use the profiling tools we discuss in the next section. We find that using this step to locate issues with poor performing traversals requires a deep knowledge of the inner workings of the databases. However, the explain() step is a commonly available tool across different database instances and some people find them to be useful in debugging, so we’ll give it a little attention.

Let’s say we wanted to know “how” our traversal will run, but not execute it. Most graph databases perform this type of debugging step via the use of an explain() step. This would be similar to an “Estimated Execution Plan” in a relational database, in as much as it shows the output of the database optimizer after it rearranges and optimizes the traversal (Gremlin does this through the use of strategies[1]) but before it actually runs it on the data. The important part to focus on is the final traversal plan. This represents the final, optimized plan to be executed on the graph data. The lines before that are the various options which were applied in order to reach the final version.

The best illustration is to run one and examine the output. In the example below the Final Traversal is highlighted in bold and the non-optimized options are removed for brevity. Let’s run an explain() step on our slow traversal and see if we can draw any conclusions from the output: