Sei sulla pagina 1di 4

Meeting 5: Data Warehouses

Natalia Vanetik
December 21, 2010

1 Question [RG] 25.2 (1)-(2)


Consider the cross-tabulation of the Sales relation in Figure 25.2.
(1) Show the result of pivoting the relation on pid and timeid.
pid/timeid 1 2 3 total
11 60 30 25 115
12 56 65 70 191
13 28 40 15 83
total 134 135 110 379
(2) Write a collection of SQL queries to obtain the same result as in (1).
SELECT pid, timeid, SUM(S.sales)
FROM Sales S
GROUP BY pid, timeid

SELECT timeid, SUM(S.sales)


FROM Sales S
GROUP BY timeid

SELECT pid, SUM(S.sales)


FROM Sales S
GROUP BY pid

SELECT SUM(S.sales)
FROM Sales S

1
2 Question [RG] 25.3 (3)
Consider the table in Figure 25.5. (3) Show the result of roll-up on locid
followed by drill-down on pid.
Roll-up on locid.
timeid total
1995 144
1996 145
1997 110
Drill-down of the above table on pid :
timeid pid sales

1 11 70
1 12 56
1 13 28
2 11 30
2 12 40
2 13 60
3 11 25
3 12 70
3 13 15

3 Question [RG] 25.7


We have a Customers table (Figure 25.9) with bitmap indices on gender and
rating and a table Prospects with fields rating and prospectid, identifying
potential customers.
(1) Would a bitmap index on the Prospects.rating help in computing the join
of Customers and Prospects on rating?
Yes, as the scan of two indices while performing a logical AND on index tuples
will give us the opportunity to fetch tuples of both relations only when the
join condition is satisfied.
(2) Without the bitmap index on Prospects.rating, would bitmap indices on
Customers help to compute the above join?
Yes, an index scan is still better than the relation scan.
(3) Describe the use of join index to support the join of these two relations
with the join condition custid=prospectid.
If Customers.custid ∩ P rospects.prospectid = ∅, there is no point in com-
puting the join. Otherwise, B+-tree indices on both parameters will save

2
time (scanning leaf level of a B+-tree is cheaper than scanning the entire
relation).

4 Question [RG] 25.8(1)


We have instances of Locations, Products and Sales relations of Figure 25.2.
(1) Suppose you want to optimize for the following two kinds of queries:
Query 1 = find sales in a given city
Query 2 = find sales in a given state
Show the join indices you would create on the example instances of Figure
25.2.
Query 1 requires join of Sales and Locations on locid. Therefore, a bitmap
index on Locations.locid and Sales.locid is required.
There are three locid values in Locations, thus the bitmap index on Loca-
tions.locid is:
1 2 3
1 0 0
0 1 0
0 0 1
The bitmap index for the Sales table:
1 2 3
1 0 0
1 0 0
1 0 0
1 0 0
1 0 0
1 0 0
1 0 0
1 0 0
1 0 0
0 1 0
0 1 0
0 1 0
0 1 0
0 1 0
0 1 0
0 1 0
0 1 0
0 1 0

3
A simple index connecting locid and the city name will also help if we do not
wish to access the tuples of Locations relation at all.

5 Question [RG] 25.9(1)


Consider the view NumReservations defined as:
CREATE VIEW NumReservations(sid,sname,numres)
AS SELECT S.sid, S.sname, COUNT(*)
FROM Sailors S, Reserves R
WHERE S.sid = R.sid
GROUP BY S.sid, S.sname

(1) How is the following query rewritten using query modification?

SELECT MAX(N.numres)
FROM NumReservations N

It will look like:


SELECT MAX(N.numres)
FROM (SELECT S.sid sid, S.sname sname, COUNT(*) numres
FROM Sailors S, Reserves R
WHERE S.sid = R.sid
GROUP BY S.sid, S.sname) as R

Potrebbero piacerti anche