On 20/02/12 06:09, Holger Knublauch wrote:
On Feb 18, 2012, at 9:48 PM, Andy Seaborne wrote:
Why not prebind it?
The problem is that ?this iterates over many instances, while
pre-binding would only allow me to bind a single value per
execution.
Do you expect the system to any better than loop over the instances?
BINDINGS does, in fact, give that possibility although it's not going to
happen because, internally, the optimizer flips the data to the left
side of a join and then it will use index joins for execution.
The only possibility I see (and this issn't ARQ specific) is if the
expression that is used to calculate the ?this instances is placed in
the query itself so optimization sees everything at once, else you are,
in effect, second guessing the optimization process.
However, this is the solution that I today ended up with. From your
responses I noticed that there is no simple generic solution to
pre-binding an iteration of values to a variable everywhere in the
query,
Submit a patch!
so that the SPIN API now uses the following logic: If a rule
or constraint uses ?this in a deeply nested clause (i.e. not on the
top level of the WHERE clause) then it uses an outer loop to walk
through the instances and pre-bind ?this. Otherwise it inserts a
?this a ?THIS_TYPE clause into the start of the WHERE clause to
optimize performance.
What happens if ?this is used in several places?
This algorithm sounds like the safest (less error prone than trying
to be super smart about the syntax of queries). If I get too much
pushback from SPIN users that performance has gone down (due to the
many QueryExecution objects etc)
If you process the algebra, then the overhead is less as you can process
the post-optimizer algebra and execute that directly.
then I can always try to get back to
a smarter algorithm. But not all queries require using ?this in deep
places, and users can work around this by reformulating their queries
as well.
Thanks Holger
Do you need to have this split mode execution? Why not build a single
query that calculates ?this (we do this in the linked data API), not
puts it in a repeated substitution?
Andy