History | Log In     View a printable version of the current page. Get help!  
Issue Details [XML]

Key: SES-668
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Critical Critical
Assignee: Arjohn Kampman
Reporter: James Leigh
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Sesame

Nested optionals with filter produce unexpected results

Created: 21/Apr/09 04:42 PM   Updated: 19/Feb/10 07:01 PM
Component/s: Query Engine
Affects Version/s: 2.2, 2.2.1, 2.2.2, 2.2.3, 2.2.4
Fix Version/s: 2.3-pr1

Environment: Tested with the MemoryStore.


 Description   
The following test case evaluates two nearly identical queries, one places a value inline, the other uses bindings. However, only the first query returns any results.

The second query only fails if the fist optional graph matches results in the data set, but fails the filter condition.

<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
xmlns:test="urn:test:"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<test:Person rdf:about="urn:test:person">
<test:name>decoy</test:name>
</test:Person>
<test:Person rdf:about="urn:test:friend"/>
</rdf:RDF>

TupleQuery qry;
qry = con.prepareTupleQuery("SELECT * WHERE { OPTIONAL { ?s <urn:test:name> ?absent } OPTIONAL { ?s a ?present } FILTER ( ?s = <urn:test:friend> ) }");
assertTrue(qry.evaluate().hasNext());
qry = con.prepareTupleQuery("SELECT * WHERE { OPTIONAL { ?s <urn:test:name> ?absent } OPTIONAL { ?s a ?present } FILTER ( ?s = $var ) }");
qry.setBinding("var", con.getValueFactory().createURI("urn:test:friend"));
assertTrue(qry.evaluate().hasNext()); // fails here

 All   Comments   Change History      Sort Order:
Comment by Arjohn Kampman [22/Apr/09 10:23 AM]
Actually, the first evaluation fails and the second is correct. The query should not produce any results due to the left-associativeness of optionals. Since there are urn:test:name statements, the first optional matches at least one statement, which binds ?s to the value urn:test:person. This, of course, makes the filter fail.

The first query probably fails to evaluate properly due to an invalid query optimization.

Comment by Arjohn Kampman [22/Apr/09 04:18 PM]
The problem was located in SameTermFilterOptimizer, which inlined "variable assignments" even in optional parts of a query, which influenced the result of optional joins.