Subselect in OPTIONAL drops variable bindings

Description

Reported by Ruslan (Ontotext):

Consider the following query:

When you evaluate the sub-SELECT in the OPTIONAL all the bindings but ?val are cut and not returned by the query. So when you select ?x you'll receive an empty binding set. This is wrong because ?x is in the mandatory part of the query.

When the query gets evaluated, its TupleExpr is Join(LeftJoin(Projection, Projection),
StatementPattern) which is even worse because passing through the OPTIONAL takes place earlier, ?v gets unbound and the remaining part of the query is evaluated for all possible values for ?v. I understood that the query tree is rearranged by the optimizer called QueryModelNormalizer which
converts it to LeftJoin(Join(Projection), StatementPattern), Projection) as it used to be in
Sesame 2.7.8.

Environment

None

Assignee

Jeen Broekstra

Reporter

Jeen Broekstra

Labels

None

Fix versions

Affects versions

Priority

Major
Configure