给出两个Datalog程序P1, P2
我想检查P1
中是否包含P2
,即每个数据库D
,P1
的输出包含在P2
。
例如,P1
:
A(X,Y) :- a(X,Y)
和计划P2
:
A'(X,Y) :- a(X,Y), b(X,Y)
很明显,对于每个可能的数据库A' contained in A
,因为b(X,Y)
仅过滤来自a(X,Y)
的结果,因此包含。
是否有标准的Datalog实现在这种查询中返回true / false?
答案 0 :(得分:0)
您无法直接表达包含,但您可以创建一个谓词来验证它是否存在P1中不存在于P2中的任何元素,并且通过否定,您可以推断该集合是否包含在另一个集合中。
not_contain(X,Y) :- A(X,Y), not A'(X,Y) .
check_containment(C) :- count(not_containt(_,_), C) .
我假设您使用带有否定的数据记录。如果check_containment等于0,则表示P1
中包含P2
。
答案 1 :(得分:0)
1993年,Equivalence of datalog queries is undecidable论文Oded Shmueli指出这通常是不可能的:
It is shown that determining containment or equivalence of Datalog queries is
recursively unsolvable.
产生此结果的原因是规则可能是“递归的”(又称“不严格的”):
ancestor(X, Z) :- ancestor(X, Y), parent(Y, Z)
和递归使问题无法确定。
但是,可能会有数据记录的片段,请参见Query Containment for Highly Expressive Datalog Fragments