CS157a
Chris Pollett
Oct 25, 2023
A|B --- 1|2 3|4 1|2 1|2then `delta(R)` is
A|B --- 1|2 3|4
A|B|C ----- 0|1|2 0|1|2 3|4|5Then the result of `pi_{A, B+C->X}(R)` is
A|X --- 0|3 0|3 3|9
Give the relational algebra for the following queries. Assume we have relations Employee(eid, fname, lname, address, birth_date, salary), WorksOn(emp_id, proj_id, hours), and Project(pid, proj_name, manager_id).
Post your solutions to the Oct 25 In-Class Exercise Thread.
A|B --- 1|2 3|4then `R(1,2)` and `R(3,4)` are true atoms and `R(1,1)` is false. `R(1,z)` will return true if `z=2`, and otherwise, return false.
LongMovie(t,y) <- Movies(t,y,l,g,s,p) AND l ≥ 100is an example Datalog rule
LongMovie(t,y) <- Movies(t,y,l,_,_,_) AND l ≥ 100
LongMovie(t,y) <- Movies(t,y,l,_,_,_) , l ≥ 100
Father("bob", "tony") <-. //notice this rule has an empty body. // We view such a rule as a fact. Sometimes we just write: // Father("bob", "tony"). Father("tony", "john") <-. Ancestor(x,y) <- Father(x, y). Ancestor(x,z) <- Father(x, y), Father(y,z).
Ancestor(x,z) <- Father(x, y), Ancestor(y,z).This would be a valid Prolog rule, but we don't usually allow a predicate to appear on both sides of a rule in Datalog.
P(x,y) <- Q(x,z), NOT R(w,x,y), x < yis not safe because of how `y` occurs and how `w` occurs.
A|B --- 1|2 1|2and `S(B,C)` is given by
B|C --- 2|3 4|5 4|5then we can compute `H` as
1|3 1|3by treating the two rows of `R` as distinct when trying to satisfy the clause.