On 18/07/12 16:25, Simon Helsen wrote:
Andy,

I have simplified the scenario a little bit. So the following query

PREFIX p1:<t1>
PREFIX p2:<t2>
SELECT DISTINCT ?R1 ?optionalValue
WHERE
{
?R1 p1:pr1 <https://host:9443/jts/process/project-areas/p>
FILTER ( ?R1 = <https://host:9443/rm/resources/_r1>)
OPTIONAL
{ ?R1 p2:pr2 ?optionalValue }
}

leads to

(prefix ((p1: <file:///C:/Temp/t1>)
          (p2: <file:///C:/Temp/t2>))
   (distinct
     (project (?R1 ?optionalValue)
       (filter (= ?R1 <https://host:9443/rm/resources/_r1>)
         (conditional
           (bgp (triple ?R1 p1:pr1
<https://host:9443/jts/process/project-areas/p>))
           (bgp (triple ?R1 p2:pr2 ?optionalValue)))))))

whereas the following query

PREFIX p1:<t1>
PREFIX p2:<t2>
SELECT DISTINCT ?R1 ?optionalValue
WHERE
{
{
?R1 p1:pr1 <https://host:9443/jts/process/project-areas/p>
FILTER ( ?R1 = <https://host:9443/rm/resources/_r1>)
}
OPTIONAL
{ ?R1 p2:pr2 ?optionalValue }
}

leads to

(prefix ((p1: <file:///C:/Temp/t1>)
          (p2: <file:///C:/Temp/t2>))
   (distinct
     (project (?R1 ?optionalValue)
       (conditional
         (assign ((?R1 <https://host:9443/rm/resources/_r1>))
           (bgp (triple <https:/host:9443/rm/resources/_r1> p1:pr1
<https://perfjts.ibm.com:9443/jts/process/project-areas/p>)))
         (bgp (triple ?R1 p2:pr2 ?optionalValue))))))

So, looking at this in more detail, the former plan surprises me a bit
because it proposes to evaluate p1:pr1 as optional, even though I didn't
express that in the query.

Yes, you did.

"conditional" is a binary operator, an optimized for of leftjoin. The first arg is the fixed side and the second args the conditional part.


{ ?s ?p ?o OPTIONAL { ?s1 ?p1 ?o1 } }

becomes

(leftjoin
   (bgp (triple ?s ?p ?o)
   (bgp (triple ?s1 ?p1 ?o1))

which is executed as

(conditional
   (bgp (triple ?s ?p ?o)
   (bgp (triple ?s1 ?p1 ?o1))

(sequence) is rather different.

WHERE
{
{
?R1 p1:pr1 <https://host:9443/jts/process/project-areas/p>
FILTER ( ?R1 = <https://host:9443/rm/resources/_r1>)
}
OPTIONAL
{ ?R1 p2:pr2 ?optionalValue }
}

is a different query because FILTERS are group-wide, a group being what is between {} (caveat a special case in OPTIONAL not occuring here).

Adding the extra {} means the FILTER is applied to

 ?R1 p1:pr1 <https://host:9443/jts/process/project-areas/p>

alone.

        Andy

Reply via email to