Database Systems Assignment with Resolution | CPSC 310, Assignments of Deductive Database Systems

Material Type: Assignment; Class: DATABASE SYSTEMS; Subject: COMPUTER SCIENCE; University: Texas A&M University; Term: Fall 2008;

Typology: Assignments

2019/2020

Uploaded on 11/25/2020

koofers-user-dvm-1
koofers-user-dvm-1 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CPSC 310 HW 6, Summer 2008, Ronnie Ward
Assigned 7/16/08, DUE in class on 7/23/08
Turn in a hardcopy with the Assignment Cover page and post your solutions to CSNet
These exercises were selected from Chapter 8 and 12, and from SimpleDB to help you
better understand transactions, storing data in records, representing tables, and indexing
in SimpleDB. Answers in RED.
1. The get/set methods in the SimpleDB Transaction class obtain a lock on the specified
block. Why don’t they unlock the block when they are done? Essentially, every
transaction all lock requests precede all unlock requests (see two-phase locking, p. 936 of
the textbook). A SimpleDB transaction releases all its locks when it commits or
rollsback. It should not release any locks prior to finishing. All SimpleDB transactions
obey this two-phase locking protocol, so that concurrent transactions will not conflict
with one another. That is, the transactions are serial (see p. 399 of the textbook). Also,
see Assuring Serializable Behavior on p. 400 of the textbook.
2. Explain why the Transaction class method nextTxNumber is synchronized. What
could happen if it were not? Is it a problem for the other methods in that class to not be
synchronized? Explain your answer. The method is called by a transaction constructor to
obtain a unique transaction number. If the method were not synchronized, then two
concurrent transaction constructors could interleave their execution in such a way that
both are assigned the same transaction number. The method is synchronized to prevent
this from happening.
3. 12.2.5, p. 578. Also calculate the wasted space in each situation.
For parts (a) and (b), the header takes 40 bytes, while for (c) it takes 80 bytes. The
calculations are thus:
a) (4096-40)/44 = 92.
b) (4096-40)/52 = 78.
c) (4096-80)/72 = 55.
Yue will provide the wasted space results. The waste space is computed as follows:
a) (4096-40)/44 = 92.
Waste: Only the left over part: 4096-40-44*92=8
b) (4096-40)/52 = 78.
Waste: inside the record because of fields starting position: 78*8=624.
No left over waste.
c) (4096-80)/72 = 55.
Waste: inside of the record: 55*28=1540, block head: 40, left over:
4096-80-72*55=56
Total waste: 1540+40+56=1636
4. Revise the classes RecordFile and RecordPage to support a previous() method, and
revise the RecordFile class to support a method named afterLast(), which positions the
current record to be after the last record in a file. Modify the TestRecordMgmt.java (see
website for lecture on 7/14/08) program to print the movies table in reverse order. This
problem was suggested by Ed Sciore:
http://www.cs.bc.edu/%7Esciore/courses/cs357/hw6.html
10 records were inserted into the movie table and the forward and backward listings
created by the following code change to TestRecordMgmt.java.
pf3
pf4

Partial preview of the text

Download Database Systems Assignment with Resolution | CPSC 310 and more Assignments Deductive Database Systems in PDF only on Docsity!

Assigned 7/16/08, DUE in class on 7/23/

Turn in a hardcopy with the Assignment Cover page and post your solutions to CSNet

These exercises were selected from Chapter 8 and 12, and from SimpleDB to help you

better understand transactions, storing data in records, representing tables, and indexing

in SimpleDB. Answers in RED.

1. The get/set methods in the SimpleDB Transaction class obtain a lock on the specified

block. Why don’t they unlock the block when they are done? Essentially, every

transaction all lock requests precede all unlock requests (see two-phase locking, p. 936 of

the textbook). A SimpleDB transaction releases all its locks when it commits or

rollsback. It should not release any locks prior to finishing. All SimpleDB transactions

obey this two-phase locking protocol, so that concurrent transactions will not conflict

with one another. That is, the transactions are serial (see p. 399 of the textbook). Also,

see Assuring Serializable Behavior on p. 400 of the textbook.

2. Explain why the Transaction class method nextTxNumber is synchronized. What

could happen if it were not? Is it a problem for the other methods in that class to not be

synchronized? Explain your answer. The method is called by a transaction constructor to

obtain a unique transaction number. If the method were not synchronized, then two

concurrent transaction constructors could interleave their execution in such a way that

both are assigned the same transaction number. The method is synchronized to prevent

this from happening.

3. 12.2.5, p. 578. Also calculate the wasted space in each situation.

For parts (a) and (b), the header takes 40 bytes, while for (c) it takes 80 bytes. The

calculations are thus:

a) (4096-40)/44 = 92.

b) (4096-40)/52 = 78.

c) (4096-80)/72 = 55.

