I want to see as many plans of a SPARQL query as possible. That is, I don't want the optimized plan only, but all the possible plans, or at least some plans, like p1,p2,p3,p4 of a query q1. Using Apache Jena or any other such tool, is it possible? I want to try all the query plans of a query and want to see the execution time.
@UninformedUser is quite right in their comment that Jena ONLY generates a single plan by default.
However, it is theoretically possible to find all the possible plans Jena could generate by toggling on/off all the optimiser flags that control which optimisations are used.
In OptimizerStd
each possible optimisation is enabled/disabled by a context symbol. So you could generate Context
objects with different combinations of the configuration symbols enabled/disabled and create instances of the optimiser with different Context
's and see how the resulting algebra differs. There are a lot of possible optimisations so you may not want to consider every possible combination of flags, maybe start by experimenting with some more obvious ones like ARQ.optFilterPlacement
and ARQ.optIndexJoinStrategy
. You may want to explore the code further to review the actual Transform
implementations to understand the potential optimisation each flag is controlling.
Note that you will first need to parse your SPARQL string into a Jena Query
object and then compile it into algebra using Algebra.compile(Query)
. If you're interesting in the quad form of the algebra you also need Algebra.toQuadForm(Op)