Page MenuHomePhabricator

Path query for taxons times out
Closed, ResolvedPublic

Description

This query:

SELECT ?item ?taxonName ?taxonRank ?parentName ?parentRank ?higherParent WHERE {
  BIND("Rivasmartinezia" AS ?taxonName) .
  BIND(wd:Q34740 AS ?taxonRank) . # Genus
  BIND(wd:Q756 AS ?higherParent) . # Plantae
  ?item wdt:P225 ?taxonName .
  ?item wdt:P105 ?taxonRank .
  ?item wdt:P171/wdt:P225 ?parentName .
  ?item wdt:P171/wdt:P105 ?parentRank .
  ?item (wdt:P171)* ?higherParent .
}

Times out even though it has only one match for ?item (wd:Q26902704) and this:

ASK {
  BIND(wd:Q756 AS ?higherParent) . # Plantae
  wd:Q26902704 (wdt:P171)+ ?higherParent .
}

is fast.

See: https://www.wikidata.org/wiki/Wikidata:Contact_the_development_team#SPARQL:_.28wdt:P171.29.2A

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript
Smalyshev renamed this task from path query times out to Path query for taxons times out.Sep 16 2016, 11:35 PM
Smalyshev moved this task from Incoming to Blazegraph on the Wikidata-Query-Service board.

This one works now:

SELECT ?item ?taxonName ?taxonRank ?parentName ?parentRank ?higherParent WHERE {
  BIND("Rivasmartinezia" AS ?taxonName) .
  BIND(wd:Q34740 AS ?taxonRank) . # Genus
  BIND(wd:Q756 AS ?higherParent) . # Plantae
  ?item wdt:P225 ?taxonName .
  ?item wdt:P105 ?taxonRank .
  ?item wdt:P171/wdt:P225 ?parentName .
  ?item wdt:P171/wdt:P105 ?parentRank .
  ?item (wdt:P171)* ?higherParent .
  hint:Prior hint:gearing "forward" .
}

(note the hint). The hint allows to control in which direction the path is traversed.
See also https://wiki.blazegraph.com/wiki/index.php/QueryHints

Since this is probably the only solution for this now (it's very hard to make optimizer always guess correctly which way to go) and upstream ticket is considered resolved for now, I'm resolving this too.