SPARQL query performance with rdflib-sqlalchemy

2019-07-14 08:49发布

问题:

I have 7200 or so SKOS.Concept objects created by rdflib-sqlalchemy from parsing a turtle file stored in a Postgres DB.

The following SPARQL query takes over 30 seconds to respond with data:

 SELECT ?subject ?prefLabel
 WHERE { ?subject rdf:type 
 <http://www.w3.org/2004/02/skos/core#Concept> .
 ?subject skos:prefLabel ?prefLabel .
 FILTER (lang(?prefLabel) = 'en') } 
 order by ?prefLabel
 LIMIT 20 OFFSET 0

I am using the limit and offset to paginate through results. I pass in the language parameter (one of ar, en, es, fr, ru, zh).

If I simply select the subject, the resulting query is lightning fast -- but I need to collate by prefLabel in the result set.

This is a query that ran very fast in a key value store (Sleepycat) but crawls when moving to rdlib-sqlalchemy with a Postgres backend.

I am quite new to rdlif and SPARQL -- any suggestions or insights would be welcome.

Thanks in advance!