You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Subquery with GROUP BY incorrectly propagates bindings — leads to inconsistent results #161
Description:
There is a bug in the Corese engine related to subqueries using GROUP BY variables combined with external bindings. Specifically, when a variable used in the GROUP BY clause is bound before the subquery, the query yields different results depending on the position of the triple pattern relative to the subquery.
🔍 Example
Query:
prefix ns: <http://ns.inria.fr/test/>
select * where {
?x ns:p ?y
{
select ?x (count(*) as ?c)
where {
?x ns:q ?z
} group by ?x
}
}
If the triple ?x ns:p ?y is placed before the subquery block, the result differs from the case where it is placed after the subquery — although the SPARQL semantics dictate that the result should be the same.
Cause:
The issue lies in the propagation of bindings to subqueries using GROUP BY. Specifically, the variable used in the GROUP BY clause (?x in this case) should not be passed as a bound variable to the subquery, as this affects its internal grouping logic.
Proposed Fix:
In class fr.inria.corese.kgram.core.Exp, update the method queryNodeList(ExpHandler h) with the following code:
voidqueryNodeList(ExpHandlerh) {
List<Node> selectList = h.getSelectNodeList();
List<Node> subSelectList = getQuery().getSelect();
if (h.isInSubScope()) {
List<Node> scopeList = getQuery().getBody().getTheNodes(h.copy());
for (Nodenode : scopeList) {
if (subSelectList.contains(node)) {
if (!contain(getQuery().getGroupBy(), node)) {
add(selectList, node);
}
}
}
} else {
for (Nodenode : subSelectList) {
if (!contain(getQuery().getGroupBy(), node)) {
add(selectList, node);
}
}
}
}
Trade-off:
This change may cause a minor performance degradation, as group-by variables are no longer optimized via direct binding injection. However, it ensures correctness and prevents logically inconsistent results.
⚠️ Regression warning:
After applying this fix, TestQuery1 > testLetQuery() fails with a StackOverflowError at Graph.java:1669. This may indicate a recursion or cyclic reference introduced indirectly by the fix.
Doublon de #17. Résolu dans Corese Next : dans le nouveau pipeline SPARQL (PR #565 / #611), l’évaluation des sous-requêtes s’exécute dans un scope isolé et la jointure avec les motifs englobants respecte la sémantique W3C indépendamment de l’ordre des clauses. Test de non-régression validé dans NextSparqlPipelineAggregateExecutorTest.
Activity
test: add regression tests for issues #264, #17 and #161
remiceres commentedon Sep 29, 2026
Doublon de #17. Résolu dans Corese Next : dans le nouveau pipeline SPARQL (PR #565 / #611), l’évaluation des sous-requêtes s’exécute dans un scope isolé et la jointure avec les motifs englobants respecte la sémantique W3C indépendamment de l’ordre des clauses. Test de non-régression validé dans
NextSparqlPipelineAggregateExecutorTest.