Reputation: 21
Consider a SPARQL aggregation query with a where
clause composed of only triple patterns and filter
statements.
Does the order of the triple patterns or the order of the filters
affect the results (not the performance)? I am quite convinced it doesn't affect the validity of the results. But maybe someone can clarify why? Also, does the order of the variables in the group by
affect the result's validity? I don't think so either but maybe someone can clarify why?
The following example is just for clarification; I am asking generally.
The query counts the number of people grouped by their eye color and country and applies a couple of filters
. The query contains only these four triple patterns (each line ending by a dot is a triple pattern, i.e., a triple with variables)
?p wdt:P26 ?human.
?p wdt:P27 ?country.
?human wdt:P31 wd:Q5.
?human wdt:P1340 ?eyeColor.
and these two filters
:
FILTER (?country != wd:Q142)
FILTER (?eyeColor != wd:Q17122705)
The WHERE
clause doesn't contain any OPTIONAL
, UNION
, MINUS
,... or any other constructor; only triple patterns and filters.
SELECT ?eyeColor (COUNT(?human) AS ?count) ?country
WHERE
{
?p wdt:P26 ?human.
?p wdt:P27 ?country.
?human wdt:P31 wd:Q5.
?human wdt:P1340 ?eyeColor.
FILTER (?country != wd:Q142)
FILTER (?eyeColor != wd:Q17122705)
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
GROUP BY ?eyeColor ?country
My question again: if we change the order of the six elements in the WHERE
clause in any way, does that affect the result (not only in this query but also for similar ones in terms of structure)? The same question about whether the order of the variables in the GROUP BY
might affect the results, for example GROUP BY ?country ?eyeColor
instead of GROUP BY ?eyeColor ?country
. Again, I am asking in general, not only for this case query.
Upvotes: 2
Views: 573
Reputation: 16700
No, the order does not change the results for tripe patterns and filters only.
All filters happen at the end of the {} block they are in (an optimizer may move them but must not change the result).
A number of triple patterns "subject predicate object" will result in the same results regardless of order.
SERVICE is not a triple pattern.
wikibase:label
is special to wikidata, not the SPARQL spec anyway.
Including any of the graph pattern operations like SERVICE or OPTIONAL.
See the SPARQL algebra the spec or sparql.org to see the algebra.
Upvotes: 3