Yue will provide the wasted space results. The waste space is computed as follows:

a) (4096-40)/44 = 92.

Waste: Only the left over part: 4096-40-44*92=

b) (4096-40)/52 = 78.

Waste: inside the record because of fields starting position: 78*8=624.

No left over waste.

c) (4096-80)/72 = 55.

Waste: inside of the record: 55*28=1540, block head: 40, left over:

Total waste: 1540+40+56=

4. Revise the classes RecordFile and RecordPage to support a previous() method, and

revise the RecordFile class to support a method named afterLast(), which positions the

current record to be after the last record in a file. Modify the TestRecordMgmt.java (see

website for lecture on 7/14/08) program to print the movies table in reverse order. This

problem was suggested by Ed Sciore:

http://www.cs.bc.edu/%7Esciore/courses/cs357/hw6.html

10 records were inserted into the movie table and the forward and backward listings

created by the following code change to TestRecordMgmt.java.

Assigned 7/16/08, DUE in class on 7/23/

Turn in a hardcopy with the Assignment Cover page and post your solutions to CSNet

//print file forward System. out .println("FORWARD listing"); rf.beforeFirst(); while (rf.next()) System. out .println(rf.getInt("movidx")+" "+ rf.getInt("yearmade")+" "+rf.getString("title")); //print the file backwards System. out .println("BACKWARD listing"); rf.afterLast(); while (rf.previous()) System. out .println(rf.getInt("movidx")+" "+ rf.getInt("yearmade")+" "+rf.getString("title"));

FORWARD listing 1 2003 Dinosaur Planet 2 2004 Isle of Man TT 2004 3 1997 Character 4 1994 Paula Abduls Get Up 5 2004 The Rise and Fall o 6 1997 Sick 7 1992 8 Man 8 2004 What the #$! Do We 9 1991 Class of Nuke Em Hi 10 2001 Fighter BACKWARD listing 10 2001 Fighter 9 1991 Class of Nuke Em Hi 8 2004 What the #$! Do We 7 1992 8 Man 6 1997 Sick 5 2004 The Rise and Fall o 4 1994 Paula Abduls Get Up 3 1997 Character 2 2004 Isle of Man TT 2004 1 2003 Dinosaur Planet

The code added or changed to RecordFile.java are as follows:

private boolean atFirstBlock() {//rgw return currentblknum == 0; } public boolean previous() {//rgw while ( true ) { if (rp.previous()) return true ; if (atFirstBlock()) return false ; moveTo(currentblknum - 1); } } public void afterLast() {//rgw moveTo(tx.size(filename) - 1);//move to last block }

The code added or changed to RecordPage.java are as follows:

private boolean searchBak( int flag) {//rgw if (currentslot < 0) while (next()); currentslot--;

Assigned 7/16/08, DUE in class on 7/23/

Turn in a hardcopy with the Assignment Cover page and post your solutions to CSNet

number_hits=0; while (mscan.next()){ lnum = mscan.getInt("mnum"); lyear = mscan.getInt("yearmade"); ltitle = mscan.getString("title"); if (lyear==searchkey)number_hits++; } mscan.close(); tx.commit(); ctm1 = fm.blockreads()-ctm1; ctm2 = fm.blockwrites()-ctm2; System. out .println("Blocks accessed withOUT indexing: " + ctm1 + " " + ctm2+ " Number hits = "+number_hits);//+"\n"

8. As described in class, yearidx records are 16 bytes long. How many index records can

be stored per block if BLOCK_SIZE were set to 1000 bytes? Assume NUM_BUCKETS in

HashIndex was changed from 100 to 1000, and assume the hash function evenly

distributed the hash keys across the buckets giving only one index block access per

search. How large of a movie table could be supported? How many movie table block

accesses would occur per search?

For year 2000, the 16 bytes: 00 00 00 01 00 00 00 00 00 00 00 03 00 00 07 D

form an index record, where the first four bytes is the integer INUSE/EMPTY flag

maintained by RecordPage.java. See IndexInfo for the schema of the other three integers

in this record—block#, record ID, data value. The number of key-pointer pairs in a 1000

byte block is 1000/16, or 62 (2 bytes wasted). If NUM_BUCKETS is increased to 1000,

then we could have 1000*62 records in the index, which is movie file of 62,000 titles!

Only one movie table block access is needed per search according to the assumptions

(evenly distributed, one index block accessed per search).

9. The IndexSelectScan we examined in class is very good when the selection predicate is

an equality (eg, type = ‘printer’ as presented in class). Explain why a HashIndex is not

useful for a predicate such as price < 1500.

The hash buckets are not in arranged in key order. They are in hash order. So if we

searched the hash block corresponding to a key of 1500, that wouldn’t tell us about the

other hash blocks in the index. We’d have to search them also for price<1500. It would

be simpler to scan the table and forget using the index.