1

I have a straightforward query that counts how many humans have an English Wikipedia page.

prefix schema: <http://schema.org/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>

SELECT ?item ?article
WHERE 
{
  ?item wdt:P31 wd:Q5 . # Must be of a human
  ?article schema:about ?item ; # Must have a Wikipedia article
           schema:inLanguage "en" ; # Article must be in English
           schema:isPartOf <https://en.wikipedia.org/> . # Wikipedia article must be regular article
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } # Helps get the label in your language, if not, then en language
}

I get expected output as follows:

 wd:Q11124  <https://en.wikipedia.org/wiki/Stephen_Breyer>
 wd:Q10727  <https://en.wikipedia.org/wiki/Steve_Leo_Beleck>
 wd:Q10065  <https://en.wikipedia.org/wiki/Taichang_Emperor>
 wd:Q9605   <https://en.wikipedia.org/wiki/Sarah_Allen_(software_developer)>

However, if I change the SELECT statement from

SELECT ?item ?article

to

SELECT (count(?item) as ?count)

I get timeout error. Please note that the count statement works if I only specify "human" condition and exclude English Wiki article condition. So, clearly, some kind of background join is causing the query to timeout.

However, this is a fairly trivial join, so the query timeout is surprising.

Please let me know what may I be missing here.

Thanks!

2

2 Answers 2

1

It is often tricky to avoid Wikidata query timeouts.

When that happens, I often split the request into different requests, then merge the data afterwards, using a script.

For instance, you may want to try the request for humans who were born on a particular date? Depending on your purpose, that might even be sufficient (for instance if you just wanted a rough estimation).

0

You could ask your query at Wikidata's Request a query site.

I had the same problem once with one of their example queries. After a few hours some real expert rewrote the slow query, adding some cryptic optimizatioin hints and flags, and afterwards the query ran in seconds.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.