sample solutions - Birkbeck College

79 downloads 202 Views 89KB Size Report
A set of transactions is serialisable if they behave as if they had been run serially, that is ... An example of non-serialisable execution is two transactions running ...
Database Management - 2011 Model Answers

1.

a. A data model should comprise a structural part, an integrity part and a manipulative part. The relational model provides standard definitions for all three parts, whereas the entity-relationship model has no standardised manipulative part. [5] A weak entity type in the entity-relationship model is an entity type that cannot exist independently of its associated owner or identifying entity type. When translating from the entity-relationship model to the relational model, a weak entity type is represented by the primary key of its owner type, its discriminator and its other attributes. [6] [11 marks]

b. The OUTER JOIN operator in SQL allows rows from one table that would be excluded in a normal join because they don’t match rows in the other table to be included in the join, padded with null values. The LEFT OUTER JOIN includes rows from the left table that do not join, the RIGHT OUTER JOIN includes those from the right table, and the FULL OUTER JOIN includes rows from both that do not join. [6] The join of R and S will have at most m tuples in it. [1] Because B is a foreign key referencing A, every non-null B-value must appear as an A-value in R. However, if a B-value in S is null, it will not match any tuple in R and R RIGHT OUTER JOIN S will produce a different result to R JOIN S. (The original question was incorrect in stating that they would return the same result—I had overlooked null values.) [4] [11 marks]

1

Page 2 of 5 c. A set of transactions is serialisable if they behave as if they had been run serially, that is, the effect of running them concurrently is the same as that when running them serially. [2] An example of non-serialisable execution is two transactions running concurrently and booking the same seat on a flight. The sequence in time might be as follows: 1. Transaction 1 finds seat 22A empty. 2. Transaction 2 finds seat 22A empty. 3. Transaction 1 books seat 22A. 4. Transaction 2 books seat 22A. [4] One mechanism is locking. [1] The acronym ACID stands for: atomicity, consistency, isolation and durability. [4] [11 marks] [Total 33 marks]

c Birkbeck College 2010

COIY028U

CONTINUED

Page 3 of 5 2.

a.

i. A key for Stocks is IS. This can be found by applying the closure algorithm. We can add D to IS + using S → D, we can add B using I → B, we can add Q using IS → Q, and can add O using B → O. [3] ii. InvestsWith(I,B,O) would not be good database design because, for example, the office of a broker would be repeated for every investor who invests with the broker. Also we could not store the office of a broker who has no investors because the primary key cannot be null. [4] iii. A 3NF decomposition of Stocks is (S, D), (I, B), (I, S, Q) and (B, O). [4] [11 marks]

b. A decomposition being lossless ensures that we can recover the original information after decomposition. A decomposition being dependency-preserving ensures that just be checking that the projected FDs in the decomposed relations are satisfied ensures that all the original FDs are satisfied. [3] As an example of a decomposition that is not lossless consider a relation schema (child, mother, f ather) and a relation over this schema with tuples (a, b, c) and (d, b, e). The FDs mother → child and mother → f ather do not hold, and the decomposition into (child, mother) and (mother, f ather) is lossy. When we join the projected tuples we get additional tuples (a, b, e) and (d, b, c). [4] As an example of a decomposition that is not dependency-preserving consider the relation schemas (theatre, city) and (theatre, f ilm) along with the FDs theatre → city and f ilm city → theatre. There could be relations for the two schemas that satisfy the first FD but when joined do not satisfy the second. [4] [11 marks]

c.

i. Referential integrity is the requirement that values for an attribute in one relation also appear as values in another relation. [2] ii. Data independence is the ability for the representation of data to be changed at one level without the change affecting how the data is retrieved at higher levels. [2]

c Birkbeck College 2010

COIY028U

TURN OVER

Page 4 of 5 iii. Entity integrity is the requirement that primary key values in a relation should not contain null values. [2] iv. Participation constraint is a constraint in the ER model that specifies whether or not every entity in an entity set must participate in a given relationship set. Participation can be optional (partial) or mandatory (total). [3] v. First normal form is the requirement that all values in relations be atomic as far as queries are concerned. [2] [11 marks] [Total 33 marks]

