Our optimization for merging subqueries by substituting IDB predicates in a rule's body with the bodies of the rules defining the IDB predicate can change the semantics of the query if the IDB predicate appears in the body of a rule with aggregation. For rules with aggregation we should only substitute if the this does not change the number of assignments for the rule body, i.e., the multiplicity of aggregation inputs may change. For example, if R.X is not a key, then this query
Q(X,count(1)) :- Q1(X).
Q1(X) :- R(X,Y).
is not equivalent to this query
Q(X, count(1)) :- R(X,Y).
The safety condition is that if Q1's head variable imply all the body variables, then it is safe to substitute.
Our optimization for merging subqueries by substituting IDB predicates in a rule's body with the bodies of the rules defining the IDB predicate can change the semantics of the query if the IDB predicate appears in the body of a rule with aggregation. For rules with aggregation we should only substitute if the this does not change the number of assignments for the rule body, i.e., the multiplicity of aggregation inputs may change. For example, if
R.X
is not a key, then this queryis not equivalent to this query
The safety condition is that if
Q1
's head variable imply all the body variables, then it is safe to substitute.