While I was exploring some SPARQL queries I noticed that fetching distinct predicates is extremely slow but no such issues while fetching subjects or objects.
I tested it with linkedgeodata and I ran the following queries at linkedgeodata's endpoint (SERVICE command not used in this case for obvious reasons), SPARQL playground and Apache Jena Fuseki server. The behavior was same. Can anyone help me understand the reason behind it?
#selecting distinct subjects. Executes fast
SELECT * WHERE {
SERVICE <http://linkedgeodata.org/sparql> {
select distinct ?s
where{
?s ?p ?o .
} limit 100
}
}
#selecting distinct predicates. VERY SLOW
SELECT * WHERE {
SERVICE <http://linkedgeodata.org/sparql> {
select distinct ?p
where{
?s ?p ?o .
} limit 100
}
}