25-Comp-B3 Data Bases and File Systems · December 2015
Nivaar worked solution (AI-drafted; not reviewed by a licensed engineer) · Last updated
Question text not reproduced: the examination questions are © Engineers and Geoscientists BC. Open the official past paper (linked at the top of this page) to read the question, then follow the worked solution below.
Part (a) — why only one clustered index per file. A clustered index is one whose search key order matches the PHYSICAL storage order of the underlying data records — the records themselves are sorted on disk (or grouped into pages) according to that key. A file's records can only be laid out on disk in ONE physical order at a time, so at most one index can have this "index order = storage order" property; every other index on the same file must be unclustered (its key order necessarily disagrees with the one physical order actually used). Trying to cluster on two different keys simultaneously would require the data to be physically sorted two different ways at once, which is impossible for a single copy of the file.
Part (b) — why a secondary (unclustered) index must be dense. A sparse index stores only one entry per DATA PAGE (not per record), which only works if the index key's order matches the physical page order — the index can point at a page and rely on the target record being found by scanning nearby records that are known to be adjacent to it. A secondary index's key is, by definition, NOT the clustering key, so records with nearby secondary-key values are scattered across unrelated, non-adjacent data pages. A sparse secondary entry pointing at "roughly the right page" would give no way to locate the actual matching record(s) among all the OTHER pages holding the rest of that key range. A secondary index must therefore be dense: it needs one entry per distinct search-key value (pointing directly at every matching record, or record group), because there is no physical adjacency left to exploit.
Given (c). An order-3 B+-tree (2 keys/3 pointers per node) already containing the 6 leaf-level keys 1, 10, 15, 17, 19, 20 under root [16] → [8], [19] → leaves [1], [10,15], [17], [19,20].
[Figure not reproduced: Question 2(c) — given starting B+-tree. See the official exam paper.]
Find. The tree after inserting 3, 5, 11, 16, 18, 21 one at a time, in that order.
Approach. Same order-3 insertion algorithm as Question 1(c): descend to the target leaf, insert in sorted position, split-and-copy-up a 3-key leaf, split-and-move-up a 3-key internal node. every intermediate leaf state is nonetheless listed in the results table).
| Stage | Leaf chain (left→right) |
|---|---|
| Given | [1] ↔ [10,15] ↔ [17] ↔ [19,20] |
| After 3 | [1,3] ↔ [10,15] ↔ [17] ↔ [19,20] |
| After 5 | [1,3] ↔ [5] ↔ [10,15] ↔ [17] ↔ [19,20] |
| After 11 (root splits) | [1,3] ↔ [5] ↔ [10,11] ↔ [15] ↔ [17] ↔ [19,20] |
| After 16 | [1,3] ↔ [5] ↔ [10,11] ↔ [15] ↔ [16,17] ↔ [19,20] |
| After 18 | [1,3] ↔ [5] ↔ [10,11] ↔ [15] ↔ [16,17] ↔ [18] ↔ [19,20] |
| After 21 (root splits again, final) | [1,3] ↔ [5] ↔ [10,11] ↔ [15] ↔ [16,17] ↔ [18] ↔ [19,20] ↔ [21] |