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.
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, 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. 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) 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
