Ex. 1
Let R,S be respectively n+m- i m-ary relational signature symbols.
Consider a new operation ÷ in relational algebra:
[[R÷S]]={⟨a1,…,an⟩| for each ⟨b1,…,bm⟩∈[[S]] (⟨a1,…,an,b1,…,bm⟩∈[[R]])}.
Show that the operator ÷ is expressible in terms of the other operators of relational algebra. Give an expression of relational algebra that defines R÷S.
Ex. 2
Prove that with a suitable (natural) encoding of finite structures A as binary strings code(A), for every sentence φ of first order logic, the function
fφ:code(A)↦ if A⊨φ then 1 else 0
belongs to non-uniform AC0.
Ex. 3
Prove that fφ of the previous exercise, belongs to NC1.
Information In databases, an important optimization rule for relational algebra expressions tries to minimize the size of intermediate results obtained during query evaluation.
Ex. 4
Prove that the following problem is undecidable:
Data: a relational algebra expression E over a signature with a single binary symbol R and perhaps some other symbols.
Question: is |[[E]]|<|[[R]]|2 for every model?
Ex. 5
Relational algebra with total order can be constructed in two ways. Assume that ≤ is a total order on all elements that appear in tuples, and there are no constants in the signature.
The first way is to introduce, to every database, an additional table (formally, a view) LEQ with two columns, containing all tuples
⟨a,b⟩ for a,b in the active domain, such that a≤b. Then ordinary expressions of relational algebra can use LEQ
as any other table. Then we treat LEQ as part of the query syntax, and not as an ordinary table.
Another way is to keep the tables as they are, but extend the syntax and in the condition θ of selection σθ(E) allow inequalities of the form i≤j for i,j not larger than the number of columns in E. Semantics is obvious, e.g. [[σi≤j(E)]]={→a∈[[E]]:ai≤aj}.
Prove that the queries expressible in both formalisms are the same.
Ex. 6
Prove that semijoin is expressible in relational algebra, and define it using the other operators.
Ex. 7
Prove that expressions built of selection, projection, sum, difference and semijoin do not express all queries definable in relational algebra.
Ex. 8
Prove that every expression built of selection, projection, sum, difference and semijoin in a database where elements are natural numbers, can be computed in time O(nlogn), where n is the maximal number of tuples in relations.
Ex. 9
Prove that expressions built of projection, product, sum, difference and semijoin express all queries definable in relational algebra, provided there there are no constants in the signature.
Ex. 10
Prove that there is an expression built of selection, projection, sum, difference and semijoin, than defines the interestion of two relations.
Ex. 11
Prove that the following relational algebra operators are not expressible in terms of the others:
- Sum is not expressible by selection, projection, product and difference.
- Difference is not expressible by selection, projection, product and sum.
- The other cases are very easy.
Ex. 12
Consider two tables A i B with two columns each. The first one has nA rows.
Design an algorithm to calculate the relational algebra expression
A−π1,2(σ1=3(A×B)).
You should assume that the active domain consist of integers, and table rows are indexed by nonnegative integers.
The algorithm should use exactly one table of two columns and nA wierszy, and a few additional variables. Do not use pointers, recursion and other methods of implicit memory allocation.
Tables A and B are read-only, and you may assume that they are sorted.
Ex. 13
Let k∈N be a constant. Prove that if E is a relational algebra expression and the maximal number of columns in subexpressions of
E is k, then there is an agorithm to calculate the value of [[E]] in every structure A running in time O(nklogn), where n the size of the active domain of A.