SPARQL Query Optimization: Basic Graph Patterns

Ruben Taelman

UGent, 21 April 2026

SPARQL Query Optimization: Basic Graph Patterns

Ghent University – imec – IDLab, Belgium

Knowledge Graphs interlink entities

RDF for describing Knowledge Graphs

Facts are represented as RDF triples

RDF triple
RDF triple

Multiple RDF triples form RDF datasets

:Alice :knows :Bob .
:Alice :knows :Carol .
:Alice :name "Alice" .
:Bob :name "Bob" .
:Bob :knows :Carol .

Multiple RDF triples form RDF datasets

SPARQL querying over RDF datasets

SPARQL 1.1: https://www.w3.org/TR/sparql-query/

SPARQL 1.2: Upcoming in 2026

Find all artists born in York

namedeathDate
Albert Joseph Moore
Charles Francis Hansom1888
David Reed (comedian)
Dustin Gee
E Ridsdale Tate1922

Basic Graph Patterns enable graph pattern matching

Steps in SPARQL query processing

Why is optimization needed?

Example: query optimization for a BGP

How, and in what order should triple patterns be executed?

1. ?person a dbpedia-owl:Artist.

2. ?person rdfs:label ?name.

3. ?person dbpedia-owl:birthPlace ?birthPlace.

Obtain cardinality of each pattern

1. ?person a dbpedia-owl:Artist. 200

2. ?person rdfs:label ?name. 10.000

3. ?person dbpedia-owl:birthPlace ?birthPlace. 1.000

Can be pre-computed, or estimated at runtime.

Select appropriate join algorithms

Usually happens in pairs of two operators (n, m)

Join orders and algorithms influence worst-case complexity

→ Query engine aims to identify query plan with lowest cost

Conclusions

Backup slides

Competences