1

I am trying to get all the city names of all countries in the world using this below query. Whenever I execute this below query it returns this message "Query timeout limit reached".

Is there any other way to get all the data before it reaches timeout limit?

SELECT ?country ?countryLabel ?city ?cityLabel
WHERE
{
  ?city wdt:P31/wdt:P279* wd:Q515;
        wdt:P17 ?country .

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY ?country
albert
  • 11,885
  • 4
  • 30
  • 57
Karuppiah RK
  • 121
  • 4
  • 1
    Probably won’t matter, but try without the ORDER BY? – philshem Aug 24 '19 at 13:01
  • Also asked at https://stackoverflow.com/questions/57635621/sparql-get-all-the-data-before-it-reaches-timeout – TallTed Aug 26 '19 at 13:26
  • btw, for city names, check out this question: https://opendata.stackexchange.com/q/3291/1511 and also this answer about geonames data: https://opendata.stackexchange.com/a/13081/1511 – philshem Aug 27 '19 at 08:18

1 Answers1

2

Based on my comment, take out the ORDER BY.


Why? It has probably to do with the query optimizer, but I don't have any real explanation. In general, with SQL that I'm more familiar, ORDER BY when unnecessary is the first thing to take out when improving query performance.


(Note that this question was cross-posted at StackOverflow, and there is a longer discussion there.)

philshem
  • 17,647
  • 7
  • 68
  • 170