The Databases Course
Exercise No. 10
Datalog and Concurrency Control
Due on February 1st by midnight
This is the only exercise about the two important subjects in the title. In order to encourage you to do it, and to help you improve your final exercises grade, anyone who submits this exercise will get an automatic bonus of four points.
- Given a binary relation child-of(x,y) meaning that x is a child of y, express same-gen(x,y) which is true when x and y are of the same generation (i.e. x and y have a common ancestor which is the same number of generations away from both of them).
- Given a directed graph G represented as a binary relation G(x,y), compute the vertices of G odd-vertex(v) which have a cycle of odd length passing through them.
- Given a directed graph G together with colors for its edges represented as a relation G(x,y,col) which means that the edge from vertex x to vertex y has color col, compute all paths 2-col-paths(x,y) such that there is a path from x to y which involves edges from exactly two colors.
- Prove that any query in relational algebra can be expressed as a datalog program (possibly with negation). You may assume that comparison relations such as =(x,y) and >(x,y) are given.
- Describe the set of relational algebra queries that can be expressed by datalog programs without negation. Prove your answer.
T1:LOCK(A), T2:LOCK(B), T1:LOCK(C), T1:UNLOCK(A), T3:LOCK(A), T1:UNLOCK(C), T2:UNLOCK(B), T3:UNLOCK(A), T4:LOCK(A), T4:LOCK(C), T4:UNLOCK(A), T2:LOCK(A), T2:UNLOCK(A), T4: UNLOCK(C).
- Build the schedule graph of this schedule.
- Give an equivalent serial schedule.
- Add a single LOCK X, UNLOCK X pair to this schedule that will cause it to be unserializable.
- Why might this be preferable over allowing only write locks? Illustrate your answer with an example.
- Does a transaction which only reads a certain item and doesn't write it really need to take a read lock on the item? Illustrate your answer with an example.