Search code examples
sparqlsemantic-web

SPARQL optional not bound VS filter not exists


Is there a difference (in term of performances, respects of standards or anything else) between:

select distinct ?planeWithoutPassengers where {
    ?planeWithoutPassengers a <http://example.org/plane> .
    filter not exists {
        ?planeWithoutPassengers <http://example.org/hasPassenger> ?passenger .
    }
}

And:

select distinct ?planeWithoutPassengers where {
    ?planeWithoutPassengers a <http://example.org/plane> .
    optional {
        ?planeWithoutPassengers <http://example.org/hasPassenger> ?passenger .
    }
    filter (!bound(?passenger)).
}

Solution

  • There is no real difference. The second one is the older version which also works on SPARQL 1.0 engines. However the first one is preferred as it reads more intuitively.