Database Homework Help
Database Homework Help
For Any Homework related queries, Call us at : - +1 678 648 4277
You can mail us at : - info@databasehomeworkhelp.com or
reach us at : - https://www.databasehomeworkhelp.com/
1. Propose a relational schema for this database.
Indicate the primary and foreign keys.
Propose a reasonable set of functional dependencies
for this schema. Show that your schema is in 3NF or
BCNF.
databasehomeworkhelp.com
orders -> ordid, cid, orderdate, shipdate
products -> pid, type, species, color, price, quantity_stocked
order_info -> ordid, pid, quantity. This is in BCNF since only
primary keys appear on the left hand side of any functional
dependency.
databasehomeworkhelp.com
The straightforward way to compute this query is using a
correlated subquery (e.g., a subquery that references an
expression in the outer query):
SELECT DISTINCT c.name, o.ordid, p.type, p.species
FROM orders AS o, customers AS c, products AS p, order_info
AS inf, animals AS a WHERE c.cid = o.cid
AND inf.pid = p.pid
AND inf.ordid = o.ordid
AND p.species NOT IN
(SELECT DISTINCT species AS s1 --all the species this
customer owns
FROM animals
WHERE c.cid = animals.ownerid);
We can get rid of the correlation in the subquery, as follows:
SELECT DISTINCT c.name, o.ordid, p.type, p.species
FROM orders AS o, customers AS c, products AS p, order_info
AS inf, animals AS a WHERE c.cid = o.cid
AND inf.pid = p.pid
AND inf.ordid = o.ordid
AND (c.cid,p.species) NOT IN
(SELECT DISTINCT customers.cid, species AS s1
FROM animals, customers WHERE customers.cid =
animals.ownerid);
databasehomeworkhelp.com
We’ll assume the second query is the one to use.
Note that when the query is re-written in this way, it’s clear we
don’t actually need the reference to customers in the inner
query at all:
SELECT DISTINCT c.name, o.ordid, p.type, p.species
FROM orders AS o, customers AS c, products AS p, order_info
AS inf, animals AS a WHERE c.cid = o.cid
AND inf.pid = p.pid
AND inf.ordid = o.ordid
AND (c.cid,p.species) NOT IN
(SELECT DISTINCT ownerid, species AS s1
FROM animals);
databasehomeworkhelp.com
least one tuple in the outer relation.
These index lookups would tend to be random. To avoid this
random I/O, a better choice would be hash or merge joins with
hash-tables built or resorting done on the fly. With sufficient
memory, these data structures allow us to sequentially scan
each inner relation just once in sequential order. No indices are
needed.
databasehomeworkhelp.com
4. Show an efficient equivalent relational algebra for
this plan, in a tree structured representation. For
each node in the tree, choose a particular
implementation of the operator in question. Indicate
which indices are used where as well as the use of
SARGable predicates as needed.
databasehomeworkhelp.com
relation once. There are 10 tuples per page. Hence, we have to
perform the following I/Os: customers: 10K / 10 = 1K I/Os
orders: 100K / 10 = 10K I/Os pets: 20K / 10 = 2K I/Os
products: 1K / 10 = 100 I/Os order_info: 200K / 10 = 20K I/S
total: 33,100K sequential I/Os
databasehomeworkhelp.com