The best explanation I can offer is that the optimizer does weird things sometimes, especially with subqueries: in my experience, subqueries rarely bring the optimization I expect. However, named subqueries often perform a lot better (they run exactly once). This version of your query runs in less than a second:

PREFIX wp:      <http://vocabularies.wikipathways.org/wp#>
PREFIX dcterms:  <http://purl.org/dc/terms/>
PREFIX dc:      <http://purl.org/dc/elements/1.1/>
SELECT DISTINCT ?metabolite1Label ?metabolite2Label ?mass1 ?mass2 WITH {
  SELECT ?metabolite1 ?metabolite2 WHERE {
    ?pathwayItem wdt:P2410 "WP706";
                 wdt:P2888 ?pwIri.
    SERVICE <http://sparql.wikipathways.org/> {
      ?pathway dc:identifier ?pwIri.
      ?interaction rdf:type wp:Interaction;
                   wp:participants ?wpmb1, ?wpmb2;
                   dcterms:isPartOf ?pathway.
      FILTER (?wpmb1 != ?wpmb2)
      ?wpmb1 wp:bdbWikidata ?metabolite1.
      ?wpmb2 wp:bdbWikidata ?metabolite2.
    }
  }
} AS %metabolites WHERE {
  INCLUDE %metabolites.
  ?metabolite1 wdt:P2067 ?mass1.
  ?metabolite2 wdt:P2067 ?mass2.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Cheers,
Lucas

On 26.06.2017 21:58, Andra Waagmeester wrote:
I am puzzled by a pattern I am seeing in submitting nested SELECT statements to the WDQS. 
In cases where a federated query to the WDQS time out, it helps to include redundant SELECT statements for the same query to resolve. 

The following query does not resolve:
Inline image 1
source: https://gist.github.com/andrawaag/ba1b7d1b9adf06e9d45afa98c1d1e239 
results: http://tinyurl.com/ybl55tk4
When the lines 7 and 9 in the above example are duplicated, suddenly the query does resolve
Inline image 2
source: https://gist.github.com/andrawaag/7e2e793342011f66bb6a3ea7bb5a1326
results: http://tinyurl.com/y9mjkejo


What is the added value of a double SELECT (line 7,8 and line 10,11). Also the lines 5 and 9 had to be separated by a SELECT statement to be successful.

Is this an implementation issue, or am I doing something wrong?

kind regards,

Andra Waagmeester




_______________________________________________
Wikidata mailing list
Wikidata@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikidata