Conversation
…IR to support having a relation with the empty tuple in it for empty antecedent rules
|
If you have a rule with empty antecedent and multiple atoms in the consequent, I don't think it's correct to count the number of rows in each of those atoms' tables separately. I think you have to evaluate the consequent as a conjunctive query and check whether the results of that query are nonempty. For example, you could define a graph that must always contain at least one triangle. That would be a rule with an empty antecedent, and a 3-atom consequent. |
|
Reflecting upon a call with @olynch on Monday, the example rule
To express all triangles we need at least the three join variables So as long as (1) is indeed the case, the counting approach is an alternative option. Anyways, I continue with the anti join approach in here but still I'm interested to know how the example from @ept works out with the compiler. |
Empty Antecedent Rules
Issue
Rules can have an empty
consequents, in which case they assert nothing and canbe ignored. However, rules can also have an empty
antecedents, in which casethey demand the consequents to evaluate to true. That means the conjunctive
query defined by the
consequentsmust be non-empty.Solution
Antijoin Approach
Whenever there is an
$S$ . This results in as many unit tuples as there$S$ (let's say $n$ rows). $n$ is usually zero or one row because
Atomwith no variable binding at all (neither row id norvalues) the FLIR expects a 0-tuple (a tuple with 0 fields; the unit tuple
hereafter). We can translate that into projecting away all columns of the
Atom's underlying relationare rows in
rules of this kind often operate on
Atoms (in the consequent) which contain atmost one row.
For the antijoin approach to work the left input relation$R$ (given by the
empty antecedent) must somehow come into existence, as there is no table to
provide it. The obvious candidate is a relation consisting of only the unit
tuple, as any quantification over the unit tuple is true by definition (its a
neutral element). An empty antecedent then signals such a "neutral relation".
Such a "unit relation" can now be constructed using the new
ConstantExprleaf.The upside of this approach is that it aligns nicely with non-empty antecedent
rules and requires no special treatment except for the creation of a neutral
relation.
A downside of this rule checking is that for consequents with more than one
Atomwe cannot tell the user whichAtoms are non-empty.The Counting Approach
Another query shape ensuring that every consequent's atom's underlying relation
is non-empty, is to count its entries with a
count()aggregation.The upside is that we can tell which base table violates the non-emptiness$n$ consequent atoms turns into $n$ queries which all$> 0$ .
assertion. The downside is it requires aggregation (which isn't a thing yet in
coln-query's IR; but we want to have it at some point anyways). Furthermore, an
empty antecedent rule with
need checking if their output is