SPARQL EXISTS variations

There was again discussion in the SPARQL EXISTS task force on different 
solutions to the SPARQL EXISTS problems.  The solutions amount to, roughly:

Simple LEFTJOIN, where no bindings from outside the EXISTS affect the pattern 
inside.
Values injection at the beginning of the pattern (SHALLOW INJECTION).
Values injection inside the pattern (DEEP INJECTION), with two variations
values projected out in sub-SELECTs are not affected (PROJECTION) and
values projected out in sub-SELECTs are affected.

Another choice point has arisen having to do with whether the pattern is 
conceptually evaluated once for each binding (ONCE) or only once overall 
(OVERALL).  I believe that this only matters for DEEP INJECTION, i.e., 
LEFTJOIN and SHALLOW INJECTION produce the same results either way.

Here are some example queries that produce different results in the different 
solutions.

1/

PREFIX ex: <https://example.com/>
SELECT ?x WHERE {
   VALUES ?v { ex:a }
   FILTER EXISTS { FILTER ( ?v = ex:a ) }
   }

LEFTJOIN produces no binding sets, SHALLOW INJECTION and DEEP INJECTION 
produce one.

2/

PREFIX ex: <https://example.com/>
SELECT ?x WHERE {
   VALUES ?v { ex:a }
   FILTER EXISTS { { FILTER ( ?v = ex:a ) } }
   }

LEFTJOIN and SHALLOW INJECTION produce no binding sets, DEEP INJECTION 
produces one.


3/

PREFIX ex: <https://example.com/>
SELECT ?x WHERE {
   VALUES ?v { ex:a }
   FILTER EXISTS { SELECT ?x WHERE { VALUES ?x { ex:b } FILTER ( ?v = ex:a ) } }
   }

LEFTJOIN, SHALLOW INJECTION, DEEP INJECTION with PROJECTION produce no binding 
sets, DEEP INJECTION without PROJECTION produces one.


4/

PREFIX ex: <https://example.com/>
SELECT ?x WHERE {
   VALUES ?v { ex:a ex:b }
   FILTER EXISTS {
     SELECT ?x WHERE {
       FILTER ( ?x > 1 )
       { SELECT ( COUNT ( ?v ) AS ?x ) WHERE {
           VALUES ?y { ex:y }
         } GROUP BY ?y }
     }       
   }
}

DEEP INJECTION without PROJECTION and with ONCE produces no results, DEEP 
INJECTION without PROJECTION and with OVERALL produces two.


peter

Received on Saturday, 16 August 2025 14:45:07 UTC