April 24, 2019
How does the input data relate to a query output.
|
|
Why is ⟨1⟩ in πA(R⋈S)?
|
|
... but that's not the only reason
|
|
Why is ⟨1⟩ in πA(R⋈S)?
{R1,S1}, {R1,S2}, {R2,S3}
Witness: Any subset of the original database that still produces the same result.
(Generally we only want 'minimal' witnesses)
|
|
How is ⟨1⟩ derived in πA(R⋈S)?
(R1⋈S1)⊕(R1⋈S2)⊕(R2⋈S3)
[head] :- [body]
Q(A):− R(A,B),S(B,C)
like SELECT A FROM R NATURAL JOIN S
Stop thinking about relations as collections of records, and instead think of them as collections of facts
R | A | B |
---|---|---|
1 | 1 | 2 |
2 | 1 | 3 |
3 | 2 | 3 |
4 | 2 | 4 |
The fact R(1,2) is true.
The fact R(2,1) is false (or unknown).
A table contains all facts that are provably true.
Q(A):− R(A,B),S(B,C)
For any A, the fact Q(A) is true if...∀A:(∃B,C:R(A,B)∧S(B,C))→Q(A)
Q(A):− R(A,B),S(B,C) Q(A):− R(A,B),R(B,C)
Treat multiple rules as a disjunction.
(Q(A) is true if any rule is satisfied)
[[A>B]] | A | B |
---|---|---|
1 | 0 | |
2 | 0 | |
3 | 0 | |
... | ||
2 | 1 | |
... |
Relations are Sets of Facts. We can have a relation consisting of all pairs A,B where A is bigger.
Safety Property: Every variable must appear in at least one finite relation in a rule body.
Recursive datalog: The body can reference the head atom
Q(A,B):− R(A,B) Q(A,C):− Q(A,B),R(B,C)(~Dijkstra's algorithm)
... is like a very large number of queries with no head variables
...
The fact Q(1,1) is true if ∃B:R(1,B)∧S(B,1)
Think of the relation as a function from potential facts to their truthiness.
R | A | B | |
---|---|---|---|
1 | 1 | 2 | → T |
2 | 1 | 3 | → T |
3 | 2 | 3 | → T |
4 | 2 | 4 | → T |
5 | 1 | 1 | → F |
6 | ... | → F |
Every row not explicitly listed is mapped to False