One of the optimizations performed by JenaARQ is to: "Place filters close to where their dependency variables are defined".
This causes the following Query Plan:
(filter (exprlist (|| (|| (isIRI ?Y) (isBlank ?Y)) (!= (datatype ?Y) <http://example.com/onto/rdf#structure>)) (|| (|| (isIRI ?Z) (isBlank ?Z)) (!= (datatype ?Z) <http://example.com/onto/rdf#structure>)))
(bgp
(triple ?X <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://swat.cse.lehigh.edu/onto/univ-bench.owl#Student>)
(triple ?Y <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://swat.cse.lehigh.edu/onto/univ-bench.owl#Faculty>)
(triple ?Z <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://swat.cse.lehigh.edu/onto/univ-bench.owl#Course>)
(triple ?X <http://swat.cse.lehigh.edu/onto/univ-bench.owl#advisor> ?Y)
(triple ?Y <http://swat.cse.lehigh.edu/onto/univ-bench.owl#teacherOf> ?Z)
(triple ?X <http://swat.cse.lehigh.edu/onto/univ-bench.owl#takesCourse> ?Z)
)))
To be transformed into the following:
(sequence
(filter (|| (|| (isIRI ?Z) (isBlank ?Z)) (!= (datatype ?Z) <http://example.com/onto/rdf#structure>))
(sequence
(filter (|| (|| (isIRI ?Y) (isBlank ?Y)) (!= (datatype ?Y) <http://example.com/onto/rdf#structure>))
(bgp
(triple ?X <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://swat.cse.lehigh.edu/onto/univ-bench.owl#Student>)
(triple ?Y <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://swat.cse.lehigh.edu/onto/univ-bench.owl#Faculty>)
))
(bgp (triple ?Z <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://swat.cse.lehigh.edu/onto/univ-bench.owl#Course>))))
(bgp
(triple ?X <http://swat.cse.lehigh.edu/onto/univ-bench.owl#advisor> ?Y)
(triple ?Y <http://swat.cse.lehigh.edu/onto/univ-bench.owl#teacherOf> ?Z)
(triple ?X <http://swat.cse.lehigh.edu/onto/univ-bench.owl#takesCourse> ?Z)
)))
It turns out that while the original query plan runs in milliseconds the "optimized" query plan takes about 7 hours to be concluded.
Does JenaARQ consider any statistics for optimizing the filter placement in the query plan?
I'm using Jena 3.12.0.