Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SERVICE query ignores LIMIT #1655

Open
hannahbast opened this issue Dec 2, 2024 · 2 comments
Open

SERVICE query ignores LIMIT #1655

hannahbast opened this issue Dec 2, 2024 · 2 comments

Comments

@hannahbast
Copy link
Member

The following query should return a single row, but it takes forever because the SERVICE query is executed without the LIMIT 1.

@UNEXENU and @joka921 Do you have an idea why that is the case?

SELECT * WHERE {
  SERVICE <https://qlever.cs.uni-freiburg.de/api/wikidata> {
    SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT 1
  }
}

https://qlever.cs.uni-freiburg.de/wikidata/RJCTro

@hannahbast hannahbast changed the title SERVICE query ignore LIMIT SERVICE query ignores LIMIT Dec 2, 2024
@UNEXENU
Copy link
Contributor

UNEXENU commented Dec 3, 2024

I've replicated the error with the following query on the olympics dataset:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX olympics: <http://wallscope.co.uk/ontology/olympics/>
PREFIX medal: <http://wallscope.co.uk/resource/olympics/medal/>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT * WHERE {
  SERVICE <https://qlever.cs.uni-freiburg.de/olympics> {
    SELECT ?athlete WHERE {
      ?athlete dbo:team <http://wallscope.co.uk/resource/olympics/team/Germany> .
    }
    LIMIT 1
  }
}

Whats happening is, the Service puts a SELECT-clause with the visible variables around the query it gets passed - here SELECT ?athlete WHERE { SELECT ?athlete WHERE { ... } LIMIT 1}.

So the Service-endpoint in the query above basically computes the same incorrect result as the following nested query:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX olympics: <http://wallscope.co.uk/ontology/olympics/>
PREFIX medal: <http://wallscope.co.uk/resource/olympics/medal/>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT ?athlete WHERE {
  SELECT ?athlete WHERE {
    ?athlete dbo:team <http://wallscope.co.uk/resource/olympics/team/Germany> .
  }
  LIMIT 1
}

It somehow works (returns one row) when ORDER BY ?athlete is added before LIMIT 1, however i don't know why that is the case.

@hannahbast
Copy link
Member Author

@UNEXENU Thanks a lot for the reply. The issue has indeed nothing to do with SERVICE. It happens exactly when there is a subquery with a single index scan and a LIMIT. A minimal dataset-independent example is:

SELECT * WHERE {
  SELECT * WHERE { ?s ?p ?o } LIMIT 1
}

https://qlever.cs.uni-freiburg.de/wikidata/IUeShp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants