2018-02-28

Feb 28 In-Class Exercise Thread.

Post your solutions to the Feb 28 In-Class Exercise to this thread.
 
Best, Chris
Post your solutions to the Feb 28 In-Class Exercise to this thread. Best, Chris

-- Feb 28 In-Class Exercise Thread
Read in R into a buffer, since we have M=3. Then use each row in R to scan through table S. The first and second record would have a matching column with the first row of S, so concatenate the corresponding rows. Then the third row of R would join with the last row os table S, so concatenate them.
 
Table X
X(A, B, C, D, E)
a1 b1 c1 d1 e2
a2 b2 c1 d1 e2
a2 b3 c2 d1 e3
(Edited: 2018-02-28)
Read in R into a buffer, since we have M=3. Then use each row in R to scan through table S. The first and second record would have a matching column with the first row of S, so concatenate the corresponding rows. Then the third row of R would join with the last row os table S, so concatenate them. Table X X(A, B, C, D, E) {| |- | a1 || b1 || c1 || d1 || e2 |- | a2 || b2 || c1 || d1 || e2 |- | a2 || b3 || c2 || d1 || e3 |}

-- Feb 28 In-Class Exercise Thread
 S x R
 Table T (A, B, C, D, E)
 
 We have M = 3. Use first two memory blocks to read in first two columns of R, then read in only the first column of S, then concatenate from there. 
 
 A  B  C  D  E 
 a1 b1 c1 d1 e2 
 a2 b2 c1 d1 e2 
 a2 b3 c2 d1 e3 
(Edited: 2018-02-28)
S x R Table T (A, B, C, D, E) We have M = 3. Use first two memory blocks to read in first two columns of R, then read in only the first column of S, then concatenate from there. A B C D E a1 b1 c1 d1 e2 a2 b2 c1 d1 e2 a2 b3 c2 d1 e3

-- Feb 28 In-Class Exercise Thread
Read R1:=R(a1, b1, c1)
Read S1:=S(c1, d1, e2)
R1.C=S1.C, so add (a1, b1, c1, d1, e2) to results
Read S2:=S(c2, d1, e3)
R1.C<>S2.C, so ignore
Discard R1
Read R2:=R(a2, b1, c1)
R2.C=S1.C, so add (a2, b2, c1, d1, e1) to results
R2.C<>S2.C, so ignore
Discard R2
Read R3:=R(a2, b3, c2)
R3.C<>S1.C, so ignore
R3.C=S2.C, so add (a2, b3, c2, d1, e3) to results
(Edited: 2018-02-28)
Read R1:=R(a1, b1, c1) Read S1:=S(c1, d1, e2) R1.C=S1.C, so add (a1, b1, c1, d1, e2) to results Read S2:=S(c2, d1, e3) R1.C<>S2.C, so ignore Discard R1 Read R2:=R(a2, b1, c1) R2.C=S1.C, so add (a2, b2, c1, d1, e1) to results R2.C<>S2.C, so ignore Discard R2 Read R3:=R(a2, b3, c2) R3.C<>S1.C, so ignore R3.C=S2.C, so add (a2, b3, c2, d1, e3) to results

-- Feb 28 In-Class Exercise Thread
Elena Pearson
R natural join S = T
T(A,B,C,D,E)
(a1,b1,c1,d1,e2)
(a2,b2,c1,d1,e2)
(a2,b3,c2,d1,e3)
Use 2 blocks to read in table R. Concatenate these tuples with the tuples in table S. We only need 2 blocks so we can do this in M-1.
(Edited: 2018-02-28)
Elena Pearson R natural join S = T T(A,B,C,D,E) (a1,b1,c1,d1,e2) (a2,b2,c1,d1,e2) (a2,b3,c2,d1,e3) Use 2 blocks to read in table R. Concatenate these tuples with the tuples in table S. We only need 2 blocks so we can do this in M-1.

-- Feb 28 In-Class Exercise Thread
With m = 3 blocks. We can read all of table R into two buffer and the remaining block can be used to scan table S. Then we can cycle through and concatenate the tuples.
a1 b1 c1 d1 e2
a2 b2 c1 d1 e2
a2 b3 c2 d1 e3
(Edited: 2018-02-28)
With m = 3 blocks. We can read all of table R into two buffer and the remaining block can be used to scan table S. Then we can cycle through and concatenate the tuples. a1 b1 c1 d1 e2 a2 b2 c1 d1 e2 a2 b3 c2 d1 e3

-- Feb 28 In-Class Exercise Thread
Resource Description for CS157B Inclass Feb 28.jpg
((resource:CS157B Inclass Feb 28.jpg|Resource Description for CS157B Inclass Feb 28.jpg))

-- Feb 28 In-Class Exercise Thread
 M=3 and each block can hold two records. table R in main memory  
    [a1,b1,c1]
    [a2,b2,c1]
    [a2,b3,c2]
 Then Concatenate tuples of Table S in main memory  
  a1	b1	c1	d1	e2
  a2	b2	c1	d1	e2
  a2	b3	c2	d1	e3
(Edited: 2018-02-28)
M=3 and each block can hold two records. table R in main memory [a1,b1,c1] [a2,b2,c1] [a2,b3,c2] Then Concatenate tuples of Table S in main memory a1 b1 c1 d1 e2 a2 b2 c1 d1 e2 a2 b3 c2 d1 e3

-- Feb 28 In-Class Exercise Thread
Table R fits into at most M-1 buffers, so read it entirely into main memory. M=3, and there are 3 records, so this fits into 2 blocks. table in main memory = {
    (a1,b1,c1),
    (a2,b2,c1),
    (a2,b3,c2)
}
Concatenate tuples of Table S to the tuples of the table in main memory. table in main memory = {
    (a1,b1,c1,d1,e2),
    (a2,b2,c1,d1,e2),
    (a2,b3,c2,d1,e3)
}
(Edited: 2018-02-28)
Table R fits into at most M-1 buffers, so read it entirely into main memory. M=3, and there are 3 records, so this fits into 2 blocks. table in main memory = { (a1,b1,c1), (a2,b2,c1), (a2,b3,c2) } Concatenate tuples of Table S to the tuples of the table in main memory. table in main memory = { (a1,b1,c1,d1,e2), (a2,b2,c1,d1,e2), (a2,b3,c2,d1,e3) }

-- Feb 28 In-Class Exercise Thread
 Read S into buffers because S fits in 1 buffer and the other buffer can be used for scanning R
 (c1, d1, e2)
 (c2, d1, e3)
 Concatenate with tuples in R
 (c1, d1, e2, a1, b1)
 (c1, d1, e2, a2, b2)
 (c2, d1, e3, a2, b3)
(Edited: 2018-02-28)
Read S into buffers because S fits in 1 buffer and the other buffer can be used for scanning R (c1, d1, e2) (c2, d1, e3) Concatenate with tuples in R (c1, d1, e2, a1, b1) (c1, d1, e2, a2, b2) (c2, d1, e3, a2, b3)
[ Next ]
X