Class TransformOrderByDistinctApplication

java.lang.Object
org.apache.jena.sparql.algebra.TransformCopy
org.apache.jena.sparql.algebra.optimize.TransformOrderByDistinctApplication
All Implemented Interfaces:
Transform

public class TransformOrderByDistinctApplication extends TransformCopy

Improved optimization for ORDER BY plus DISTINCT or REDUCED combinations, see JENA-441 for original proposal and discussion.

This optimization is enabled by default as with most ARQ optimizations and may be disabled by setting the symbol ARQ.optOrderByDistinctApplication to false.

Optimization Applicability

This is a limited optimization that applies in the case where you have a query that meets the following conditions:

  • Uses both ORDER BY and DISTINCT or REDUCED on the same level of the query
  • There is a fixed list of variables to project i.e. not SELECT *
  • ORDER BY conditions only use variables present in the project list

Essentially this takes algebras of the following form:

 (distinct 
   (project (?var) 
     (order (?var) 
       ... )))
 

And produces algebra of the following form:

 (order (?var)
   (distinct 
     (project (?var) 
       ... )))
 

In the general case this in unsafe because it would change the semantics of the query since ORDER BY can access variables that are not projected. However if the conditions outlined are met then this optimization is safe, the algebras will be semantically equivalent and the resulting form likely significantly more performant, of course YMMV depending on how much data you are querying.