Blazegraph's query optimizer orders operations in a way that leads to a timeout in some cases where disabling the optimizer returns a result within seconds.
Examples:
https://www.mediawiki.org/w/index.php?title=Wikibase/Indexing/SPARQL_Query_Examples&oldid=2033092#Aliases_of_properties_which_are_used_more_than_once
The query below currently works, though it had the problem before:
```
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX wikibase: <http://wikiba.se/ontology#>
SELECT DISTINCT ?result WHERE {
{
{ ?subject0 rdfs:label "United States"@en . } UNION { ?subject0 skos:altLabel "United States"@en . }
}
{
{ ?predicate1 rdfs:label "president"@en . } UNION { ?predicate1 skos:altLabel "president"@en . }
}
?predicate1 a wikibase:Property .
?predicate1 wikibase:directClaim ?directPredicate2 .
?subject0 ?directPredicate2 ?result .
}
```
This url helped us identify what problem caused the timeout. [[ http://wdqs-beta.wmflabs.org/bigdata/namespace/wdq/sparql?query=PREFIX+rdfs%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23%3E%0D%0APREFIX+skos%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F2004%2F02%2Fskos%2Fcore%23%3E%0D%0APREFIX+wikibase%3A+%3Chttp%3A%2F%2Fwikiba.se%2Fontology%23%3E%0D%0A%0D%0ASELECT+DISTINCT+%3Fresult+WHERE+{%0D%0A%09{+%0D%0A%09%09{+%3Fsubject0+rdfs%3Alabel+%22United+States%22%40en+.+}+UNION+{+%3Fsubject0+skos%3AaltLabel+%22United+States%22%40en+.+}%0D%0A%09}%0D%0A%09{%0D%0A%09%09{+%3Fpredicate1+rdfs%3Alabel+%22president%22%40en+.+}+UNION+{+%3Fpredicate1+skos%3AaltLabel+%22president%22%40en+.+}%0D%0A%09}%0D%0A%09%3Fpredicate1+a+wikibase%3AProperty+.%0D%0A%09%3Fpredicate1+wikibase%3AdirectClaim+%3FdirectPredicate2+.%0D%0A%09%3Fsubject0+%3FdirectPredicate2+%3Fresult+.%0D%0A}&explain | Blazegraph explain feature ]]
The query works with optimizer disabled:
```
PREFIX hint: <http://www.bigdata.com/queryHints#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX wikibase: <http://wikiba.se/ontology#>
SELECT DISTINCT ?result WHERE {
hint:Query hint:optimizer "None" .
{
{ ?subject0 rdfs:label "United States"@en . } UNION { ?subject0 skos:altLabel "United States"@en . }
}
{
{ ?predicate1 rdfs:label "president"@en . } UNION { ?predicate1 skos:altLabel "president"@en . }
}
?predicate1 a wikibase:Property .
?predicate1 wikibase:directClaim ?directPredicate2 .
?subject0 ?directPredicate2 ?result .
}
```