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 codegen - WHY-NOT adom not added where needed #30

Open lordpretzel opened 6 years ago

lordpretzel commented 6 years ago

If using sqlcodegen dl, the unsafe rules generated by WHY-NOT are not fixed by adding domain predicates.

Q(X) :- hop(X,Y). WHYNOT(Q('a')).

returns

move((((((('notREL_' || 'HOP_WON') || '(') || 'a') || ',') || V0) || ')'),(((((('REL_' || 'HOP_LOST') || '(') || 'a') || ',') || V0) || ')')) :- RHOP_LOST(a,V0).
move((((('notREL_' || 'Q_WON') || '(') || 'a') || ')'),(((('REL_' || 'Q_LOST') || '(') || 'a') || ')')) :- r0_WL(a,Y,FALSE).
move((((('REL_' || 'Q_LOST') || '(') || 'a') || ')'),(((((('RULE_' || '0_WON') || '(') || 'a') || ',') || Y) || ')')) :- r0_WL(a,Y,FALSE).
move((((((('RULE_' || '0_WON') || '(') || 'a') || ',') || Y) || ')'),(((((('GOAL_' || '0_0_LOST') || '(') || 'a') || ',') || Y) || ')')) :- r0_WL(a,Y,FALSE).
move((((((('GOAL_' || '0_0_LOST') || '(') || 'a') || ',') || Y) || ')'),(((((('notREL_' || 'HOP_WON') || '(') || 'a') || ',') || Y) || ')')) :- r0_WL(a,Y,FALSE).
move((((((('notREL_' || 'HOP_WON') || '(') || 'a') || ',') || Y) || ')'),(((((('REL_' || 'HOP_LOST') || '(') || 'a') || ',') || Y) || ')')) :- r0_WL(a,Y,FALSE).
RHOP_LOST_nonlinked(a,V0) :- not RHOP_WON_nonlinked(a,V0).
RHOP_WON_nonlinked(a,V0) :- HOP(a,V0).
RQ_LOST_nonlinked(a) :- not RQ_WON_nonlinked(a).
RQ_WON_nonlinked(a) :- r0_WL_nonlinked_chkpos(a,Y,TRUE).
RHOP_LOST(a,V1) :- r0_WL(a,V1,FALSE),RHOP_LOST_nonlinked(a,V1).
r0_WL_nonlinked(a,Y,FALSE) :- RHOP_LOST_nonlinked(a,Y),RQ_LOST_nonlinked(a).
r0_WL_nonlinked_chkpos(a,Y,TRUE) :- RHOP_WON_nonlinked(a,Y).
r0_WL(a,Y,FALSE) :- r0_WL_nonlinked(a,Y,FALSE).

For instance, RHOP_LOST_nonlinked(a,V0) :- not RHOP_WON_nonlinked(a,V0). is unsafe

Probably this is because we do this fix during the translation into relational algebra. We need to do this as a post processing step (e.g., done in translator dummy or as an optional step during WHY/WHYNOT rewriting).

lordpretzel commented 6 years ago

This only happens if no domain is provided by the user, e.g., the following works already:

Q(X) :- R(X,Y). WHYNOT(Q(2)). Q2(X) :- R(X,Y). Q2(X) :- R(Y,X). USERDOMAIN OF R.A IS Q2. USERDOMAIN OF R.B IS Q2.