Variable scope for subqueries

This is in reference to ISSUE-4 
(http://www.w3.org/2009/sparql/track/issues/4) and is in discharge of 
ACTION-16.

At the F2F, we had a short discussion about variable scope and 
subqueries: http://www.w3.org/2009/sparql/meeting/2009-05-07#line0199

At the time, Axel asked for a fleshed out example of the query that Andy 
used on IRC to demonstrate the scoping issue.

Andy's query on IRC was :

SELECT * { {?x :p ?v } { SELECT * { ?x :q ?w FILTER (?v>3) } } }

...but I don't believe that demonstrates the proper issue. The above 
query has the (non-)issue of whether ?v is visible inside the subquery. 
I believe that SPARQL Query/1.0 already answers that: the bottom-up 
nature of SPARQL's algebra means that the scope of the FILTER is within 
the subquery's group. The only way that this FILTER would apply to 
bindings from the {?x :p ?v} BGP is via a top-down evaluation model, and 
that would be a breaking change to current SPARQL semantics.

Instead, I think this query demonstrates the scoping issue for subqueries:

SELECT * { ?x :p1 ?y {SELECT ?x { ?x :p 2?y }} FILTER(?y > 3)}

The question is, I think, does the subquery's projection completely hide 
the "inner" ?y from the rest of the query? I believe there was clear 
consensus at the F2F that the answer is "yes", which is consistent with 
current SPARQL bottom-up semantics and with projection in general.

Anyway, having reviewed this issue, I think it's more of a non-issue, as 
I haven't seen any advocates for an alternative approach. If anyone is 
unhappy with this resolution to ISSUE-4, please let us know.

Lee

Received on Monday, 31 August 2009 05:46:47 UTC