Two-Phase-Locking (2PL) Transactions - database

I'm currently dealing with the 2-Phase-Lock Protocol considering the following schedule S:
S = R_3 D R_1 A W_2 A W_2 C R_3 B W_3 B R_1 B
Where R = Read, W = Write, {A, B, C} = objects and {1,2,3} = transactions.
Now I shall show that the 2PL can't be used for S. But I actually don't see why, I would set the Locks(L)/Unlocks(U) like:
L_3 D R_3 D U_3 D L_1 A R_1 A U_1 A L_2 C W_2 C U_2 C L_3 B R_3 B W_3 B U_3 B R_1 B
So, I used at maximum 1 L/U per Object of a Transaction. What I am doing wrong here?

I finally found out why I was wrong. It is correct that a transaction can perform at maximum 1 Lock/Unlock per object. But I was forgetting that after a transactions performed its first Unlock (doesn't matter on which object) it is not allowed to perform a Lock again at all, even on another object that has not been locked before.

Related

How to state that a class is related to ALL instances of another class via a property

Have two questions
Given classes A, B and object property p (A->B). How to say that for any a from A and any b from B a is mapped via property p to b (a p b)?
In other words A has property p and every instance of A is mapped to all instances of B via propery p.
Now we have 3 classes A, B, C and 2 properties p1 (A->B or domain A, range B) and p2 (B->C or domain B, range C).
How to say in Protege that for any a from A and any c from C there exists a b from B for which a p1 b and b p2 c?

How to find multiple minimal/canonical covers or rearrange them to find new ones

I have a relation and function dependencies as follows:
R = (A, B, C, D, E)
F = (A -> B C,
B C -> D,
A C -> D E)
Now I am going to compute the minimal/canonical cover using this video.
So firstly I check if I have singleton right-hand sides in my FDs. No I don't, so I have to split them up. I.e. A -> B C is split into A -> B and A -> C. Similarly for A C -> D E.
So now I have...
F = (A -> B,
A -> C,
B C -> D,
A C -> D,
A C -> E)
Secondly, I check if any FDs have more than 1 LHS attributes. If they do, I see if any one of them can be eliminated by checking if their closure contains the other element. If it does, then we don't need that other element.
So for B C -> D, B closure is B and C closure is C. None of the closures contain the other attribute so we cannot eliminate B C -> D.
So now we move to A C -> D. A closure is ABCDE, we can instantly see that A's closure contains C. So C is and extraneous attribute and can be removed so our new set of FDs is...
F = (A -> B,
A -> C,
B C -> D,
A -> D,
A C -> E)
So now we move to the last one: A C -> E, again, A's closure is ABCDE, which contains C so we can eliminate the C from the FD. So our set of FDs is now:
F = (A -> B,
A -> C,
B C -> D,
A -> D,
A -> E)
Lastly, we check if there are any redundant FDs. We do this by going through each FD, covering it up, and seeing if the closure of its LHS contains its RHS.
So for A -> B, we cover it up and compute A closure, which is ACDE which doesnt contain B so we cannot eliminate A -> B. We do this for all FDs and we end up seeing that we can only eliminate A -> D because when we cover A -> D up and compute A closure it contains D, so we don't need A -> D
So now our new set of FDs are:
F = (A -> B,
A -> C,
B C -> D,
A -> E)
Now my question is:
Is my final set of FDs the correct minimal/canonical cover? Can it be written in another way? Also, In the video, it says that multiple canonical covers can exist for a given set of functional dependencies. How can I discover these?
Thank you for your time.
For eg.
X→YZ
Y→XZ
Z→XY
check out this answer with more than one possibility of minimal set
1:
X→Y,
Y→Z,
Z→X
2:
Z→Y,
Y→X,
X→Z
I checked all your steps and your final set is correct.
That said, I'm not sure about the multiple covers thing. The only difference between minimal cover and canonical cover is that a canonical cover is "allowed" to have more than one attribute on the right hand side, whereas minimal cover is not [source]. In this (trivial) sense you could obviously write the same set FDs in a different way.
On the other hand, I don't know if there could be two different sets of minimal covers with the same closure. I would say it is impossible, but that's just my intuition and I don't have elements to back it up.

Decomposing into BCNF

Suppose R = {A,B,C,D}
And FD = C→D,C→A,B→C
I am supposed to find:
1. the key(s)
2. the NF it is in
3. the BCNF (if possible and if not in already)
So here's what I've got so far:
the key is B since it transitively determines C which determines D and A.
it is in 2NF since dependancies are on the whole key
R1 = {B,C} R2 = {C, A, D}
So here's where I have an issue. The mark scheme says to decompose R into AC, BC, and CD. But why wouldn't my answer be right? Am I saying the FD is C -> {A,D} and if so is this difference to C -> A and C -> D?
When you're asked to compute the minimum cover of R, you're usually expected to answer like this.
C -> D
C -> A
B -> C
When you're asked to elevate R to BCNF, you're usually expected to answer like this.
B C
C AD
If you're not using a standard textbook, I can't give you any suggestions. Questions and answers written by TAs (teaching assistants) are particularly hard to understand. Sometimes they're just wrong.

Equivalent of SSE unpacklo_ps/unpackhi_ps in AVX (for doubles)

In SSE, if I have a 128-bit register containing 4 floats i.e.
A = a b c d ('a','b','c','d' are floats and 'A' is a 128-bit SSE register)
and
B = e f g h
then if I want
C = a e b f
I can simply do:
C = _mm_unpacklo_ps(A,B);
Similarly if I want
D = c g d h
I can do:
D = _mm_unpackhi_ps(A,B);
If I have an AVX register containing doubles, is it possible to do the same with a single instruction?
Based on how these intrinsics work, I know that I can't use _mm256_unpacklo_pd(), _mm256_shuffle_pd(), _mm256_permute2f128_pd() or _mm256_blend_pd(). Is there any instruction apart from these that I can use or do I have to use a combination of the above instructions?
One way that I can think of is the following:
A1 = _mm256_unpacklo_pd(A,B);
A2 = _mm256_unpackhi_pd(A,B);
C = _mm256_permute2f128_pd(A1,A2,0x20);
D = _mm256_permute2f128_pd(A1,A2,0x31);
If anyone has a better solution, please do post below.

Context Free pumping lemma

Is the following language context free?
L = {a^i b^k c^r d^s | i+s = k+r, i,k,r,s >= 0}
I've tried to come up with a context free grammar to generate this but I can not, so I'm assuming its not context free. As for my proof through contradiction:
Assume that L is context free,
Let p be the constant given by the pumping lemma,
Choose string S = a^p b^p c^p d^p where S = uvwxy
As |vwx| <= p, then at most vwx can contain two distinct symbols:
case a) vwx contains only a single type of symbol, therefore uv^2wx^2y will result in i+s != k+r
case b) vwx contains two types of symbols:
i) vwx is composed of b's and c's, therefore uv^2wx^2y will result in i+s != k+r
Now my problem is that if vwx is composed of either a's and b's, or c's and d's, then pumping them won't necessary break the language as i and k or s and r could increase in unison resulting in i+s == k+r.
Am I doing something wrong or is this a context free language?
I can't come up with a CFG to generate that particular language at the top of my head either, but we know that a language is context free iff some pushdown automata recognizes it.
Designing such a PDA won't be too difficult. Some ideas to get you started:
we know i+s=k+r. Equivalently, i-k-r+s = 0 (I wrote it in that order since that is the order in they appear). The crux of the problem is deciding what to do with the stack if (k+r)>i.
If you aren't familiar with PDA's or cannot use them to answer the problem, at least you know now that it is Context Free.
Good luck!
Here is a grammar that accepts this language:
A -> aAd
A -> B
A -> C
B -> aBc
B -> D
C -> bCd
C -> D
D -> bDc
D -> ε

Resources