Query optimizations

GraphDB uses a number of query optimization techniques by default. They can be disabled by using the enable-optimization configuration parameter set to false, however there is rarely any need to do this.

See also

GraphDB’s Query profiling with the Explain plan explains how to view query plans and applied optimizations.

Note

GraphDB allows hints for guiding the query optimizer.

Caching literal language tags

This optimization applies when the repository contains a large number of literals with language tags, and it is necessary to execute queries that filter based on language, for example, using the following SPARQL query construct:

FILTER ( langMatches(lang(?name), "es") )

In this case, the in-memory-literal-properties configuration parameters can be set to true, causing the data values with language tags to be cached.

Not enumerating sameAs

During query answering, all URIs from each equivalence class produced by the sameAs optimization are enumerated. You can use the onto:disable-sameAs pseudo-graph to significantly reduce these duplicate results by returning a single representative from each equivalence class.

Consider these example queries executed against the FactForge combined dataset. Here, the default is to enumerate:

PREFIX onto: <http://www.ontotext.com/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
SELECT *
# FROM onto:disable-sameAs
{
    ?x a dbo:Airport; dbo:location dbr:Bulgaria
}

As shown, this query returns 30 results. If you uncomment the FROM onto:disable-sameAs line, the query returns 27 results.

The Expand results over equivalent URIs checkbox in the GraphDB Workbench SPARQL editor plays a similar role, but the meaning is reversed.

Warning

If the query uses a filter over the textual representation of a URI, such as filter(strstarts(str(?x),"http://dbpedia.org/ontology")), the response may omit some valid solutions, as not all URIs within an equivalence class are matched against the filter.