IITDBGroup / gprom

GProM is a middleware that adds support for provenance to database backends.
http://www.cs.iit.edu/%7edbgroup/research/gprom.php
Apache License 2.0
8 stars 5 forks source link

Datalog merging subqueries incorrect for rules with aggregation #89

Closed lordpretzel closed 1 year ago

lordpretzel commented 1 year ago

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.