BD2 Text and Sol Draft
BD2 Text and Sol Draft
C. XML (9 p.)
<!ELEMENT Kindergarten ( Dish+, Child+ )>
<!ELEMENT Dish ( Name, Ingredient+, EthicalIndications, NutritionFacts … )>
<!ELEMENT Child ( Name, BirthDate, EatenFood*, Classroom… )>
<!ELEMENT EatenFood ( Ingredient, DateOfFirstIngestion )>
The DTD above describes the composition of the dishes served to the youngest babies in the nursery of a kindergarten and
the list of the ingredients that each baby has already eaten at least once at home, based on its parents’ indications. The
purpose of this data structure is to avoid that a baby eats any food for the first time at school rather than under parental
supervision. Unspecified elements only contain PCData or are immaterial to the assignment. Extract in XQuery:
(3 p.) 1. The baby who tasted broccoli at the youngest age (expressed in days). For readability and simplicity of notation, an
expression like xf:get-days-from-dayTimeDuration(op:subtract-dates(xs:date($d1),xs:date($d2))) can be implied by a simple $d1 – $d2 .
(6 p.) 2. For each dish in the menu, list the names of the children who are not allowed to eat it (yet).
Remark: it could be specified also as a BEFORE TRIGGER. In such a case the WHEN condition can be omitted in the next
trigger. In the above case the row is inserted in the table, otherwise no data are stored for invalid requests. The choice
depends on the application requirements.
It could be combined also with the next trigger, using an IF command.
Dump, b(t1), u(t1,o1,a1,b1), d(t1,o2,b2), b(t2), b(t3), r(t1), i(t3,o3,a3), c(t3), ckpt(t1,t2), b(t4), b(t5), b(t6),
u(t4,o4,a4,b4), p(t4), la(t1), u(t2,o2,b5,a5), r(t2), lc(t2), c(t4), i(t5,o6,a6), d(t6,o6,b6), r(t5), failure
Step 2: update UNDO/REDO according to the begin/commit/abort commands after the checkpoint
b(t4), b(t5), b(t6) These three transactions need to be UNDONE UNDO={ t1,t2,t4,t5,t6 } REDO={ }
la(t1) t1 remains in the UNDONE set
r(t2) t2 is inserted in the READY set UNDO={ t1,t4,t5,t6 } REDO={ } READY={ t2 }
lc(t2) t2 needs to be REDONE UNDO={ t1,t4,t5,t6 } REDO={ t2 } READY={ }
c(t4) t4 needs to be REDONE UNDO={ t1,t5,t6 } REDO={ t2,t4 } READY={ }
r(t5) t5 is inserted in the READY set UNDO={ t1,t6 } REDO={ t2,t4 } READY={ t5 }
t5 is in doubt – it will receive a COMMIT answer from the TM, so it needs to be REDONE
UNDO={ t1,t6 } REDO={ t2,t4,t5 }
Notice that t3 commited before the CKPT and therefore does not need to be redone/undone
FOR $d in doc(..)/Kindergarten/Dish
LET $i := $d/Ingredient
RETURN
<DISH> {$d/name/text()} </DISH>
<LISTCHILDRENNOTALLOWED>
{FOR $c in doc(..)/Kindergarten/Child
WHERE count($i) <> count (FOR $j in $i RETURN $c/EatenFood[Ingredient=$j])
RETURN <CHILD>{$c/name}</CHILD>}
</LISTCHILDRENNOTALLOWED>
D
The merge-scan apploach is trivially linear in the size of the joined tables and constant w.r.t. the value of σ:
p1: 125K + 75K = 200K
p2: The minimum cost (if σ = 0%) is 4 (a simple descent in the B+ index).
Otherwise the tuples in the interval are 2M ∙ σ
4 + blocks in the index + #ofTuples ∙ ( 1 the pointer + 1 the lookup + 1 the block of S ) =
4 + 2M ∙ σ / ( 2M / 50K ) + 2M ∙ σ ∙ 3 = 4 + σ ∙ ( 50K + 6M ) ~= σ ∙ 6.05 M
One break even for σ = 30,25 %