Now a lot of users of SPARQL probably don’t even know what I mean by the above, but I would give you good odds that most people are using the former without realizing it or knowing that the latter could actually be more performant in many scenarios.

So to illustrate this, let’s show you the difference in syntax. First, let’s see value equality:

FILTER(?x = 1)

And now let’s look at the corresponding term equality form:

FILTER(SAMETERM(?x, 1))

The syntactic difference is obvious –value equality uses the = operator while term equality uses the SAMETERM function. The latter is likely more performant but it does have a drawback in that it is only term equality. Term equality only returns true if the RDF terms are identical. So if the RDF term in the database was encoded as “001″^^xsd:integer term equality would give false whereas value equality would return true because the value of the terms is equivalent.

As a general rule, use term equality wherever the value of the term is not an issue, such as when you are matching URIs or non-value typed literals (e.g. plain literals, xsd:string, literals with language tags). Also if you know the RDF terms in your database are consistently encoded (or your database does this for you), then always use term equality unless value equality is more appropriate for your query.

Note that many SPARQL engines will be clever enough to turn value equality into term equality when possible, but not all will, so sometimes if you have a slow running query when using value equality, try switching to term equality and see if that improves things.



« Now a lot of users... »


A quote saved on May 3, 2013.

#differences
#database
#most-people
#values


Top related keywords - double-click to view: