I found a cursed query:
My initial query finding 129112 results (where only 1 row was expected):
SELECT (COUNT(?item) AS ?count) ?type WHERE {VALUES (?item) { (wd:Q1018063) (wd:Q1026869) } .?item wdt:P31 ?type .}GROUP BY ?type
The simplified demonstration of the problem suggested by @Lucas_Werkmeister_WMDE:
SELECT ?type (COUNT(*) AS ?count) WHERE { VALUES ?item { <a> <b> } ?item wdt:P1622 ?type. } GROUP BY ?type
Try it! Current results:
| type | count |
|---|---|
| wd:Q14565199 | 0 |
| wd:Q14565199 | 0 |
| wd:Q13196750 | 0 |
| wd:Q13196750 | 0 |
The problem doesn’t occur with only one value in the VALUES clause (wild guess: an optimizer turns that into a BIND(), avoiding the bug), but as soon as there is more than one value (note that <a> and <b> aren’t values we actually have any triples for), the query service seems to behave as if it first takes all the possible values of ?type (independent of ?item) and then counts the ?item wdt:P1622 ?type triples for each of of those ?types and each ?item from the VALUES clause. Compare:
SELECT ?type (COUNT(*) AS ?count) WHERE { VALUES ?item { wd:Q183 wd:Q142 wd:Q145 } # Germany, France, United Kingdom ?item wdt:P1622 ?type. # driving side } GROUP BY ?type
Try it! Current results:
| type | count |
|---|---|
| wd:Q14565199 | 1 |
| wd:Q14565199 | 1 |
| wd:Q14565199 | 0 |
| wd:Q13196750 | 0 |
| wd:Q13196750 | 0 |
| wd:Q13196750 | 1 |