c Birkbeck College 2010

COIY028U

CONTINUED

Page 5 of 5 3.

a. Three-valued logic is a form of logic involving the truth values true, false and unknown. It is necessary because of conditions (predicates) involving null values which represent unknown values. [2] “spouse=‘Joe”’

“age < 50”

“not(spouse=‘Joe’) or age < 50”

true

true

true

true

false

false

true

unknown

unknown

false

true

true

false

false

true

false

unknown

true

unknown

true

true

unknown

false

unknown

unknown

unknown

unknown

[9]

[11 marks]

b. Views are useful because they provide an additional layer of abstraction above the logical model of a database and thereby isolate users from changes at lower levels. They can also be used to restrict access to parts of a database to only appropriate groups of users. [3] An SQL view is updatable if the query defining the view satisfies the following: • The from clause has only one database relation. • The select clause contains only attribute names of the relation (no expressions, aggregates, or distinct). • Any attribute not listed in the select clause can be set to null. • There is no group by or having clause. [4] If a view is defined as the join of two relations where the join attributes do not appear in the view, then an insertion of a tuple in the view might result in tuples being inserted into the base relations such that the inserted view tuple no longer appears in the view. [4] [11 marks]

c Birkbeck College 2010

COIY028U

TURN OVER

Page 6 of 5 c. XML represents data by a self-describing tree structure, that is, the “schema” is stored along with the nodes of the tree. Nodes can be nested to an arbitrary level and nodes of the same “type” can have different structures in different parts of a tree. Thus XML is more flexible than the relational model, which can be seen as allowing only rigid structures of fixed depth. [3] Three approaches to managing XML data in a database system are native XML database systems, XML-enabled database systems, and hybrid systems. In the first, XML is stored in the most appropriate structures and hence one would expect best performance. In the second, XML can be mapped to the model of the database (e.g. relational), providing flexibility but probably at the expense of performance. In the third approach, the desire is to attain the performance of native systems with the flexibility of managing multiple models. [5] The XPath expression //item[date=’1 May 2011’]/title. [3] [11 marks] [Total 33 marks]

c Birkbeck College 2010

COIY028U

CONTINUED

Page 7 of 5 4.

a.

i. A relation R is in BCNF if and only if whenever a non-trivial FD X → Y holds in R, X is a superkey for R. [2] ii. studio → president and president → address violate BCNF because title year is the only key for Films. [3] iii. A BCNF decomposition of Films is given by, say, first decomposing Films with respect to president → address, giving {president, address} and {title, year, studio, president}. We can then decompose using studio → president to give {title, year, studio}, {studio, president} and {president, address}. [6] [11 marks]

b. Object-relational systems provide a number of extra features over relational systems. These include user-defined types, type inheritance, table inheritance, array and multiset types, object identity, reference types, and methods. [8] Entity-relationship features provided by object-relational systems include composite attributes and specialisation/generalisation. [3] [11 marks]

c Birkbeck College 2010

COIY028U

TURN OVER

Page 8 of 5 c. Assume that Team has n tuples and Player has m tuples. Assume that l Player tuples have a city value of London. (i) Use nested loops to iterate over each Team tuple in the outer loop and each Player tuple in the inner loop. The cost of this would be n ∗ m. (ii) First iterate over Player tuples to find those for which the city is London. Then for each of these, iterate over Team tuples to find matches. The cost would be m + l ∗ n. Assuming l is much smaller than m, this would be a big saving over (i). (iii) Assuming Player is indexed on city and Team is indexed on player, perform an index lookup on Player for tuples for which city is London. For each tuple, perform an index lookup on Team for matching player names. The cost depends on the costs of the index lookups, but should be lower than (ii). (iv) Sort-merge . . . (v) Hash join . . . [11 marks] [Total 33 marks]

c Birkbeck College 2013

COIY028H6

END OF PAPER