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

Optimize queries by inverting the property path #47

Open
nicolas-raoul opened this issue Nov 4, 2020 · 0 comments
Open

Optimize queries by inverting the property path #47

nicolas-raoul opened this issue Nov 4, 2020 · 0 comments

Comments

@nicolas-raoul
Copy link
Collaborator

nicolas-raoul commented Nov 4, 2020

https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/query_optimization#Inverse_property_paths

Another technique for subverting the optimizer into delivering results is to invert the property path used in the query; possibly particularly useful when dealing with timeouts of reports having wdt:P31/wdt:P279* constructions. Consider the following examples - the first times out, the second works speedily:

# Museums in Northern Ireland - TIMES OUT
SELECT distinct ?museum ?museumLabel WHERE {
  ?museum wdt:P131* wd:Q26 .
  ?museum wdt:P31/wdt:P279* wd:Q33506 .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

# Museums in Northern Ireland - SUCCEEDS
SELECT distinct ?museum ?museumLabel WHERE {
  ?museum wdt:P131* wd:Q26 .
  wd:Q33506 ^wdt:P279*/^wdt:P31 ?museum .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

It is worth a try.

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

No branches or pull requests

1 participant